Skip to content

Instantly share code, notes, and snippets.

@pao
pao / joco_brute_decode.py
Created December 3, 2011 21:32
Brute-force script to decode the Artificial Heart Level 4 easter-egg image
from base64 import b64decode
import struct
from zlib import crc32
b64alphabet = []
b64alphabet.extend([chr(x) for x in range(ord('A'),ord('Z')+1)])
b64alphabet.extend([chr(x) for x in range(ord('a'),ord('z')+1)])
b64alphabet.extend([chr(x) for x in range(ord('0'),ord('9')+1)])
b64alphabet.extend(['+', '/'])
@pao
pao / getHeart.py
Created January 20, 2012 06:17
Script to batch download additional digital materials for Artificial Heart Level 4.
'''
Usage: python getHeart.py YOURCODE your@email.com someregex
The "someregex" matches against the link text.
For instance:
* "flac" will get all the FLAC downloads
* "flac|VIDEO" will get FLAC and video
and so on.
'''
import os
load("ode.jl")
#load("winston.jl")
msdsys(t,y,m,b,k,Fext,xoff) = [0 1; -k./m b./m]*y + [0 0; sin(t.^2)./m k./m]*[Fext xoff]'
msdsys(t,y) = msdsys(t, y, 5, -0.5, 50, 0, 0)
function msd_analytic(t, m, b, k, x0)
wn = sqrt(k./m)
zeta = -b./m./2./wn
wd = wn.*sqrt(1-zeta.^2)
@pao
pao / total.hs
Created March 15, 2012 17:11
Add numbers in a file (sample problem)
module Total where
import Data.Char
import System.IO
main = do
contents <- readFile "numbers.txt"
print $ add_up contents
add_up :: String -> Double
@pao
pao / PKbench.jl
Created March 29, 2012 20:00
Benchmarking some Julia functions derived from R functions
# in http://dmbates.blogspot.com/2012/03/pk-models-in-r-and-in-julia.html I describe
# the motivation behind these functions. The test data is extracted from an R data set
# Use semicolons between elements to ensure this is a vector
Time = [0; 0.25; 0.57; 1.12; 2.02; 3.82; 5.1; 7.03; 9.05; 12.12; 24.37; 0; 0.27; 0.52; 1; 1.92; 3.5; 5.02; 7.03; 9; 12; 24.3; 0; 0.27; 0.58; 1.02; 2.02; 3.62; 5.08; 7.07; 9; 12.15; 24.17; 0; 0.35; 0.6; 1.07; 2.13; 3.5; 5.02; 7.02; 9.02; 11.98; 24.65; 0; 0.3; 0.52; 1; 2.02; 3.5; 5.02; 7.02; 9.1; 12; 24.35; 0; 0.27; 0.58; 1.15; 2.03; 3.57; 5; 7; 9.22; 12.1; 23.85; 0; 0.25; 0.5; 1.02; 2.02; 3.48; 5; 6.98; 9; 12.05; 24.22; 0; 0.25; 0.52; 0.98; 2.02; 3.53; 5.05; 7.15; 9.07; 12.1; 24.12; 0; 0.3; 0.63; 1.05; 2.02; 3.53; 5.02; 7.17; 8.8; 11.6; 24.43; 0; 0.37; 0.77; 1.02; 2.05; 3.55; 5.05; 7.08; 9.38; 12.1; 23.7; 0; 0.25; 0.5; 0.98; 1.98; 3.6; 5.02; 7.03; 9.03; 12.12; 24.08; 0; 0.25; 0.5; 1; 2; 3.52; 5.07; 7.07; 9.03; 12.05; 24.15]
# Or use the columnization indexing trick, this also work
@pao
pao / glm.jl
Created March 29, 2012 22:57
Implementing Generalized Linear Models in Julia
type Link
name::String
linkFun::Function
linkInv::Function
muEta::Function
end
type Dist
name::String
variance::Function
@pao
pao / banner.txt
Created April 2, 2012 05:26
Helper to write the MLP Music Archive update script
==============================================
= MLP MUSIC ARCHIVE UPDATER =
==============================================
= v007ab: "Sneak Attack! Huge Album Update!" =
==============================================
This program will delete any unnecessary, duplicated, or buggy files from the
previous update.
Be sure this file is at the ROOT of the Archive folder (With the README.TXT,
@pao
pao / png.jl
Created April 8, 2012 00:36
Sample of struct.jl usage
# Sample of struct.jl: Reading a .png header
load("struct.jl")
fpng = open(ARGS[1])
# check the signature
signature = unpack(s"BcccBBBB", fpng)
@assert isequal(signature, struct(s"BcccBBBB", 0x89, 'P', 'N', 'G', 0x0D, 0x0A, 0x1A, 0x0A))
# read the header
VLRU w/MRU at vector end (same timings as 240590 but with this explanatory note)
UnboundedVLRU(), 50 items
Assignment:
elapsed time: 0.09535598754882812 seconds
Lookup, random access:
elapsed time: 0.015466928482055664 seconds
Random mixed workload:
elapsed time: 0.0009279251098632812 seconds
UnboundedVLRU(), 500 items
Assignment:
LLRU
UnboundedLLRU(), 50 items
Assignment:
elapsed time: 0.09373784065246582 seconds
Lookup, random access:
elapsed time: 0.018180131912231445 seconds
Random mixed workload:
elapsed time: 0.0008568763732910156 seconds
UnboundedLLRU(), 500 items
Assignment: