Skip to content

Instantly share code, notes, and snippets.

View aseemk's full-sized avatar

Aseem Kishore aseemk

View GitHub Profile
@aseemk
aseemk / keybase.md
Created March 22, 2014 22:14
Keybase verification!

Keybase proof

I hereby claim:

  • I am aseemk on github.
  • I am aseemk (https://keybase.io/aseemk) on keybase.
  • I have a public key whose fingerprint is 8FD7 03E6 42A7 B1CD 6D50 07F4 4929 0166 F879 0B95

To claim this, I am signing this object:

@aseemk
aseemk / async-loading.md
Last active August 29, 2015 14:07
CoffeeScript + Streamline patterns for async loading + caching.

Pattern 1: Pre-fetch the result, and cache it.

The result will hopefully already be available when needed, and the async call will be made only once.

fooFuture = fetchFoo !_

# anytime when needed:
foo = fooFuture _ # supports multiple calls!
@aseemk
aseemk / neo4j-transaction-test._coffee
Created November 10, 2014 02:41
Neo4j transaction test.
echo = console.log
Request = require 'request'
BASE_URL = 'http://localhost:7474'
# helper to make transactional requests:
req = (_, {query, params, commit, rollback, txId}) ->
method = if rollback then 'DELETE' else 'POST'
url = "#{BASE_URL}/db/data/transaction"
@aseemk
aseemk / shell
Created April 8, 2011 09:57
Streamline's compiler chokes on valid JS when a function happens to have a keyword name.
$ node-streamline -c truthy_.js
$ node-streamline -c true_.js
/usr/lib/node/.npm/streamline/0.1.11/package/lib/transform.js:1549
throw new Error(message);
^
Error: error streamlining source: Missing identifier on line 5
at Object.transform (/usr/lib/node/.npm/streamline/0.1.11/package/lib/transform.js:1549:10)
at /usr/lib/node/.npm/streamline/0.1.11/package/lib/compile.js:48:30
at /usr/lib/node/.npm/streamline/0.1.11/package/lib/compile.js:43:206
@aseemk
aseemk / under_.js
Created April 10, 2011 01:56
Testing support for using Streamline.js with Underscore.js.
// streamline.options = { "callback": "_cb" }
var _ = require('underscore');
var array = [1, 2, 3];
function process(item, _cb) {
// simulate async task
setTimeout(_cb, 1000);
return item;
}
@aseemk
aseemk / closure_error_.js
Created April 10, 2011 08:56
Throwing an error synchronously within a closure isn't caught -- Streamline bug?
console.log('will throw error in one second...');
try {
// simulate async step here:
setTimeout(_, 1000);
// then *synchronously* throw error here:
(function closure() {
throw new Error();
})();
@aseemk
aseemk / multiple_return_values_.js
Created April 10, 2011 11:59
Trying to accommodate multiple "return values" in Streamline syntax.
// here's an example third-party, out-of-my-control function.
// it calls the callback with multiple non-error values:
function addAndProfile_original(x, y, callback) {
var start = Date.now();
return setTimeout(function () {
var time = Date.now() - start;
callback(null, x + y, time);
}, 1000);
}
@aseemk
aseemk / streamline.coffee
Created April 19, 2011 08:02
A wrapper around streamline that supports require()-ing coffee files.
coffee = require 'coffee-script'
streamline = require 'streamline'
fs = require('fs')
if require.extensions
require.extensions['.coffee'] = (module, filename) ->
content = coffee.compile fs.readFileSync filename, 'utf8'
if filename.match /_\.coffee$/
content = streamline.transform.transform content
module._compile content, filename
@aseemk
aseemk / app.js
Created April 19, 2011 11:12
Express sample app using Eco templating engine.
var express = require('express');
var app = express.createServer();
app.configure(function () {
app.use(app.router);
});
app.set('views', __dirname + '/views');
app.set('view engine', 'html');
app.register('.html', require('eco'));
@aseemk
aseemk / app.js
Created April 19, 2011 11:29 — forked from laurie71/blocks.js
Test app for Express blocks middleware
var express = require('express');
var app = express.createServer();
app.configure(function () {
app.use(require('./blocks')(app));
app.use(app.router);
});
app.set('views', __dirname);
app.set('view engine', 'html');