Skip to content

Instantly share code, notes, and snippets.

View jameswomack's full-sized avatar
📈

James J. Womack jameswomack

📈
View GitHub Profile
@jameswomack
jameswomack / routeMatching.js
Created February 24, 2014 09:39
Matching routes in a base node.js HTTP server
var http = require('http');
var routes = {
'/foo/.*' : function (req, res) {
res.locals.content = res.locals.content + '<h1>Foo Bar</h1>';
},
'/foo' : function (req, res) {
res.locals.content = res.locals.content + '<h1>Foo</h1>';
}
};
//
// NGViewController.h
// TextFieldChanges
//
// Created by James Womack on 2/28/14.
// Copyright (c) 2014 James Womack. All rights reserved.
//
#import <UIKit/UIKit.h>
const instanceCount = 2;
var IHaveThePower = function (passedInConfig) {
var config = JSON.parse(JSON.stringify(passedInConfig));
var okForPublic = {'foo':0, 'bar':0};
var exports = {};
function publicize(key) {
Object.defineProperty(exports, key, {
@jameswomack
jameswomack / shallowInheritance.js
Last active August 29, 2015 13:57
Shallow Inheritance in JavaScript
var A = function (neighborhood) {
this.neighborhood = neighborhood;
}
A.prototype.getInitial = function () {
return this.neighborhood[0];
}
A.prototype.getLast = function () {
return this.neighborhood[this.neighborhood.length-1];
}
@jameswomack
jameswomack / departmentStore.js
Created March 11, 2014 01:20
Getters|Setters & Private|Public Scope in JavaScript
function DepartmentStore(name, location) {
var define = Object.defineProperty.bind(undefined, this);
define('title', {
get: function () {
return name.concat(' ', location);
}
});
define('location', {
function DepartmentStore(name, location) {
this.getTitle = function () {
return name + ' ' + location;
}
this.setLocation = function (value) {
return location = value;
};
}
public class DepartmentStore {
private String name;
private String location;
public DepartmentStore(String someName, String someLocation) {
name = someName;
location = someLocation;
}
public String getTitle() {
@jameswomack
jameswomack / instanceofMultiLevelInheritance.js
Created March 12, 2014 04:49
Making `instanceof` work on multi-level inheritance structures with JavaScript
function DepartmentStore() {}
DepartmentStore.prototype = Object.create(Function);
var departmentStore = new DepartmentStore;
console.log(departmentStore instanceof Function);
console.log(departmentStore instanceof DepartmentStore);
/*
true
true
@jameswomack
jameswomack / setTimeoutEval.js
Last active August 29, 2015 13:57
Passing a string to `setTimeout` in browsers results in `eval` being used
function logPIAfterDelay() {
setTimeout(function () {
console.log(Math.PI);
}, 1000);
}
function logPIAfterDelayEval() {
setTimeout("console.log(Math.PI)", 1000);
}
var commander = require('commander');
commander.version('0.0.1').command('new');
commander.parse(process.argv);
console.log(commander.commands);
var matches = commander.commands.filter(function(c){
return c._name == commander.args[0];
});
if (!matches.length