Skip to content

Instantly share code, notes, and snippets.

View indexzero's full-sized avatar
🗽
✊ Fist in the air in the land of hypocrisy

Charlie Robbins indexzero

🗽
✊ Fist in the air in the land of hypocrisy
View GitHub Profile
@heapwolf
heapwolf / sesh.js
Created March 3, 2011 17:26
A simplified way to store script state across browser refreshes.
;(function() {
return window.sesh = {
init: function() {
var self = this;
window.addEventListener('unload', function() {
self.serialize();
}, false);
self.parse();
},
/*
A simple new-line delimited JSON protocol with upgrades.
Receiving Usage:
protocol = require('./frame-protocol');
// parsing data
parser = protocol.Parser();
function MemoryCache () {
this.cache = {};
}
MemoryCache.prototype.get(url) {
if (!this.cache[url]) return null;
return {headers:this.cache[url].headers, body:this.cache[url].body.toString()};
}
MemoryCache.prototype.set(url, headers, body) {
this.cache[url] = {headers:headers, body:new Buffer(body)};
}
@bmeck
bmeck / preloader.js
Created March 28, 2011 18:05
An extensible preloader
//
// Create our type
//
function PreLoader() {
this._queue = [];
this._mime = {};
this._handlers = {};
this._loaded = [];
};
PreLoader.prototype.addFileType = function addFileType(extension,mime) {
@3rd-Eden
3rd-Eden / detect.client.socket.io.js
Created April 5, 2011 08:20
Serverside client transport detection for Socket.io
require.paths.unshift('/usr/local/lib/node/socket.io/lib/socket.io/transports');
var htmlfile = require('htmlfile')
, flashsocket = require('flashsocket')
, jsonppolling = require('jsonp-polling')
, websocket = require('websocket')
, xhrmultipart = require('xhr-multipart')
, xhrpolling = require('xhr-polling');
var http = require('http')
, io = require('socket.io');
@nesquena
nesquena / killmatch
Created April 6, 2011 02:52
Kills all processes matching a pattern (killmatch)
# !/usr/bin/env ruby
# USAGE
# sudo killmatch Rails
unless ARGV[0]
puts "Specify a pattern to kill! i.e killmatch Rails"
exit
end

Currently the AMD syntax requires a large amount of repetition just to always get access to our required modules, this could be simplified by doing the following:

/**
 * Defines a new module
 *
 * @param {String} name         An optional name for the module || filename.
 * @param {Array}  dependencies Dependencies for the module, can be omitted.
  • @param {Function|Object} module The Modules code.
////////////// SETUP /////////////////
sleep = (time, fun) { setTimeout fun, time }
global.dawn = require("../node/bridge").load("../cpp/dawncontroller/dawncontroller")
global.__ = require "pipe_utils"
Units = require "./units"
Unit = Units.Unit
instruments = require "./instruments"
@cowboy
cowboy / var-indenting.js
Created April 28, 2011 16:26
JavaScript var indenting thoughts.
// I don't have answers yet, just questions. Keep in mind that I prefer code
// that is easiest to maintain.
// Example from http://www.nczonline.net/blog/2010/10/26/wanted-dynamic-execution-contexts-in-javascript/
// Consider:
// Let's say you start with this, but need to (in a later commit) add a few
// additional vars.
var myglobal = {
@140bytes
140bytes / LICENSE.txt
Created May 9, 2011 16:13
140byt.es -- Click ↑↑ fork ↑↑ to play!
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 YOUR_NAME_HERE <YOUR_URL_HERE>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE