Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / .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 / 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 / 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 / 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 / server.py
Created December 5, 2012 20:09
simple python server
import SimpleHTTPServer;
map = SimpleHTTPServer.SimpleHTTPRequestHandler.extensions_map;
map[""] = "text/plain"
for key, value in map.items():
map[key] = value + ";charset=UTF-8"
SimpleHTTPServer.test()
@weisjohn
weisjohn / index.html
Created January 2, 2013 04:25
getUserMedia example
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
<video id="sourcevid" autoplay="true">NO SUPPORT FOR VIDEO </video>
</body>
</html>
@weisjohn
weisjohn / twss.coffee
Last active December 17, 2015 09:59 — forked from mutewinter/twss.coffee
That's what see said hubot script.
# Description:
# Use Skynet to determine if a thing that was said is actually something
# S.H.E (Silicon Helix Entity) said.
#
# Dependencies:
# "twss": "0.1.6"
#
# Commands:
# Just say something like, "that was hard". Hubot will do the rest.
#