Skip to content

Instantly share code, notes, and snippets.

(function () {
var modules = {}, cache = {};
if (typeof define == 'undefined') {
window.define = function (id, factory) {
modules[id] = factory;
};
window.require = function (id) {
var module = cache[id];
if (!module) {
module = cache[id] = {};
@arian
arian / build.sh
Created April 1, 2013 00:10
Using Prime in gjs to create Gtk Applications.
# use the split-generics branch of prime.
wrup -r prime ../../www/prime/index.js -r bind ../../www/prime/function/bind -o prime.js
@arian
arian / multiply.js
Last active December 14, 2015 20:09
How Hardware multiplies unsigned integers
function multiply(multiplicant, multiplier){
var product = 0;
for (var i = 0; i < 32; i++){
product += (multiplier & 1) ? multiplicant : 0;
multiplicant <<= 1;
multiplier >>= 1;
}
@arian
arian / asserts.js
Created February 24, 2013 23:33
better asserts, that can be switched of with a DEV variable.
"use strict";
if (typeof DEV == 'undefined') return;
function assert(condition, message){
if (!condition) throw new Error(message || "Assertion fault");
}
exports.assert = assert;
@arian
arian / .gitignore
Last active December 13, 2015 19:58
dependency injection example for mocking with testing
node_modules/
@arian
arian / test-const-result.js
Created December 28, 2012 14:22
compression and replacing vars/consts
//arian@arian-sys:~/www/wrapup (master) $ ./node_modules/.bin/uglifyjs test.js --compress --mangle --define ES5=false
//WARN: Condition always true [test.js:6,34]
//WARN: Dropping unreachable code [test.js:9,2]
function foo(){console.log("es5")}
for (expr1; expr2; expr3) {
// do thing
}
expr1
while (expr2) {
// do thing
expr3
}
@arian
arian / node.conf
Created October 9, 2012 22:16
UpStart conf
# based on http://geeknme.wordpress.com/2009/10/15/getting-started-with-upstart-in-ubuntu/
description "start and stop the nodejs server"
version "1.0"
author "Arian Stolwijk"
# tell upstart we're creating a daemon
# upstart manages PID creation for you.
expect fork
script
@arian
arian / .bashrc
Created September 19, 2012 15:42
.bashrc additions.
# add ~/bin to path
PATH=$PATH:/home/arian/bin
# use all 256 colors
if [ -n "$DISPLAY" -a "$TERM" == "xterm" ]; then
export TERM=xterm-256color
fi
function git_prompt {
local STATUS=`git status 2>&1`
@arian
arian / index.js
Created October 9, 2015 14:11
requirebin sketch
// require() some stuff from npm (like you were using browserify)
// and then hit Run Code to run it on the right
var slick = require('slick');
var sMyString = "<foo><bar></bar></foo>";
var oParser = new DOMParser();
var oDOM = oParser.parseFromString(sMyString, "text/xml");
console.log(slick('bar', oDOM));