Skip to content

Instantly share code, notes, and snippets.

@jiaaro
jiaaro / simpleTarget.js
Last active December 16, 2015 06:39
Partially de-obfuscated simpleTarget() from nodewar.com
// nodewar.com library function…
// o.lib.targeting.simpleTarget(ship, pos)
//
// mostly deobfuscated/deminified
//
function simpleTarget(ship, pos) {
var i, r, h,
torque = 0,
thrust = 0,
dir = o.lib.targeting.dir(ship, pos);
@jiaaro
jiaaro / script.bash
Created April 24, 2013 14:45
Embed Python in a bash script
#!/bin/bash
export FOO=100
python - <<END
import os
print "foo:", os.environ['FOO']
END
@jiaaro
jiaaro / knn_solution.py
Created June 4, 2013 00:19
solution to the homework in "Machine Learning for Humans: K Nearest-Neighbor" at (http://www.jiaaro.com/KNN-for-humans/)
from collections import Counter
K = 3
dataset = [
# weight, color, # seeds, type
[303, 3, 1, "banana"],
[370, 1, 2, "apple"],
[298, 3, 1, "banana"],
[277, 3, 1, "banana"],
[377, 4, 2, "apple"],
@jiaaro
jiaaro / getjson.js
Last active January 9, 2019 09:10
super simple implementation of getJSON
function getJSON(url, cb) {
var xhr = new XMLHttpRequest();
xhr.open("GET", url, true);
xhr.onreadystatechange = function() {
if (xhr.status != 200 || xhr.readyState != 4) return;
cb(JSON.parse(xhr.responseText));
}
xhr.send();
};
# add new database to addons before running this
# fill in the blank
# eg. DBNAME=HEROKU_POSTGRESQL_ROSE <- new Database
DBNAME=HEROKU_POSTGRESQL_ROSE
heroku maintenance:on
heroku scale web=0
heroku pgbackups:capture --expire
@jiaaro
jiaaro / retirement calc.md
Last active December 3, 2022 18:51
A Simple, Easy-to-edit Retirement Saving Calculator (in python)

Retirement Calculator

  • ages are in years
  • contribution, and savings are in dollars
  • avg_annual_return is a ratio, so 1.07 is a 7% annual return

let's say I'm 25 years old, I am going to contribute $2000/yr in bonds (~5% return), and I've already invested $5700 in bonds

@jiaaro
jiaaro / sub.js
Last active December 27, 2015 18:48
v1 of implementing xkcd substituions: http://xkcd.com/1288/
function replace(txt) {
txt = txt.replace(/witnesses/gi, "dudes I know");
txt = txt.replace(/allegedly/gi, "kinda probably");
txt = txt.replace(/new study/gi, "tumblr post");
txt = txt.replace(/rebuild/gi, "avenge");
txt = txt.replace(/space/gi, "spaaace");
txt = txt.replace(/google glass/gi, "virtual boy");
txt = txt.replace(/smartphone/gi, "pokédex");
txt = txt.replace(/electric/gi, "atomic");
txt = txt.replace(/senator/gi, "elf-lord");
@jiaaro
jiaaro / audioop.py
Last active January 2, 2016 12:59
add audioop.max() to pypy? twitter: @jiaaro - email: me@jiaaro.com
import struct
import math
from ctypes import create_string_buffer
class error(Exception):
pass
# this module redefines the names of some builtins that are used
max_ = max
@jiaaro
jiaaro / marco_arment.py
Created March 7, 2014 14:07
Marco Compatibility
import warnings
import random
if random.random() > 0.999:
warnings.warn("Hi marco, nice day today, eh?")
@jiaaro
jiaaro / exploit.js
Created May 29, 2014 14:45
XSS Game level 6
alert('adsf')