Skip to content

Instantly share code, notes, and snippets.

@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")}
@-webkit-keyframes rotate {
0% {-webkit-transform: rotate(0deg);}
100% {-webkit-transform: rotate(360deg);}
}
.rotation {
-webkit-animation: rotate;
-webkit-animation-duration: 1s;
-webkit-animation-iteration-count: infinite;
-webkit-animation-timing-function: linear;
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 / events.js
Created August 17, 2012 12:09
Multiple Event handlers idea with next()
var slice = Function.prototype.call.bind(Array.prototype.slice);
var forEach = Function.prototype.call.bind(Array.prototype.forEach);
var Event = function(event){
this.event = event || window.event;
this.locals = {};
};
Event.prototype.target = function(){
@arian
arian / gist:3345801
Created August 14, 2012 02:20
Make Jade templates requirable
./node_modules/.bin/jade --no-debug --client --out ./public/templates ./views/partials/*
sed -i 's/^function anonymous/require("jade\/runtime");module.exports = function/' ./public/templates/*
@arian
arian / crop.js
Created August 5, 2012 19:33
Cropping images with nodejs streams and imagemagick
var spawn = require('child_process').spawn;
var Stream = require('stream');
/**
* crops and resizes images to our desired size
* @param {Stream} streamIn in stream containing the raw image
* @return {Stream}
*/
exports.cropImage = function(streamIn){