##JavaScript isn't threaded
- Synchronous code locks up the browser
- Asynchronous code frees up the browser but leads to...
##Async callback hell
"Return" values are no longer available to our synchronous code
function isPrime( num ) { | |
// everything but 1 can be prime | |
var prime = num != 1; | |
for ( var i = 2; i < num; i++ ) { | |
if ( num % i == 0 ) { | |
prime = false; | |
break; | |
} | |
} | |
return prime; |
function logCar(car) { | |
console.info("I'm a", car.color, car.make); | |
} | |
function Car(make, color) { | |
this.make = make; | |
this.color = color; | |
} | |
Car.prototype.log = function () { logCar(this); } |
Function.prototype.cachify = function () { | |
var cache = {}, self = this; | |
return function (arg) { | |
if (arg in cache) { | |
console.info('cache hit'); | |
return cache[arg]; | |
} | |
return cache[arg] = self.call(self, arg); | |
}; |
var Person = function(name) { | |
this.name = name; | |
}; | |
// Part 2 | |
Person.prototype.getName = function() { | |
return this.name; | |
}; | |
var thomas = new Person('Thomas'); |
// Part 1 | |
document.getElementById('the_div' ).addEventListener('click', function(){ log('the_div!') }, true); | |
document.getElementById('the_list').addEventListener('click', function(){ log('the_list!') }, false); | |
document.getElementById('the_item').addEventListener('click', function(){ log('the_item!') }, true); | |
// Part 2 | |
document.getElementById('the_div' ).addEventListener('click', function(){ log('the_div!') }, false); | |
document.getElementById('the_list').addEventListener('click', function(){ log('the_list!') }, false); |
/** | |
* Include via a <script> tag and reload CSS files via ctrl-R without a full-page refresh. | |
* Maintains your state, especially useful for JavaScript-based single-page apps | |
* | |
* Requires jQuery 1.6 or greater | |
*/ | |
(function () { | |
"use strict"; |
##JavaScript isn't threaded
##Async callback hell
"Return" values are no longer available to our synchronous code
This is a really fast way to restore a large Postgres database by omiting the indexes and restoring them later (if necessary).
Dump database.
pg_dump -Fc --no-owner my_db -f ~/my_db.dump
Create the summary files. One for the indexes and another for everything else.
pg_restore -l ~/my_db.dump | grep -v 'INDEX public' > ~/my_db.list
This is a really fast way to restore a large Postgres database by omiting the indexes and restoring them later (if necessary).
Dump database.
pg_dump -Fc --no-owner my_db -f ~/my_db.dump
Create the summary files. One for the indexes and another for everything else.
pg_restore -l ~/my_db.dump | grep -v 'INDEX public' > ~/my_db.list
At 9:45am, Wednesday October 23rd, I was turning right from Skymark Ave to Explorer Drive.
There was a bus, 35AW, parked on Skymark with its hazard lights on, approximately 3 meters back from the intersection.
I passed the bus on the left, intending to turn right on Explorer, but before I could complete the pass, the bus started moving.
I was ahead of the bus, forward of its front left corner, and couldn’t get back into the right lane; further I believed the driver hadn’t seen me, as I could clearly see him and he showed no signs of acknowledging my presence, and I believed that I was in danger of being struck unless I made my presence known. I called “Hello!” to the window, which I could see was partially open.
The bus slammed on its brakes, and the driver blasted the horn at me while giving me the middle finger. I returned the gesture over my shoulder.