Skip to content

Instantly share code, notes, and snippets.

View jamwt's full-sized avatar

Jamie Turner jamwt

View GitHub Profile
@jamwt
jamwt / mirror_hackage.py
Created August 14, 2012 19:26
Hackage Mirror Script (Python 2)
# requires python-requests.org
import sys
import requests
import os
import hashlib
import traceback
if len(sys.argv) < 2:
sys.stderr.write("error: require path to mirror base as first argument")
raise SystemExit(1)
var c, c1, c2, c3 chan int
var i1, i2 int
select {
case i1 = <-c1:
print("received ", i1, " from c1\n")
case c2 <- i2:
print("sent ", i2, " to c2\n")
case i3, ok := (<-c3): // same as: i3, ok := <-c3
if ok {
print("received ", i3, " from c3\n")
data Waiter = WaitHandle Handle
| WaitMVar (MVar a)
| WaitChan (Chan b)
| WaitTimeout Int
wait :: [Waiter] -> Waiter
#include <czmq.h>
#define NUM_MESSAGES (50000000)
void no_op(void *unused1, void *unused2) {}
void run_send() {
zctx_t *ctx = zctx_new();
void *outsock = zsocket_new(ctx, ZMQ_PUSH);
zsocket_connect(outsock, "tcp://localhost:5005");
$ httperf --verbose --num-conns=100 --num-calls=100 --port=4000
httperf --verbose --client=0/1 --server=localhost --port=4000 --uri=/ --send-buffer=4096 --recv-buffer=16384 --num-conns=100 --num-calls=100
httperf: maximum number of open descriptors = 1024
reply-rate = 673.6
reply-rate = 611.0
reply-rate = 660.8
Maximum connect burst length: 1
Total: connections 100 requests 10000 replies 10000 test-duration 15.447 s
localhost:~ jamie$ dig @4.2.2.1 ptr 4.2.2.1
; <<>> DiG 9.8.3-P1 <<>> @4.2.2.1 ptr 4.2.2.1
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 27874
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 0
;; QUESTION SECTION:
import Control.Concurrent (forkIO, threadDelay)
import Control.Concurrent.Chan (newChan, readChan, writeChan)
import Control.Monad (replicateM_, replicateM, mapM_)
import Data.Function (on)
import Data.List as List
data MapItem a =
Item Int a
| Done
@jamwt
jamwt / gist:8348851
Last active January 2, 2016 19:09
Fib with Python, Kaleidoscope, and C. gcc -O2 ghc --make -O2
# Python
[hsenv]jamwt@tango:~/contrib/kaleidoscope/src/chapter7$ cat test.py
def fib(x):
if x < 3:
return 1
else:
return fib(x-1)+fib(x-2)
print fib(45)
@jamwt
jamwt / keybase.md
Created May 23, 2014 18:52
keybase.md

Keybase proof

I hereby claim:

  • I am jamwt on github.
  • I am jamwt (https://keybase.io/jamwt) on keybase.
  • I have a public key whose fingerprint is 9187 BBB5 9A2E 835A 1065 EF05 EC63 C37B 9089 B161

To claim this, I am signing this object:

struct Foo<A: Send> {
transformer: |A| -> A,
}