Skip to content

Instantly share code, notes, and snippets.

@leeavital
leeavital / bytes
Created August 30, 2017 13:48
convert a byte count to a human readable form
#!/usr/bin/env python3
import sys
import math
totalBytes = int(sys.argv[1])
units = ["bytes", "kilobytes", "megabytes", "gigabytes", "terrabytes", "petabytes"]
unitIndex = int(math.log(totalBytes, 1024))
bytesPerUnit = math.pow(1024, unitIndex)
@leeavital
leeavital / hello.hs
Last active August 29, 2015 14:20
FRP Notes
import UI.HSCurses.Curses
main = do
scr <- initScr
wAddStr scr "Hello world"
k <- getch
endWin
@leeavital
leeavital / debugbuild.sh
Created April 22, 2015 03:54
Debug build
#!/bin/bash
set -e
f=$1
rm -f $f.*.s
rm -f $f.*.ll
@leeavital
leeavital / domath.sml
Last active August 29, 2015 14:18
DSO FFI
fun naiveIsPrime n =
let
fun helper n agg =
if agg = 1 then
true
else if n mod agg = 0 then
false
else
helper n (agg - 1)
in
@leeavital
leeavital / bench.sh
Last active August 29, 2015 14:17
Benchmark
#!/bin/bash
old=old.out
new=new.out
echo "" > tmp
echo "" > out.csv
@leeavital
leeavital / rants
Created November 24, 2014 17:41
Rants -- angry pants
#!/usr/bin/env bash
if [[ $1 = "-h" || $1 = "--help" || -z $1 ]]
then
cat <<EOD
rants -- angry pants
compile
rants c [project]
rants compile [project]
z = raw_input()
z = reduce(lambda x,y:x+y,[ord(x) for x in z])
print z%3
@leeavital
leeavital / gist:5526756
Created May 6, 2013 17:48
The Most Important Problem in the History of Cutlery Science
from itertools import permutations, combinations
chopsticks = ["ch", "op", "st", "icks"]
spoon = ["sp", "oon"]
fork = ["f", "ork"]
knife = ["k", "ni", "fe"]
"chopsticks"