Skip to content

Instantly share code, notes, and snippets.

@weisjohn
weisjohn / github_mega_clone.js
Created November 16, 2012 02:47
clone all my repos using the Github API
var request = require('request'),
u = require('underscore')
exec = require('child_process').exec,
child = null,
repos = null;
request('https://api.github.com/users/weisjohn/repos', function (error, response, body) {
if (!error && response.statusCode == 200) {
// grab all the repos from github
@weisjohn
weisjohn / install_node.sh
Created November 12, 2012 18:54
Install node.js from source
mkdir -p ~/src && cd ~/src
git clone git://github.com/joyent/node.git
cd node
./configure
make
make install
@weisjohn
weisjohn / pntdrrn.js
Created October 12, 2012 03:10
Pseudo Non-Terminating Decimal Represenation of a Rational Number
function test_pntdrrn_regex(pattern, sample, dividend, divisor) {
console.log(
dividend + "/" + divisor + "\t\t" +
pattern.toString() +
( pattern.test(sample) ? "" : " doesn't" ) + " match" +
( pattern.test(sample) ? "es " : " " ) +
"`" + sample + "`"
);
}
@weisjohn
weisjohn / .functions_snippet
Created September 7, 2012 02:17
server()
# Start an HTTP server from a directory, optionally specifying the port
function server() {
local port="${1:-8888}"
open "http://localhost:${port}/"
# Set the default Content-Type to `text/plain` instead of `application/octet-stream`
# And serve everything as UTF-8 (although not technically correct, this doesn’t break anything for binary files)
python -c $'import SimpleHTTPServer;\nmap = SimpleHTTPServer.SimpleHTTPRequestHandler.extensions_map;\nmap[""] = "text/plain";\nfor key, value in map.items():\n\tmap[key] = value + ";charset=UTF-8";\nSimpleHTTPServer.test();' "$port"
}
@weisjohn
weisjohn / upstart
Created August 23, 2012 19:54
upstart example
#!upstart
description "node.js enhancement_renderer"
author "john weis"
start on startup
stop on shutdown
script
export HOME="/root"
@weisjohn
weisjohn / negation.js
Created July 19, 2012 23:13
simple negated addition problem
var operands = "", operation = ""; for (var i = 0; i < 10; i++) { operands += "- + "; operation = '1 + ' + operands + '1'; console.log(operation + ": " + eval(operation) ); }
/*
1 + - + 1: 0
1 + - + - + 1: 2
1 + - + - + - + 1: 0
1 + - + - + - + - + 1: 2
1 + - + - + - + - + - + 1: 0
1 + - + - + - + - + - + - + 1: 2
1 + - + - + - + - + - + - + - + 1: 0
@weisjohn
weisjohn / gist:3092612
Created July 11, 2012 19:26
Enter the Dragon -
// things you should be able to know from javascript, according to Dmitry Baranovskiy - http://www.youtube.com/watch?v=Trr95ij1358
5 - "4";
5 + "4";
+!{}[true]
+[1]
+[1,2]
7 - "a"
7 / 0
@weisjohn
weisjohn / gist:3009515
Created June 28, 2012 06:34
git push hook sample display
#!/bin/bash
$ git push
Counting objects: 5, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 324 bytes, done.
Total 3 (delta 2), reused 0 (delta 0)
remote: % Total % Received % Xferd Average Speed Time Time Time Current
remote: Dload Upload Total Spent Left Speed
@weisjohn
weisjohn / .aliases
Created June 22, 2012 17:49
An alias that pretty-prints git logs as graphs
# this came from jtaby http://www.slideshare.net/jtaby/tools-and-techniques-for-faster-development slide 94
alias gl="git log --graph --pretty=format:'%Cred%h%Creset %C(cyan)%an%Creset - %C(yellow)%d%Creset %s %Cgreen(%cr)%Creset' --abbrev-commit --date=relative"
@weisjohn
weisjohn / gist:2973551
Created June 22, 2012 15:39
git config --global core.excludesfile ~/.gitignore_global
# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.so
# Packages #