Skip to content

Instantly share code, notes, and snippets.

View juliangruber's full-sized avatar

Julian Gruber juliangruber

View GitHub Profile
// Javascript Doubly Ended Queue
var Dequeue = function() {
this._head = new Dequeue.Node();
this._tail = new Dequeue.Node();
this._head._next = this._tail;
this._tail._prev = this._head;
}
Dequeue.Node = function(data) {
this._data = data;
# Author: Pieter Noordhuis
# Description: Simple demo to showcase Redis PubSub with EventMachine
#
# Update 7 Oct 2010:
# - This example does *not* appear to work with Chrome >=6.0. Apparently,
# the WebSocket protocol implementation in the cramp gem does not work
# well with Chrome's (newer) WebSocket implementation.
#
# Requirements:
# - rubygems: eventmachine, thin, cramp, sinatra, yajl-ruby
@chalmerj
chalmerj / gist:1492384
Created December 18, 2011 04:39
Init script for Graphite carbon-cache
#! /bin/sh
### BEGIN INIT INFO
# Provides: carbon-cache
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: carbon-cache init script
# Description: An init script for Graphite's carbon-cache daemon.
### END INIT INFO

High level style in javascript.

Opinions are like assholes, every one has got one.

This one is mine.

Punctuation: who cares?

Punctuation is a bikeshed. Put your semicolons, whitespace, and commas where you like them.

@creationix
creationix / component-build.js
Created October 25, 2012 16:27
architect http plugin for dynamic component building
module.exports = setup;
setup.consumes = ["http"];
function setup(config, imports, register) {
imports.http.wrap(require('./middleware')(config));
register();
}
@Marak
Marak / 0-primeFactor.js
Last active October 12, 2015 03:58
Experimenting with new process.prevTick() API
//
// Calculating prime factors in polynomial time using node.js process.prevTick()
//
// see: http://en.wikipedia.org/wiki/Prime_factor
// see: http://en.wikipedia.org/wiki/Novikov_self-consistency_principle
//
// Authors:
// http://jesusabdullah.net/
// http://marak.com
//
@tj
tj / in.js
Last active December 11, 2015 08:38
quick hack of an example of how to add some type enforcement via pre-processing
def greet(first:string, last:string) {
ret "Hello " + first + " " + last
}
var cluster = require('cluster');
var PORT = +process.env.PORT || 1337;
if (cluster.isMaster) {
// In real life, you'd probably use more than just 2 workers,
// and perhaps not put the master and worker in the same file.
cluster.fork();
cluster.fork();
cluster.on('disconnect', function(worker) {
# setup fd 3 as udp connection to drone
exec 3<>/dev/udp/192.168.1.1/5556
# takeoff
echo -e "AT*REF=1,512\r" >&3
# landing
echo -e "AT*REF=2,0\r" >&3
...
# profit?
@tj
tj / example.js
Created July 31, 2013 18:48
console.api()
function params(fn) {
var str = fn.toString();
var sig = str.match(/\(([^)]*)\)/)[1];
if (!sig) return [];
return sig.split(', ');
}
console.api = function(obj){
console.log();
var proto = Object.getPrototypeOf(obj);