Skip to content

Instantly share code, notes, and snippets.

Aseem Kishore aseemk

Block or report user

Report or block aseemk

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@aseemk
aseemk / keybase.md
Created Mar 22, 2014
Keybase verification!
View keybase.md

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 Aug 29, 2015
CoffeeScript + Streamline patterns for async loading + caching.
View async-loading.md

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!
View neo4j-transaction-test._coffee
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 Apr 8, 2011
Streamline's compiler chokes on valid JS when a function happens to have a keyword name.
View shell
$ 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 Apr 10, 2011
Testing support for using Streamline.js with Underscore.js.
View under_.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 Apr 10, 2011
Throwing an error synchronously within a closure isn't caught -- Streamline bug?
View closure_error_.js
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 Apr 10, 2011
Trying to accommodate multiple "return values" in Streamline syntax.
View multiple_return_values_.js
// 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 Apr 19, 2011
A wrapper around streamline that supports require()-ing coffee files.
View streamline.coffee
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 Apr 19, 2011
Express sample app using Eco templating engine.
View app.js
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 Apr 19, 2011 — forked from laurie71/blocks.js
Test app for Express blocks middleware
View app.js
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');
You can’t perform that action at this time.