Skip to content

Instantly share code, notes, and snippets.

View jameswomack's full-sized avatar
📈

James J. Womack jameswomack

📈
View GitHub Profile
@jameswomack
jameswomack / gist:9801263
Created March 27, 2014 06:00
Snippets for cleaning up your repo
# Is request needed?
grep -rn 'request\.' ./lib/*.js
# Uninstall and remove from package.json
npm uninstall proxy-out --save-dev
# Delete npm_modules folders that aren't assigned in package.json
npm prune
@jameswomack
jameswomack / foo.js
Created April 8, 2014 07:25
detachable command
function command(cmd, shouldEnd, shouldDetach) {
var args = cmd.trim().split(' ');
var cmdName = args.shift();
var opts = shouldDetach ? {detached: true, stdio: ['ignore', out, err] } : {};
var child = require('child_process').spawn(cmdName, args, opts);
if (shouldDetach) {
console.log('Spawned child ' + cmdName + ' with pid ' + child.pid);
child.unref();
@jameswomack
jameswomack / foo.js
Created April 8, 2014 07:29
Clean piped input
var stream = require('stream');
var util = require('util');
function Clean(options) {
if (!(this instanceof Clean)) {
return new Clean(options);
}
stream.Transform.call(this, options);
}
@jameswomack
jameswomack / pmoAuthUrl.txt
Created April 10, 2014 01:33
PMO Auth URL that fails to redirect
http://auth.api.sonyentertainmentnetwork.com/2.0/oauth/authorize?response_type=code&client_id=55950157-ae9d-4b10-b0de-94dbef199f2c&scope=openid&state=eyJjYW5jZWxVUkwiOiJodHRwczovL2FsZy5uZG1kaHMuY29tL2NvbXBvbmVudD9hPW4mZj1lJnM9bnAmcD1vMiZ0eXBlPWF1dGhvcml6YXRpb25fY29kZSZlbnRpdHlJZD0wMDAwMDAwMDAwMDAwMDM1Jm5wRW52PW5wJm89YyZhaz0yMWkyYWJvVDdXQTAwUFkxcE1mZlhlVzFoU3EwMDkwMDBPRU1FeUdIT3VRMzQwSjFxSE9xaERnMTBEMGkwc1dlQWVEMEFwQTBrTWxlZ095cXpJaVV5NVMzbCZyPXImcmV0dXJuVVJMPWh0dHBzJTNBJTJGJTJGcGxheW1lbW9yaWVzb25saW5lLmNvbSUyRmFjY291bnQlMkZsb2dpbiZuZXdUb2tlbj10cnVlIiwic2VydmljZUVudGl0eSI6Im5wIiwidGhlbWUiOiJsaXF1aWQiLCJmbG93IjoiY3JlYXRlQWNjb3VudEV4dGVybmFsIiwicmV0dXJuVVJMIjoiaHR0cHM6Ly9hbGcubmRtZGhzLmNvbS9jb21wb25lbnQ%2FYT1uJmY9ZSZzPW5wJnA9bzImdHlwZT1hdXRob3JpemF0aW9uX2NvZGUmZW50aXR5SWQ9MDAwMDAwMDAwMDAwMDAzNSZucEVudj1ucCZvPWMmYWs9MjFpMmFib1Q3V0EwMFBZMXBNZmZYZVcxaFNxMDA5MDAwT0VNRXlHSE91UTM0MEoxcUhPcWhEZzEwRDBpMHNXZUFlRDBBcEEwa01sZWdPeXF6SWlVeTVTM2wmcj1yJnJldHVyblVSTD1odHRwcyUzQSUyRiUyRnBsYXltZW1vcmllc29ubGluZS5jb20lMkZhY2NvdW50
@jameswomack
jameswomack / loop_recursion_right.js
Last active August 29, 2015 13:59
Right & Wrong: Loop recursion
function Students(classroom){
this.relationships = {};
this.reverseSearchMap = {};
this.students = classroom.students;
}
Students.prototype.populate = function(){
for(var index = 0; index < this.students.length; index++){
var student = students[index];
var studentName = this.fullNameForStudent(student);
new (function weAreAnonymous(){
console.log(this.constructor.name);
})() // weAreAnonymous
@jameswomack
jameswomack / self_this.js
Last active August 29, 2015 13:59
Examples of eliminating `self = this`
/* WRONG */
function Sobachi(){
this.prefecture = 'Iwate';
this.characterName = 'Sobatchi';
this.friends = [];
}
Sobachi.prototype.addFriends = function(friends){
var self = this;
@jameswomack
jameswomack / testedProject.txt
Created April 14, 2014 05:29
Each JS module should have it's own test file
package.json
Gulpfile.js
index.js
lib
-> foo.js
-> bar.js
-> baz.js
node_modules
config
-> index.js
mooshoo()
background url('mooshoo.png')
foo(i)
-webkit-foo: i;
-opera-foo: i;
-mozilla-foo: i;
foo: i;
#foo
@jameswomack
jameswomack / herokuPull.sh
Created April 15, 2014 01:17
Pull your Heroku app down on a different machine
heroku keys:add ~/.ssh/id_rsa.pub
heroku git:clone -a app-name-here