Skip to content

Instantly share code, notes, and snippets.

View aseemk's full-sized avatar

Aseem Kishore aseemk

View GitHub Profile
@aseemk
aseemk / images.css
Created May 27, 2011 18:21
Image constraining tests
h1 {
font-size: 1.5em;
font-weight: bold;
margin: 1em 0;
}
h2 {
font-size: 1.25em;
margin: 1em 0;
}
@aseemk
aseemk / amazon-search-indices.md
Created June 17, 2011 23:44
Amazon Product Advertising API - search indices not in the "blended" index

Search indices not available in the "Blended" search index:

  • Appliances
  • ArtsAndCrafts
  • Baby
  • Beauty
  • Blended
  • Classical
  • DigitalMusic
  • Grocery
@aseemk
aseemk / mkdirp.coffee
Created June 29, 2011 08:04
My implementation of a synchronous `mkdir -p` for Node.
# synchronously creates the directory at the given path, including all
# intermediate directories, if it doesn't already exist. (like `mkdir -p`)
mkdirpSync = (dir) ->
# normalize and resolve path to an absolute one:
# (path.resolve automatically uses the current directory if needed)
dir = path.resolve path.normalize dir
# try to create this directory:
try
@aseemk
aseemk / require-watcher.coffee
Created June 29, 2011 08:12
Node require watcher: exits the process when any require()'d files are changed.
# require-watcher.coffee
# Watches files that have been require()'d, and if they change, exits the
# current process, assuming that node-supervisor will then restart it.
fs = require 'fs'
# watch handler to exit the process on file changes:
watchFile = (filename) ->
fs.watchFile filename, (oldStat, newStat) ->
@aseemk
aseemk / app-dev.js
Created July 6, 2011 23:39
Handler for efficiently caching compiled Coffee and/or Streamline files.
// app-dev.js
// Helper script to register CoffeeScript and Streamline extension handlers
// before running an app during development.
//
// Uses https://github.com/aseemk/coffee-streamline for efficient require(),
// caching compiled files between runs. Sweet!
//
// Usage: instead of `_coffee app`, just do `node app-dev app`.
//
// Also works great w/ node-dev <https://github.com/fgnass/node-dev>:
@aseemk
aseemk / types.coffee
Created July 14, 2011 01:28
CoffeeScript's awesome inheritance model lets you strip boilerplate type checking.
# WARNING: This will no longer work with CoffeeScript 1.3.2 in IE:
# http://coffeescript.org/#changelog
class Animal
@is: (node) ->
if not @TYPE then return true
node.type is @TYPE
@isnt: (node) ->
not @is node
@aseemk
aseemk / buggy_.coffee
Created July 16, 2011 01:12
Streamline bug due to switch case w/out a break (CoffeeScript optimization)
async = (_) ->
setTimeout _, 1000
switch true
when true
alert 'about to start async'
async _
# this never executes!
alert 'done w/ async'
@aseemk
aseemk / express.md
Created July 17, 2011 19:54
Express monkey-patch to properly use Node callback convention; thus supports Streamline
@aseemk
aseemk / register.js
Created August 10, 2011 00:31
Streamline bug? A piece of code is somehow called twice.
var __global = typeof global !== 'undefined' ? global : window;
function __cb(_, fn){ var ctx = __global.__context; return function(err, result){ __global.__context = ctx; if (err) return _(err); try { return fn(null, result); } catch (ex) { return __propagate(_, ex); } } }
function __future(fn, args, i){ var done, err, result; var cb = function(e, r){ done = true; err = e, result = r; }; args = Array.prototype.slice.call(args); args[i] = function(e, r){ cb(e, r); }; fn.apply(this, args); return function(_){ if (done) _.call(this, err, result); else cb = _.bind(this); } .bind(this); }
function __propagate(_, err){ try { _(err); } catch (ex) { __trap(ex); } }
function __trap(err){ if (err) { if (__global.__context && __global.__context.errorHandler) __global.__context.errorHandler(err); else console.error("UNCAUGHT EXCEPTION: " + err.message + "\n" + err.stack); } }
/* 1 */ this.register = function __1(user, thing, oldStatus, newStatus, _) {
if (!_) {
return __future.call(thi
@aseemk
aseemk / ifs_.coffee
Created August 10, 2011 01:12
Streamline bug: nested switch statements somehow mess up sync flow
# async simulation helper:
async = (_) ->
setTimeout _, 500
# assume we're dealing with a status change event
type = 'event'
kind = 'statusChange'
# assume we initially have no user or target
user = null