Skip to content

Instantly share code, notes, and snippets.

View jordanorelli's full-sized avatar
🎴

Jordan Orelli jordanorelli

🎴
View GitHub Profile
@jordanorelli
jordanorelli / templates.go
Created August 9, 2012 21:42
primitive template cache in Go with os.Stat
package core
import (
"bytes"
"fmt"
"html/template"
"io/ioutil"
"net/http"
"os"
"path/filepath"
jordanorelli@yupa[0] ~: ab -n 10 -c 10 "http://127.0.0.1:8080/"
This is ApacheBench, Version 2.3 <$Revision: 1178079 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 127.0.0.1 (be patient).....done
Server Software:
Server Hostname: 127.0.0.1
@jordanorelli
jordanorelli / idcache.go
Created August 24, 2012 16:51
fixed-size set in Go
type idCache struct {
data map[string]*string
maxSize int
newest *string
oldest *string
}
func newIdCache(size int) *idCache {
return &idCache{
data: make(map[string]*string, size),
@jordanorelli
jordanorelli / loop.go
Created September 6, 2012 21:59
CPU-blocking test
package main
import (
"fmt"
"runtime"
"time"
)
func main() {
// THIS is totally required; without it, you're blocking the CPU regardless
@jordanorelli
jordanorelli / queue.go
Created September 7, 2012 17:53
an absurd queue implementation with higher-order channels
package main
import (
"fmt"
"math/rand"
"time"
)
type Queue struct {
data []interface{}
@jordanorelli
jordanorelli / chan.go
Created September 7, 2012 19:49
channel example
package main
import (
"fmt"
"math/rand"
"time"
)
func produce(c chan int) {
// loop indefinitely
from random import randint
import gevent
def mightfail():
x = randint(1, 10)
print x
if x == 10:
raise ValueError("that's too big")
return x
from random import randint
import gevent
def mightfail():
x = randint(1, 10)
if x == 10:
raise ValueError("that's too big")
return x
jobs = [gevent.spawn(mightfail) for x in xrange(50)]
from random import randint
from gevent.util import wrap_errors
import gevent
def mightfail():
x = randint(1, 10)
if x == 10:
raise ValueError("that's too big")
return x
from random import randint
from gevent.util import wrap_errors
import gevent
def mightfail():
x = randint(1, 10)
if x == 10:
raise ValueError("that's too big")
return x