Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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
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 / 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 [email protected] 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
@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(['+', '/'])
package com.olearyp.ponyboard;
import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import android.webkit.WebSettings;
import android.webkit.WebSettings.ZoomDensity;
import android.webkit.WebView;
public class PonySWFLauncherActivity extends Activity {
@pao
pao / lightworks_process.vcf
Created June 7, 2011 11:49
Parallel convert to Lightworks
VirtualDub.Open(VirtualDub.params[0],"",0);
VirtualDub.audio.SetSource(0);
VirtualDub.audio.SetMode(0);
VirtualDub.audio.SetInterleave(1,500,1,0,0);
VirtualDub.audio.SetClipMode(1,1);
VirtualDub.audio.SetConversion(0,0,0,0,0);
VirtualDub.audio.SetVolume();
VirtualDub.audio.SetCompression();
VirtualDub.audio.EnableFilterGraph(0);
VirtualDub.video.SetInputFormat(0);
@pao
pao / home_dash_keymap.ahk
Created February 10, 2011 00:56
AutoHotkey script fancified to work with the Firefox Home Dash add-on.
#NoTrayIcon
; Original tab switch behavior for most applications
#IfWinNotActive ahk_class MozillaWindowClass
Browser_Back::^PgUp
Browser_Forward::^PgDn
#IfWinNotActive
; Firefox-specific behavior for Home Dash
#IfWinActive ahk_class MozillaWindowClass
@pao
pao / cm-ec2-init.sh
Created November 20, 2010 00:23
Scripts to get and manage CyanogenMOD on an Amazon EC2 instance
#!/bin/bash
# wget https://gist.github.com/raw/707468/cm-ec2-init.sh && . cm-ec2-init.sh
# Epic CM-on-EC2 Init Script for ami-4a0df923
# Preemptively agree to the JDK license
echo "sun-java6-bin shared/accepted-sun-dlj-v1-1 boolean true" | sudo debconf-set-selections
# Get required packages
sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner"
sudo aptitude update