Skip to content

Instantly share code, notes, and snippets.

View goatslacker's full-sized avatar

Josh Perez goatslacker

View GitHub Profile
@goatslacker
goatslacker / iterator.js
Created September 9, 2011 00:12
depth first search
var dfs = {
a: 1,
b: {
c: 2,
d: 3,
e: 4,
f: {
g: 5,
h: 6
},
@goatslacker
goatslacker / improper-hint-reports.js
Created September 11, 2011 07:32
improper jshint warning
var foo = 2+2;
var query = "http://goatslacker.com/?query";
function split() {
var queryString = {};
query.split("?").pop().split("&").forEach(function (prop) {
var item = prop.split("=");
queryString[item.shift()] = item.shift();
});
return queryString;
}
@goatslacker
goatslacker / list.js
Created September 14, 2011 23:07
cutesy little Object storage with Array like functionality
var List = function () {
this.h = {};
this.i = [];
};
List.prototype.set = function (key, val, unshift) {
var op = unshift ? "unshift" : "push";
this.h[key] = val;
@goatslacker
goatslacker / spaceship.coffee
Created October 7, 2011 08:01
creates an svg path for a spaceship based on Dave Bollinger's algorithm
# Based on Dave Bollinger`s work
class Spaceship
constructor: (@size = 5) ->
@ship = ( solid: [], cockpit: [], body: [] )
# map the ship
{ empty, solid, cockpit, body } = @map this
var a = [
34, 203, 3, 746, 200, 984, 198, 764, 9, 4, 17, 200, 242, 23, 12, 2, 98,
49, 32, 64, 23, 45, 95, 75, 34, 507, 123, 454, 76, 34, 12, 5, 23, 55, 11,
95, 45, 33, 63, 66, 234, 76, 76, 45, 44, 77, 22, 12, 90, 9001, 34, 23, 1
];
var merge_sort = (function () {
var merge = function (left, right) {
var result = [];
// write about this, closures and prorotypes.
// can use this
// but new's need to be inside function
var baz = 0;
function Bar() {
this.ct = (baz += 1);
};
var Foo = function () {
this.a = 1;
var foo = (function () {
var bar = 0;
return function () {
bar += 1;
console.log(bar);
};
}());
var woot = foo;
foo();
@goatslacker
goatslacker / minimalist-classes.js
Created November 2, 2011 08:04 — forked from BrendanEich/minimalist-classes.js
less minimalism, richer leather
// A response to jashkenas's fine proposal for minimalist JavaScript classes.
// Harmony always stipulated classes as sugar, so indeed we are keeping current
// JavaScript prototype semantics, and classes would only add a syntactic form
// that can desugar to ES5. This is mostly the same assumption that Jeremy
// chose, but I've stipulated ES5 and used a few accepted ES.next extensions.
// Where I part company is on reusing the object literal. It is not the syntax
// most classy programmers expect, coming from other languages. It has annoying
// and alien overhead, namely colons and commas. For JS community members who
@goatslacker
goatslacker / jqhint
Created November 5, 2011 00:31
jquery jshint options
/*jshint white: false, undef: true, regexp: false, plusplus: false,
eqeqeq: false, eqnull: true, undef: false, evil: true, newcap: false,
forin: false, maxlen: 9001, immed: false */