Skip to content

Instantly share code, notes, and snippets.

@airportyh
airportyh / jasmine.js
Created July 12, 2013 14:55
Jasmine with .only
var isCommonJS = typeof window == "undefined" && typeof exports == "object";
/**
* Top level namespace for Jasmine, a lightweight JavaScript BDD/spec/testing framework.
*
* @namespace
*/
var jasmine = {};
if (isCommonJS) exports.jasmine = jasmine;
/**
@airportyh
airportyh / index.js
Created September 30, 2013 04:30
requirebin sketch
var o = require('observable')
var h = require('hyperscript')
var field = h('input', {'type': 'text'})
value = o.input(field)
value(function(v){
console.log('changed to', v)
})
var text =
$('#text')
.asEventStream('input')
.map(function(e){
return $(e.target).val()
})
.toProperty('')
$ rvm requirements
Installing requirements for OSX, might require sudo password.
Failed loading requirements for OSX!
Requirements installation failed with status: 1.
@airportyh
airportyh / commonjs_vs_amd.md
Last active March 4, 2023 19:49
CommonJS vs AMD

CommonJS is the module system used in Node.js. It is synchronous in nature, in that, when you load a module, your code will synchronously wait for the loading of that module to complete before continuing.

// load the `fs` module
var fs = require('fs')
// now use it
fs.readFile('myfile.txt', function(err, data){
  ...
})
@airportyh
airportyh / index.js
Created November 5, 2013 20:27
requirebin sketch
var JsDiff = require('diff')
var one = 'beep boop';
var other = 'beep boob blah';
var diff = JsDiff.diffChars(one, other);
// display it in the DOM
var display = document.createElement('pre');
diff.forEach(function(part){
events.js:72
throw er; // Unhandled 'error' event
^
Error: watch ENOENT
at errnoException (fs.js:1019:11)
at FSWatcher.start (fs.js:1051:11)
at Object.fs.watch (fs.js:1076:11)
at Gaze._watchDir (/Users/airportyh/Home/Code/watcher_deathmatch/node_modules/gaze/lib/gaze.js:279:30)
at /Users/airportyh/Home/Code/watcher_deathmatch/node_modules/gaze/lib/gaze.js:336:10
at iterate (/Users/airportyh/Home/Code/watcher_deathmatch/node_modules/gaze/lib/helper.js:52:5)

Pluggable Web Server

A zero-config pluggable web server using middlewares.

Install the core server npm install psrv -g and run psrv to start the surver. It doesn't do anything, just 404 for all requests. To make it serve static files npm install psrv-static -g. Restart the server and now it serves files from the current directory. To make it auto-compile CoffeeScript, or Browserify, install psrv-coffee-script and psrv-browserify respectively. Plugins can be installed globally or locally and the psrv executable will auto-discover them and load them.

var start = new Date().getTime()
timestamp = function timestamp(msg){
var end = new Date().getTime()
console.log('[' + (end - start) + 'ms]', msg)
}
var mine = require('js-linker/mine.js');
var fs = require('fs');
timestamp('loaded modules')
timestamp('start')
@airportyh
airportyh / README.md
Last active August 29, 2015 13:56
Benchmarks comparisons of Component with syntax-error feature applied.

component is Component version 0.19.6. mycomponent is the same version with applied.