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 / 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"],
# 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 / 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 / organism.py
Last active January 4, 2016 18:36
NOTE: organism.py belongs in a directory "breeder"
#!/usr/bin/env python
import ast
from os.path import isfile
from hashlib import md5
from random import randint, choice
from glob import glob
import re
# scratch area
"""
@jiaaro
jiaaro / investment_calculator.py
Last active March 16, 2016 04:18
Calculate the value of your investments and savings at some point in the future
class Investment(object):
def cash_invested_by_month(self, month):
raise NotImplementedError
def value_in_month(self, month):
raise NotImplementedError
class SingleInvestment(Investment):
def __init__(self, amount, monthly_interest_rate, month=0):

Keybase proof

I hereby claim:

  • I am jiaaro on github.
  • I am jiaaro (https://keybase.io/jiaaro) on keybase.
  • I have a public key ASAmjWlR2gGlcJGuKzzPQ4UDqxXW0WeP-NDoJACLKWKo7go

To claim this, I am signing this object:

If you've ever wondered what it's be like to "go indie" here is a script with some assumptions that might help you project your income.

Assumptions:

  • You will make a new app every month
  • Apps have a useful life of 3 years (after that they stop earning money)
  • Apps will earn $250 in their launch month
  • Apps will earn $100/mo at first (starting month 2), but that revenue will slowly decline (~50% each year)
  • As you make more apps your brand/mailing list will start to pay dividends (after 4 apps you'll see the numbers above double, after 8 they'll 3x, and so on)

So how would that work out?

@jiaaro
jiaaro / install_nodejs
Last active August 8, 2016 12:50
Put the following files in a folder called `bin` (so they'll be `bin/post_compile` and `bin/install_nodejs`)
#!/usr/bin/env bash
set -eo pipefail
NODE_VERSION=$(curl --silent --get https://semver.io/node/stable)
NODE_BASENAME=node-v${NODE_VERSION}-linux-x64
NODE_ARCHIVE="http://nodejs.org/dist/v${NODE_VERSION}/${NODE_BASENAME}.tar.gz"
# make a temp directory
tempdir="$( mktemp -t node_XXXX )"
rm -rf $tempdir