- OSCON-2006
- javascript bootcamp
- slides at www.slash7.com
- Misc
- triple = is identity
- single & double quotes are the same
- objects
- var obj = {}
- obj = {foo:"bar", baz:"quux"}
- obj.foo = "bbar"
- attribute access
- obj.attr
- obj[attr]
- "hashes" are just objects
- Can create with constructor-like functions
- function Foo() {
this.prop = 'val'
this.otherprop = 'otherval'
}
var obj = new(Foo)
- strings
- Are arrays
- Auto type conversion during concatenation
- escaping
- escape() for html
- encodeURI() for URLs
- escape() & unescape() are global functions, not string methods
- control structs
- Braces not required, even for multiline
- switch(str) {
case "foo":
alert(foo)
break
default:
dodefault()
}
- Two kinds of for loop
- for (var i=0; i<3; i++) { ... }
- for (attr in someObj) { ... }
iterates in a defined order, but it's difficult to predict order.
- RegExp
- regexps are objects
- constructors
- literal => /foo/i
Need to esc. slashes
- new RegExp("/usr/local/", "gi")
Don't need to esc. slashes.
- "a string'.match(regobj)
- regobj.test("a string")
- functions
- Can assign func. to a var
- var myfunc = function() { ... }
- Can pass functions as args to other funcs
- function foo(arg1, arg2) {
dosomething(arg1);
arg2(someParam)
}
- The array var "arguments" contains the args passed in.
- JSON
- syntaxerror ! line 6: missing } after property list
- If you forget a comma in a definition list
- eval-ing a string - security hole
- json library at json.org is safer
- Object Hierarchies
- create parent constructor
- create child constructor
- "extend" it like so:
child.prototype = new parent
- Exceptions
- try {
dofoo();
} catch (e if e.name == "TypeError") {
alert("TypeError from hell")
} catch (e) {
alert("error " + e.name + "; msg="+ e.message)
}
- Custom exceptions possible
- Can thow anything, incl. a string
- Can define exception object types
- function fooerr(arg) {
this.name = "fooerr";
this.message = "error in " + arg + ".";
}
- In the Browser
- Split personality - ECMAscript vs. W3C DOM
- The problem is DOM incompatibility, not ecmascript
- How to access the DOM
- document.getElementById()
- parent.getElementsByTagName("div")
- var ptag = document.createElement('p');
ptag.innerHTML = "some text";
somediv.appendChild(ptag);
- Python Optimization
- Profiling
- Python has a built-in profiler
- import profile
profile_run('function()', 'outfile-name.prof')
from pstats import Stats
s = Stats('outfile-name.prof')
s.sort_stats('time', 'calls')
s.print_stats() - Need to calibrate profiler..., but calibration doesn't work right...
- timeit
- module to time things
- t = Timer('func(arg)'
t.timeit(numtimes)
- Tips
- run profiler from the command or #! line
- python -m profile script.py
- python -m timeit statement
- python -m pstats profile-data.prof
- list slicing creates new objects!
- Good Ideas
- Information Radiators
- Lava lamps for red-light/green-light
- embed webserver in browser!
- Mine gnats for users that have contributed to fixing a bug
- Wednesday
- Keynotes
- Tim O'Reilly
- how does open source deal with the web?
- open src licences are obsolete
- even if you have google's SW, you still need their db's, thousands of servers, bus. processes, etcl.
- asymmetric competition
- google & MS aren't in the same market..
- craigslist is 7th most visited site, only 18 employees (vs. 9000 for yahoo)
- operations as advantage
- Big ops have massive economies of scale
- More apps will be hosted
- open data
- portable data
- microformats
- movemydata.org
- other stuff
- School of Rock - Scott Yarra - Greenplum
- how the open src. industry is similar to the rock-n-roll industry
- Trying to Suck Less - Anil Dash - Sixapart
- blogs
- typepad, vox, livejournal, etc.
- cuteoverload.com
- niche comunities
- Things should be open and meaningful
- Opensourcing their infrastructure
- perlbal
- memcached
- MogileFS
- scalable file system
- assumes disks will fail
- djabberd
- Embedding a DB in a Browser - David Van Couvering
- (See sheeri.com for a blog of this)
- He develops apache derby
- davidvancouvering@sun.com
- Why put db in browser?
- mobile users
- keep personal data off the server
- fast local web cache
- requirements
- java
- embeddable
- small footprint
- standards compliant
- secure
- auto. crash recovery
- why java?
- why a database?
- standard portable api
- acid sematics
- flexibble data model
- powerful query capabilities
- works with existing tools
- What is derby
- 100% java OS database
- embeddable, small (2mb)
- architecture
- javascript uses liveconnect to talk to java
- which then talks to derby
- Like AJAX, but maybe L(ocal)JAX
- Could embed a webserver in the browser.
- Need a signed applet to access the FS
- Building a Sane Query Interface
- (See sheeri.com for a blog of this)
- What's an insane interface?
- no help
- no clue how much might be returned
- better
- shows help
- pulldowns
- shows, for instance, the date ranges in the db
- puldowns automatically turn into popups when the number is too large
- shows number of records in db
- each field shows number of choices next to pullldown
- results are sortable, and paged
- Lots of description of the particular implementation...
- Uses a single query method to do all the necessary sql
- returns different kinds of info depending on the inputs
- used to populate dropdowns
- also used to pull query results
- Lessons learned
- cache values (pulldowns) on server
- Use js for client side validation
- Semasiology of Open Source
- semasiology == change in defn. of words
- The term "artificial intelligence" is a good example of a bad term
- The Language/Action Perspective
- SHRDLU
- language is action (commitments)
- doesn't make sense to ask whether a sentence is true or false
- Ask if it is useful in context
- Boils down to...
- "we need to talk about opensource in the context of labor organization, or professional societies"
- or something like that...
- how do we organize ourselves?
- Defn. of "open source" is no longer changing
- Now we need to talk about the hermeneutics of open source...
- Django - Jacob Kaplan-Moss
- Lawrence Kansas is a cool place
- Lots of back-patting
- Data mining with Orange & Python
- http://www.ailab.si/orange
- Thursday
- Keynotes
- The Zen of Free - Simon Phipps - Sun
- Director of opensource foo at Sun
- altruism without sacrifice
- Licensing w/o Lawyers
- Governance (eg. commit access) is now more important than licensing
- We need "the freedom to leave" - open standards
- Standards need to be created transparently
- Standards need transparent stewardship
- Open standards - Gary Lang - Autodesk/OSGeo.org
- How and why Autodesk opensourced its mapping product.
- 5 A Day - Robert r0ml Lefkowitz
- Open Source is (not?) like a tomato...
- Vast numbers of wacky metaphors.
- We should shoot for opensource to be 1/3 of all sw used
- Stephen O'Grady - RedMonk
- Opensource has "arrived"
- What we need to do now
- evangelize and market
- make open data a priority
- lower barriers to entry
- be creative
- work together
- eg. proliferation of linux distros & packaging systems
- Tech Documentaries - Jason Scott
- Last documentary was on BBSs
- Next documentary is on text adventures
- How Databases Work - D. Richard Hipp - SQLite
- sql is a peculiar programming lang.
- each statement is a little program
- sql describes what, not how
- many ways to implement a given statement
- Anatomy of an rdbms
- statements fed into compiler
- comp. creates procedural representation
- virtual machine runs proc. code
- Storage engine performs IO
- prepared statements
- is the procedural representation
- Usually a complex tree structure that the virt. mach. "walks"
- Sometimes the prep. stmt. is bytecode
- Sometimes it's native machine code.
- If you understand how the proc. repr. works, you can write better sql
- Rows are stored at unique "addresses"
- seq. no.
- file offset
- file + page + offset
- etc.
- Full table scan
- Single column index
- two "columns" - col value, row addr
- stored in sorted order
- indexed query
- faster only if num output rows much smaller than num rows in table
- Multi column index
- pretty similar to single-col.
- Second col. used as a tie-breaker
- Index is only helpful if the where clause matches the first col. of the index.
- use first col. to satisfy where clause, other cols to satisfy order by clause
- Use further cols to satisfy ouput cols.
- Time Travel Tables in PostgreSQL
- costs
- two timestamp cols in every roow
- queries must be qualified
- update overhead to manage triggers
- No updates or deletes, only inserts
- Trigger-based
- When User Interface Attacks - Amy Hoy
- Not just about effectiveness - people have feelings about UI
- UI *is* a science - it can be tested, and there are rules
- three layers
- expectations
- interaction
- behavior
- basic principles
- users brains are affected by literacy
- LTR and top-to-bottom
- line endings have emphasis
- bot. rt. is dead zone
- readers adapt to web pages
- they tune out zones (nav)
- if it looks like an ad,users ignore it
- users "satisfice", or give up
- users scan in predictable ways
- 30-40% of users have "low literacy"
- large blocks of text defeat them
- stuff you can do
- for low literacy
- keep it simple
- break text into paras
- highlight key items
- use headings and bulleted lists
- These tips also increase usability 30-40% for literate users.
- forms
- labels
- good for screen readers
- <label for="field_id">field name</label>
- labels are clickable for checkboxes & radios!
- also, give inline hints
- labels should go on the top of the field
- simple segmentation gives momentum and direction
- vertical spacing
- often better than boxes and lines
- headings
- numbered steps
- progress indicators
- can also use columns (see eye scan order...)_
- buttons
- make it hard to accidentally click the worng button
- don't put destructive buttons next to non-destructive
- Describe the results of the button in clear english
- Don't have a clear/cancel button unless you really need it
- de-emphasize "negative" buttons
- field types
- field types matter
- users will "satisfice"
- avoid selects
- especially multi-selects
- use checkboxes or radio lists
- provide both yes and no choices
- one choice per line
- put common choices at the top (but also in their "rightful" place in the list)
- slides at: www.slash7.com
- Troubleshooting the JVM - Moazam Raja
- Friday
- 10 Tools Developers Need Now - Karl Fogel - Google
- Actually about collaborative tools
- our attitude toward tools
- B4 anon cvs, lots of wasted effort
- good tools trump good intentions
- Wants to make us dissatisfied with some of our existing tools
- With large numbers of users, you can look at patterns
- spam
- moderating mailing lists for spam is a pain
- The Contribulyzer
- helps discover new committers by tracking diff. kinds of contributions
- http://www.red-bean.com/svnproject/contribulyzer/
- Worked as intended
- As a side-effect, it has made the project a lot more careful about attribution
- If this info is stored in the bug system, you can mine that.
- IRC
- has lots of timing info (time betw statement & resp)
- names are commonly used (foo: here's the answer)
- not much threading info
- irc bots or servers should mine conversations for info
- who gives good answers
- who participates and who doesn't
- who helps who
- who knows what
- affero.net has a manual system for this, but it's manual
- automated FAQ maintenance!
- bot collects conversations
- sends email to human
- says "this might be a new FAQ"
- Need information aggregators
- No source of project info between slashdot and the chaos of the mailing lists
- collaborative tool for generating mailing list summaries.
- summarydesk.tigris.org
- managing projects - Alex Martelli