Skip to content

Instantly share code, notes, and snippets.

View spikebrehm's full-sized avatar

Spike Brehm spikebrehm

View GitHub Profile
// console.log(global.Client.toString());
function (host, port) {
this.host = host;
this.port = port;
this.socket = require('dgram').createSocket('udp4');
}
@spikebrehm
spikebrehm / tmux.out
Created May 21, 2014 17:02
Named #tmux sessions FTW
vagrant@localhost:~$ tmux list-sessions
railsc: 1 windows (created Wed May 21 16:57:04 2014) [283x66] (attached)
rookery: 1 windows (created Wed May 21 16:56:30 2014) [141x32] (attached)
specs: 1 windows (created Wed May 21 16:58:34 2014) [141x15] (attached)
zeus: 1 windows (created Tue May 20 23:42:45 2014) [141x14] (attached)
@spikebrehm
spikebrehm / htmlDecode.js
Created August 24, 2014 18:53
Is this method of decoding HTML entities safe from XSS injections?
function htmlDecode(input) {
var e = document.createElement('div');
e.innerHTML = input;
return e.childNodes.length === 0 ? "" : e.childNodes[0].nodeValue;
}
░░░░▄▄▄▄▀▀▀▀▀▀▀▀▄▄▄▄▄▄
░░░░█░░░░▒▒▒▒▒▒▒▒▒▒▒▒░░▀▀▄
░░░█░░░▒▒▒▒▒▒░░░░░░░░▒▒▒░░█
░░█░░░░░░▄██▀▄▄░░░░░▄▄▄░░░█
░▀▒▄▄▄▒░█▀▀▀▀▄▄█░░░██▄▄█░░░█
█▒█▒▄░▀▄▄▄▀░░░░░░░░█░░░▒▒▒▒▒█
█▒█░█▀▄▄░░░░░█▀░░░░▀▄░░▄▀▀▀▄▒█
░█▀▄░█▄░█▀▄▄░▀░▀▀░▄▄▀░░░░█░░█
░░█░░▀▄▀█▄▄░█▀▀▀▄▄▄▄▀▀█▀██░█
░░░█░░██░░▀█▄▄▄█▄▄█▄████░█
var name = 'Bob';
var Person = function(name){
this.name = name;
console.log(name);
}
var me = Person('John');
console.log(name);
function Person(name) {
this.name = name;
}
Person.prototype = {
hello : function() {
return "Hello, " + this.name;
}
};
@spikebrehm
spikebrehm / gist:1716171
Created February 1, 2012 09:40
Serving mustache templates using Node and jsdom
var http = require('http'),
fs = require('fs'),
jsdom = require('jsdom'),
mustache = require('mustache');
var global = this;
var trips = [
{
@spikebrehm
spikebrehm / builder.coffee
Created August 16, 2012 17:08
Require not exported to the window?
...
bundle = browserify()
bundle.addEntry('./assets/coffeescripts/lib/renderer.coffee')
src = bundle.bundle()
fs.writeFileSync @config.coffeePath, src, 'utf8'
...
@spikebrehm
spikebrehm / eventable.js
Created March 30, 2012 17:54
Add Backbone-style events to any function's prototype
/**
* This is intended to be a simple behavior mixin that allows Backbone-style event delegation to be added to any object's prototype.
*
* Use:
*
* function MyView(){ this.$el = $('#my_view'); this.delegateEvents(); }
* $.extend(MyView.prototype, Eventable);
* MyView.prototype.events = {'click a.close': 'close'};
* MyView.prototype.close = function(){ this.$el.hide(); }
*
@spikebrehm
spikebrehm / Directory structure
Created January 22, 2013 23:09
Code for blog post: "We've launched our first Node.js app to production!"
| app
|-- collections
|-- controllers
|-- helpers
|-- models
|-- templates
|-- views