Skip to content

Instantly share code, notes, and snippets.

Stephen Wyatt Bush wyattdanger

Block or report user

Report or block wyattdanger

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View jokes
{setup:"Our wedding was so beautiful,",punchline:"even the cake was in tiers"},{setup:"I'm reading a book on the history of glue",punchline:"I just can't seem to put it down"},{setup:"What do you call an Argentinian with a rubber toe?",punchline:"Roberto"},{setup:"I am terrified of elevators,",punchline:"I'm going to start taking steps to avoid them"},{setup:"Why do crabs never give to charity?",punchline:"Because they're shellfish."},{setup:"Why don't skeletons ever go trick or treating?",punchline:"Because they have no body to go with"},{setup:"What do you call cheese by itself?",punchline:"Provolone"},{setup:'"Ill call you later."',punchline:"Don't call me later, call me Dad"},{setup:"Dad, I'm hungry.",punchline:"Hello, Hungry. I'm Dad"},{setup:"Where does Fonzie like to go for lunch?",punchline:"Chick-Fil-Eyyyyyyyy"},{setup:"Did you hear about the cheese factory that exploded in France?",punchline:"There was nothing left but de Brie"},{setup:"I knew I shouldn’t have had the seafood",punchline:"I’m feeling
@wyattdanger
wyattdanger / linked-list.js
Created Sep 28, 2012
simple implementation, does not handle errors
View linked-list.js
/*
* LinkedList
* Very simple LinkedList implementation
*/
function Node(item, next) {
this.item = item;
this.next = next;
}
View plan.js
var Plan = (function() {
// protected
var records = [];
// the Plan constructor
function Plan(id, price) {
this.id = id;
this.price = price;
records.push(this);
View setup_load_paths.rb
if ENV['MY_RUBY_HOME'] && ENV['MY_RUBY_HOME'].include?('rvm')
begin
rvm_path = File.dirname(File.dirname(ENV['MY_RUBY_HOME']))
rvm_lib_path = File.join(rvm_path, 'lib')
#$LOAD_PATH.unshift rvm_lib_path
require 'rvm'
RVM.use_from_path! File.dirname(File.dirname(__FILE__))
rescue LoadError
raise "RVM ruby lib is currently unavailable."
end
@wyattdanger
wyattdanger / timeouts.js
Created May 25, 2012
events can be scheduled while code is running, but can't be executed until the runtime is free
View timeouts.js
var start = new Date();
setTimeout(function () { var end = new Date(); console.log("Timeout 3ms elapsed:", end - start, "ms"); }, 3);
setTimeout(function () { var end = new Date(); console.log("Timeout 2ms elapsed:", end - start, "ms"); }, 2);
setTimeout(function () { var end = new Date(); console.log("Timeout 1ms elapsed:", end - start, "ms"); }, 1);
while( new Date() - start < 2000 ) {}
setTimeout(function () { var end = new Date(); console.log("Timeout 0ms elapsed:", end - start, "ms"); }, 0);
View squareroot.coffee
squareRoot = ( num ) ->
square = ( x ) -> x * x
avg = ( x, y ) -> (x + y) / 2
goodEnough = ( x ) -> Math.abs( square( x ) - num ) < 0.01
improveGuess = ( x ) -> avg( x, num/x )
iter = ( guess ) ->
return guess if goodEnough guess
iter improveGuess guess
iter 1.0
View longestCommonPrefix.js
function longestCommonPrefix ( arr ) {
var result = "";
var firstWord = arr[0];
for ( var i = 0; i < firstWord.length; i++ ) {
for ( var j = 0; j < arr.length; j++) {
if ( firstWord[i] === arr[j][i]) {
continue;
} else {
return result;
@wyattdanger
wyattdanger / further-example.diff
Created May 1, 2012
to give each instance of Bar it's own `a` property, rather than a shared `a` on the prototype
View further-example.diff
function Foo () {
this.a = [];
}
+function Bar () {
+ Foo.call(this);
+}
-function Bar () {}
Bar.prototype = new Foo();
@wyattdanger
wyattdanger / inheritance-demo.js
Created May 1, 2012
Contrasting prototypal inheritance in JavaScript with classical inheritance in Ruby. In this gist you'll find a JavaScript file and a Ruby file which try to do the same thing, the outputs of each file, and a diff of the two outputs.
View inheritance-demo.js
var inspect = require('util').inspect, // To help with printing to console
log = console.log;
// Define class Foo
function Foo () {
this.a = [];
}
// Define class Bar which inherits from Foo
function Bar () {}
@wyattdanger
wyattdanger / simple-parser
Created Apr 23, 2012
simple parser in peg.js
View simple-parser
start =
expression
expression =
_ a:atom
{ return a }
/ _ "(" a:expression b:expression* ")"
{ return [a].concat(b) }
You can’t perform that action at this time.