Skip to content

Instantly share code, notes, and snippets.

View neale's full-sized avatar
🧶
zen

Neale Ratzlaff neale

🧶
zen
View GitHub Profile
@neale
neale / Program timer
Last active August 29, 2015 14:19
Times programs in your directory and logs times to a file
#!/usr/bin/env bash
trap 'exit' ERR
set -u
DIR="$(pwd)"
LOG="$DIR/times/times.txt"
PROGRAMS=($(find $DIR -maxdepth 1 -type f | grep -v "$(basename $0)"))
mkdir -p $DIR/times
touch $LOG
echo "timing for each random array"
for i in "${PROGRAMS[@]}"; do
@neale
neale / get_runtime.sh
Last active August 29, 2015 14:20
Runs every program in a directory and redirects output to a log file
#!/usr/bin/env bash
trap 'exit' ERR
set -u
DIR="$(pwd)"
LOG="$DIR/times/times.txt"
PROGRAMS=($(find $DIR -maxdepth 1 -type f | grep -v "$(basename $0)"))
mkdir -p $DIR/times
touch $LOG
read -a ITERATIONS <<< "1 5 10 50 100 500 1000 5000 10000 50000 100000"
echo "timing for each random array"
@neale
neale / variable_name.js
Last active August 29, 2015 14:20
Two functions to find the longest possible variable length, which turns out the be the max memory allocation to a node process
#!/usr/bin/env node
function name1(err) {
var name = '';
var interation = 0;
for (var i = 0; i < 9007199254740992; ++i) {
delete global[name];
name += 'x';
global[name] = 42;
iteration = i;
//speed up the printing, console.log is a snail
@neale
neale / factor.py
Last active August 29, 2015 14:20
Finds common factor between two unorganized lists
#!/usr/bin/env python
def answer(x, y):
sum_x, sum_y = sum(x), sum(y)
before = max(x, y)
after = min(x, y)
if after == 0:
return 100
return int(round(abs((sum(before) / sum(after) - 1)) * 100))
#!/usr/bin/env python
def answer(x):
len_x = len(x)
sum_x = sum(x)
if sum_x % len_x == 0:
return len_x
else:
return len_x - 1
#!/usr/bin/env python
def changeslow(coins, amounts, highest, sum_coins, goal, store):
if sum_coins == goal:
store == show(coins, amounts, store)
return
if sum_coins > goal:
return
for value in amounts:
@neale
neale / PGP.txt
Last active August 29, 2015 14:21
PGP
```
-----BEGIN PGP MESSAGE-----
Version: GnuPG v1
owGbwMvMwMR4MoOlxuXq1RjG0wfeJTGERs0/X62UlJ9SqWRVrZSck5maVwJi5SXm
pipZKWWnViYlFqfqZeYr5OWnpOplFStA1egolaUWFWfm5wFVGeiZ61ko1eqAlIM0
p2XmpacWFRRlgsxSMjNOTTI2TEtNMrNINTMxSjQxTTY3SrY0TbY0szAwMU82MUkx
TTE1TQYamZFfXIJiqxLYzPjMFKCoM0S9s4mJi6mLqakzUK4ULJFqlGJsYGZsnJqa
ZpyWmGSUmpiYbGmRmJyYapqaZGpgAFJYnFoE9VJeamJOalFiSVVOYloayNFAqbLM
5FQkX6dnlmSUJmHRBlJeUlkA4penJsVDdcYnZealAL2MHCaGQJXJJZkgrYYmxkYG
def rolling_apply_slow(a, w):
print len(a)
"""applys a function to a window slowly b/c python loops != c loops"""
r = np.empty(a.shape)
r.fill(np.nan)
for i in range(w-1, a.shape[0]):
r[i] = max(a[(i-w+1):i+1])
print len(r)
return r
@neale
neale / ugh.py
Created October 8, 2015 23:48
Python minification for OS1
for i in range(3):
with open('./txt-file-'+str(i)+'.txt', 'wb+') as f:
for x in {f.write, __import__('__builtin__').__dict__['print']}:
x(str([__import__('random').__dict__['choice'](map(chr,range(97, 123))) for n in range(10)]))
print __import__('random').__dict__['randint'](1, 43) * __import__('random').__dict__['randint'](1, 43)
#!/usr/bin/env python
import subprocess
chapters = [
'intro',
'linear_algebra',
'prob',
'numerical',
'ml',