Skip to content

Instantly share code, notes, and snippets.

View huonw's full-sized avatar

Huon Wilson huonw

View GitHub Profile
@huonw
huonw / link-mine.py
Created January 29, 2012 11:02
Link mine Less Wrong
@huonw
huonw / blah.R
Created March 7, 2012 06:57
R histogram
hist(waiting, breaks=min(waiting) + 0:20*(max(waiting) - min(waiting))/20)
@huonw
huonw / ahfkjahsdkfha.c
Created March 7, 2012 10:15
pthread v0.0.0.0.0.1
#include<stdio.h>
#include<stdlib.h>
#include<pthread.h>
// debugging
#define HERE() printf("%s:%s:%d\n", __FILE__, __func__, __LINE__)
#define LENGTH 100000000
#define NUM_THREADS 2
@huonw
huonw / gist:2413449
Created April 18, 2012 13:09
rot13 bookmarklet
javascript:function%20convert(inText){var%20outText='',t;for(i=0;i<inText.length;i++){t=inText.charCodeAt(i);if((t>64&&t<78)||(t>96&&t<110))t%20+=%2013;else%20if((t>77&&t<91)||(t>109&&t<123))t%20-=%2013;outText%20+=%20String.fromCharCode(t);}return%20outText;}var%20sel=window.getSelection().getRangeAt(0);if(sel==''){var%20act=document.activeElement;if(act.type=="textarea"){var%20start=act.selectionStart,end=act.selectionEnd;if(start!=end){var%20prefix=act.value.substring(0,start);var%20middle=convert(act.value.substring(start,end));var%20suffix=act.value.substring(end);act.value=prefix;act.value%20+=%20middle;void(act.value%20+=%20suffix);}}else{void(inText=prompt('Phrase...',''));if(inText)alert(convert(inText));}}else{out=convert(sel.toString());sel.deleteContents();var%20span=document.createElement("span");span.innerHTML=out;sel.insertNode(span);}
#!/usr/bin/env python3
import sys, random
incrs = 10000
try:
processes = int(sys.argv[1])
counters = int(sys.argv[2])
except:
counters = 100
#!/usr/bin/env python
import sys, argparse
p = argparse.ArgumentParser()
p.add_argument('levels', type=int, help='height of tree')
p.add_argument('--procs', type=int, default=4,help='num processors')
p.add_argument('-d', type=float, default=0.999999,help='damper')
p.add_argument('--deg', type=int,default=2,help='degree of tree')
javascript:function convert(e){var t="",n;for(var r=0;r<e.length;r++){n=e[r].toUpperCase();if(dic.hasOwnProperty(n)&&dic[n].length>0){var i=dic[n];t+="[["+i[Math.floor(Math.random()*i.length)]+"]]"}else t+=n}return t}var dic={" ":["156142887792515"],A:["I.have.letter.A","107015582669715"],B:["146468602064836","116067591741123","515425308486884","123610221018617"],C:["53872404042","imagineifyoucouldntc"],D:["322391688648","112542438763744"],E:["91766446175","115430438474268","283780138400963","123538490993811"],F:[],G:["Google","111532845537326","234343043309512"],H:["111356865552629"],I:["124741367672248"],J:["40324932642"],K:["221460146083","56926372437"],L:[],M:["theletterM.mcr"],N:["TheLetterN"],O:["307606749307431"],P:[],Q:["333248933364176","theletterqcafe"],R:["106699962703083"],S:["19thletter"],T:["440658102627745"],U:["156366047808011"],V:["77189649729"],W:["302663476724"],X:["124482324249542"],Y:["112991612048936"],Z:["165724910215"],"?":["466839490011958","173756546013139"],"!":["IWubLiterature"]};v
use T = core::io;
fn main() {
T::println("test");
}
#include<stdio.h>
int main() {
puts("to terminal 1");
fflush(stdout);
int fd = dup(fileno(stdout));
freopen("out-file.txt", "w", stdout);
puts("to file");
@huonw
huonw / borrow.rs
Last active December 15, 2015 04:39
fn borrow(s: &'a str) -> &'a str {
s
}
fn make_str() -> ~str { ~"foo" }
fn main() {
let x = borrow(make_str());
/* Current solution:
let temp = make_str();