Skip to content

Instantly share code, notes, and snippets.

#! /usr/bin/env bash
# build MooTools
packager build Core/Class \
Core/Class.Extras \
Core/Element \
Core/Element.Event \
Core/DOMReady \
-blocks 1.2compat 1.3compat '!ES5' '!ES5-bind' \
var jsdom = require('jsdom')
var fs = require('fs')
var nodes = fs.readFileSync("../nodes.js").toString();
jsdom.env({
features: {
QuerySelector: true
},
src: [nodes],
@arian
arian / parentify.js
Created March 22, 2012 20:02
Parentify primes
var parentify = function(prime){
var parent = prime.parent
if (!parent) throw new Error('Cannot parentify this prime')
var method = prime.prototype.parent = function(name){
var fn = parent[name]
if (typeof fn != 'function') throw new Error('This method called with parent() does not exist')
delete this.parent
var ret = fn.apply(this, array.slice(arguments, 1))
var mocha = require('mocha');
// setup
var suite = new mocha.Suite('', new mocha.Context),
utils = mocha.utils,
Reporter = mocha.reporters.Spec,
ui = mocha.interfaces['bdd'];
ui(suite);
suite.emit('pre-require', global);
def(emi.prototype, "emit", function(event){
var listeners = this._listeners, events, off = []
this.off = function(_event, fn){
if (_event == event) off.push(fn)
else emi.prototype.off.call(this, _event, fn)
return this
};
if (listeners && (events = listeners[event])){
var args = Array.prototype.slice.call(arguments, 1)
for (var i = 0, l = events.length; i < l; i++) events[i].apply(null, args)
@arian
arian / npm-data.js
Created March 1, 2012 23:18
Analyze NPM package data
var fs = require('fs');
var packages = JSON.parse(fs.readFileSync('/home/arian/.npm/-/all/.cache.json'));
var total = 0, zeros = 0, alphas = 0;
for (var name in packages){
var package = packages[name],
@arian
arian / FlowAsync.js
Created February 25, 2012 01:06
Flow Control for Node
var slice = Array.prototype.slice;
return function(){
var queue = [];
this.push = function(fn){
if (typeof fn != 'function'){
throw new Error('the passed argument is not a function');
describe('getStyle height / width / margin with CSS', function(){
var style, element;
it('[beforeAll]', function(){
var className = String.uniqueID();
style = $(document.createElement('style'));
style.type = 'text/css';
var definition = [
'.' + className + '{',
var re = /([\d.]+)(s|ms)?/, units = {ms: 1, s: 1e3};
var parseDuration = function(value){
var match = value.toString().match(re);
return match ? parseFloat(match[1]) * (units[match[2]] || 1) : parseFloat(value)
};
console.log(parseDuration(200));
console.log(parseDuration('200'));
console.log(parseDuration('200ms'));
console.log(parseDuration('.2s'));
// Code ported from the C example from the book
// "Computer Graphics with OpenGL" 4th ed. by Hearn, Baker, Carithers.
// section 14-8
define(function(){
var binomialCoeffs = function(n, C){
var k = 0, j = 0;