Skip to content

Instantly share code, notes, and snippets.

@turnersr
turnersr / jumptable.asm
Created October 18, 2014 17:13
Jump Table Example
start:
0x00401000: pushl %ebp
0x00401001: movl %esp, %ebp
0x00401003: subl $0x8, %esp
0x00401006: movl 0x14(%ebp), %eax
0x00401009: movl %eax, -4(%ebp)
0x0040100c: movl 0x10(%ebp), %ecx
0x0040100f: movsbl (%ecx), %edx
0x00401012: movl %edx, -8(%ebp)
0x00401015: movl -8(%ebp), %eax
@turnersr
turnersr / animating_temperature.py
Created September 28, 2014 20:45
Create temperate over time animation. Example at https://vimeo.com/107410270
from iris import load_cube
import iris.quickplot as qplt
import matplotlib.pyplot as plt
from matplotlib import animation
import sys
# air_temp_location is the directory with your air.sig995 netCDF files
air_temp_location = ""
date = range(1948,2015)
@turnersr
turnersr / sample_dirichlet.py
Last active August 29, 2015 14:00
Sampling from a Dirichlet distribution by sampling from a n-sphere and then projecting onto a n-simplex.
import numpy as np
def projection_on_to_simplex(sphere_point):
# References
# Same implmentation as the one used here at https://gist.github.com/daien/1272551
# Efficient Projections onto the .1-Ball for Learning in High Dimensions - http://machinelearning.org/archive/icml2008/papers/361.pdf
mu = np.sort(sphere_point)[::-1]
mu_sums = np.cumsum(mu)
rho = np.nonzero(mu * np.arange(1, sphere_point.shape[0] + 1) > (mu_sums - 1))[0][-1]
@turnersr
turnersr / rs.py
Created April 29, 2014 04:17
Single-pass, parallel statistics algorithms for mean, variance, and standard deviation
class RunningStat(object):
"""
Based on ideas presented in
1. Numerically Stable, Single-Pass, Parallel Statistics Algorithms - http://www.janinebennett.org/index_files/ParallelStatisticsAlgorithms.pdf
2. Accurately computing running variance - http://www.johndcook.com/standard_deviation.html
"""
def __init__(self):
self.m_n = 0
self.m_oldM = 0
@turnersr
turnersr / dirichlet_pdf.py
Last active August 29, 2015 14:00
Dirichlet pdf in python
import math
import numpy as np
# Another example at http://stackoverflow.com/questions/10658866/calculating-pdf-of-dirichlet-distribution-in-python
def gamma(x):
return math.gamma(x)
Uniregistry, Corp. 9 ['COUNTRY', 'CHRISTMAS', 'PICS', 'PHOTO', 'GIFT', 'LINK', 'GUITARS', 'SEXY', 'TATTOO']
Afilias Limited 8 ['BLACK', 'MEET', '\xe7\xa7\xbb\xe5\x8a\xa8 (xn--6frz82g) \xe2\x80\x93 Chinese for "mobile"', 'BLUE', 'KIM', 'PINK', 'RED', 'SHIKSHA']
United TLD Holdco Ltd. 7 ['DEMOCRAT', 'SOCIAL', 'MODA', 'DANCE', 'IMMOBILIEN', 'KAUFEN', 'NINJA']
United TLD Holdco, Ltd. 7 ['ROCKS', 'CONSULTING', 'HAUS', 'PUB', 'ACTOR', 'REVIEWS', 'FUTBOL']
Top Level Domain Holdings Limited 6 ['VODKA', 'COOKING', 'RODEO', 'HORSE', 'FISHING', 'MIAMI']
@turnersr
turnersr / palau_flag.dart
Created December 23, 2013 01:50
Day 2, use of the the cascade operator.
import 'dart:html';
import 'dart:math';
void main() {
init_palau_flag();
}
void init_palau_flag() {
palau_flag();
}
@turnersr
turnersr / dart.html
Last active December 31, 2015 23:49
Day 1, using Dart to paint circles.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>My First Canvas Example</title>
</head>
<body style="margin:0px">
<Canvas id="my_canvas"> </Canvas>
<script type="application/dart" src="dots.dart"></script>
@turnersr
turnersr / sort_check.ml
Created August 26, 2013 17:01
A simple sort result checker used to test the correctness of sorting function in a black box setting. This is taken from http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.112.3042&rep=rep1&type=pdf .
let x = [1;3;4;5;1;2;10;7];;
let y = List.sort compare x;;
let convert_pos list n =
let rec aux i r = function
| [] -> r
| e::t -> aux (i+1) (r @ [e*n+i]) t
in aux 0 [] list;;