Skip to content

Instantly share code, notes, and snippets.

@liamcurry
liamcurry / gist:1019779
Created June 10, 2011 21:06
Add embedded document helpers to Mongoose.js
mongoose.Types.DocumentArray.prototype.sortByDir = function(direction, path) {
this.sort(function(a, b) {
var aVal = a.get(path),
bVal = b.get(path);
if (!aVal && !bVal) return 0;
if (!aVal) return 1;
if (!bVal) return -1;
if (direction > 0) return !(aVal < bVal);
return (aVal < bVal);
});
!function (name, definition) {
if (typeof define == 'function' && define.amd) define(name, definition)
else if (typeof module != 'undefined') module.exports = definition()
else this[name] = definition()
}('thing', function () {
// codes
return module
})
@stas
stas / firewall.sh
Created February 6, 2012 15:49
iptables boilerplate, because no one did this till now
#!/bin/bash
IFNET="eth0"
IPNET="8.8.8.8"
PORTS="20 21 25 80 8000 8888 12000 12001 12002 12003"
BANLIST="64.205.0.18"
if [ "$1" = "start" ]; then
echo "Starting firewall..."
@csanz
csanz / hackathons101.md
Created April 29, 2012 15:41
Hackathons 101

Summary

Just some quick notes on how to create a hackathon, super simple really.

Sponsors & Judges

  • Prepare one page summary of the event (Name, venue, audience numbers)
  • Reach out to tech evangelist from various companies, offer 10 minutes to pitch their APIs (skype or in person)
  • Reach out to influential hackers to be judges and includes sponsors
@samdelagarza
samdelagarza / latency.txt
Created May 31, 2012 20:20 — forked from jboner/latency.txt
Latency numbers every programmer should know
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns
Mutex lock/unlock 25 ns
Main memory reference 100 ns
Compress 1K bytes with Zippy 3,000 ns
Send 2K bytes over 1 Gbps network 20,000 ns
Read 1 MB sequentially from memory 250,000 ns
Round trip within same datacenter 500,000 ns
Disk seek 10,000,000 ns
@max-mapper
max-mapper / index.js
Created July 7, 2012 00:04
geohash based spatial index on leveldb
var plumbdb = require('plumbdb')
var shp2json = require('shp2json')
var tako = require('tako')
var geohash = require('geohash').GeoHash
var JSONStream = require('JSONStream')
var async = require('async')
var gju = require('geostuff')
var t = tako()
@amatus
amatus / rust_for_rpi.md
Last active February 18, 2017 21:13 — forked from anonymous/gist:6664882
Howto build a rust compiler for the Raspberry Pi on Debian 7.1 (wheezy)

Howto build a rust compiler for the Raspberry Pi on Debian 7.1 (wheezy)

sudo apt-get install git build-essential
test `uname -m` = x86_64 && sudo apt-get install ia32-libs
git clone https://github.com/raspberrypi/tools.git
export PATH=$PWD/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin:$PATH
git clone http://github.com/mozilla/rust.git
cd rust
./configure --target-triples=arm-unknown-linux-gnueabihf

make

@tj
tj / routes.js
Created October 15, 2011 00:23
Express routes
var app = require('../app');
console.log();
app.routes.all().forEach(function(route){
console.log(' \033[90m%s \033[36m%s\033[0m', route.method.toUpperCase(), route.path);
});
console.log();
process.exit();
@ryanfitz
ryanfitz / stitch_jade_compile.js
Created February 19, 2011 02:26
render jade templates on client side using stitch
var stitch = require('stitch');
var express = require('express');
options = {
paths : [__dirname + '/lib', __dirname + '/vendor'],
compilers: {
jade: function(module, filename) {
var jade = require('jade');
var source = require('fs').readFileSync(filename, 'utf8');
@domenic
domenic / example.js
Last active May 25, 2018 10:17
Promise chaining example
// `promise` is some operation that may succeed (fulfill) or fail (reject)
var newPromise = promise.then(
function () {
return delay(1000);
},
writeError
);
// If `promise` fulfills, `newPromise` will fulfill in 1000 ms.
// If `promise` rejects and writing to the error log succeeds,