Skip to content

Instantly share code, notes, and snippets.

var tx = dirac.tx.create();
utils.async.series([
tx.begin.bind( tx )
// Remove items
, tx.payment_summary_items.remove.bind(
tx.payment_summary_items
, { payment_summary_id: $where.id }
)
// Add items

In many websites, there are static portions of the page such as the navigation or header that rarely change. If we could deliver the markup for navigation, the experience would feel a bit snappier while the rest of the page is generated.

Try running this snippet in node and visit localhost:3000/incremental and localhost:3000/blocking. These are pretty trivial examples but we could cache and immediately send the nagivation bar and `` elements for every request.

var resource = require('resource', {
http: $.ajax
})('http://localhost:3000')
var api = resource('api')
var users = api('users')
var bob = users(123)
users.get( 123, function( error, bob ){
.container {
background: #fff;
color: #333;
}
.container.dark {
background: #333;
color: #fff;
}
db.user_invoices.findAysnc({
status: 'pending'
, billing_period_begin: period.startDate
, billing_period_end: period.endDate
})
.catch( function( error ){ throw error; });
.map( function( invoice ){
return invoices.create( invoice )
.sendEmailAsync()
.error( function( error ){
@jrf0110
jrf0110 / handlebars-error.js
Last active August 29, 2015 14:16
When handlebars calls a function via a template, the context of the function call is always set to the data passed into the template. This botches functions that rely `this`.
var handlebars = require('handlebars');
var tmpl = handlebars.compile('hello, {{person.getName}}');
var bob = Object.create({
name: 'Bob'
, getName: function(){
console.log( 'this', this );
return this.name;
}
});

I'm having an issue with arrow functions:

~ iosjs --version
v1.3.0

That looks like iosjs and not node on accident.

~ iojs -e "console.log('hi')"

The Big(O) for IO-bound Operations

Big(O) notation is great for describing computations on large data-sets in a synchronous programming environment, but what about IO-bound operations?

Big(IO)

Let n represent the complexity of an asynchronous operation that takes a non-constant time t to complete. Then an asynchronous operation that starts only after a previous operation (async) has been completed (serial asynchrony) is represented as n1 * n2 or simply n^2. Two asynchronous operations started at the same time is represented as n1 + n2 or 2n. Since we're waiting for both operations to complete, but they were fired off in near parallel, then we can consider the time t3 to be equal max( t1, t2 ). Therefore, the Big(IO) of any kn is to be considered equal.

An async series operation over an array of length n should be Big(IO) = n^n

var db = require('./db');
db.restaurants.findOne( 25, {
one: [ { table: 'regions', alias: 'region'
, pluck: [{ table: 'region_zips', alias: 'zips', column: 'zip' }]
}
]
}, function( error, restauarant ){
console.log( error, restauarant );
});
perform test_case('Should format string as URL friendly');
perform assert_equals(
select str_to_slug( E'John\'s Burger Joint' )
, 'johns-burger-joint'
);
perform end_test();
perform test_case('Should do something else');
perform assert_equals( 'bob', 'bob' );
perform end_test();