Skip to content

Instantly share code, notes, and snippets.

@yorickvP
yorickvP / scgi.js
Created June 23, 2011 18:52
node.js SCGI server using node-binary
/* requires substack/node-binary and dependencies (npm install binary) */
/* also don't forget node.js */
var net = require('net');
var Binary = require('binary');
exports.attach = function attach(server) {
if ('number' == typeof server) {
var port = server;
server = net.createServer();
@yorickvP
yorickvP / compare.js
Created January 1, 2012 00:59
compose using bindify
var b = require('bindify')
// first make a function that does \ a b -> \ c -> b(a c)
var compose_2 = b(b, null
, Function.prototype.call
, b._1
, b._wrap(b._this)
, nested_b(nested_b, null
, b._0
, b._wrap(b._this)
@yorickvP
yorickvP / boxblurcanvas.js
Created January 16, 2012 14:31
Fast canvas box blur
/*
BoxBlur - a fast almost Box Blur For Canvas
Edited by Yorick to make it faster in modern browsers
Version: 0.3
Author: Mario Klingemann
Contact: mario@quasimondo.com
Website: http://www.quasimondo.com/
@yorickvP
yorickvP / browserify-makedep.js
Last active October 4, 2015 23:17
Browserify dependency listing
#!/usr/bin/env node
// works as a CLI similar to the browserify one, but prints a space-separated list of dependencies for the arguments you give.
// requires browserify (obviously), JSONStream and event-stream.
var JSONStream = require('JSONStream')
, child_process = require('child_process')
, path = require('path')
, es = require('event-stream')
var parser = JSONStream.parse([true])
var cwd = process.cwd()
@yorickvP
yorickvP / gist:2725801
Created May 18, 2012 15:15
Simple (regex) routing in JavaScript
module.exports = function router() {
function router(method, url) {
var r = get_routes(method), rl = r.length
for (var i = 0; i < rl; ++i) {
if (r[i].type == 'string') {
if (r[i].url == url)
return [[url], r[i].callback] }
else {
var route = r[i]
if (route.type == 'regexp') {
@yorickvP
yorickvP / gist:2793942
Created May 26, 2012 13:24 — forked from netdesign/gist:2793843
Autocomplete
<form onsubmit="myAuth.login(), false">
<input type="text" name="name" id="auth_name" autocomplete="on">
<input type="password" name="password" id="auth_passwd" autocomplete="off">
<input type="submit" value="Log In">
</form>
@yorickvP
yorickvP / gist:3171926
Created July 24, 2012 19:05
generic C/C++ project makefile template
ifdef VERBOSE
Q =
E = @true
else
Q = @
E = @echo
endif
CFILES := $(shell find src -mindepth 1 -maxdepth 4 -name "*.c")
CXXFILES := $(shell find src -mindepth 1 -maxdepth 4 -name "*.cpp")
@yorickvP
yorickvP / shutdowner.js
Created November 3, 2012 11:29
Shut down servers nicely
// keeps track of connections to a http server and closes them when the server closes.
function LinkedList() {
this.start = null
this.end = null }
LinkedList.prototype.add = function(data) {
var ref = { data: data, next: null, prev: null }
if (!this.start) this.start = ref
if (this.end) {
@yorickvP
yorickvP / thankstome.user.js
Created January 15, 2013 00:05
warn when you're about to tweet "thanks to me"
// ==UserScript==
// @name Warn when you're about to tweet "thanks to me"
// @namespace http://localhost/
// @version 0.1
// @description Add an alert whenever someone types "thanks to me"
// @match http://twitter.com/*
// @match https://twitter.com/*
// ==/UserScript==
(function() {
@yorickvP
yorickvP / rps.js
Created January 15, 2013 01:13
rock paper scissors for more than 2 players and extensible
function RPS(noPlayers, proto) {
var obj = Object.create(proto || RPS.prototype)
obj.players = noPlayers
obj.score = {}
obj.moves = {}
for (var i = 0; i < noPlayers; i++) {
obj.score[i] = 0
obj.moves[i] = [] }
return obj }