Skip to content

Instantly share code, notes, and snippets.

import functools
class memoize(object):
def __init__(self, func):
self.func = func
self.cache = {}
def __call__(self, *args):
return self.cache_get(args, lambda: self.func(*args))
def __get__(self, obj, objtype):
return self.cache_get(obj, lambda: self.__class__(functools.partial(self.func, obj)))
@bradfitz
bradfitz / gist:1080828
Created July 13, 2011 17:38
Go optional args, v2
package main
import (
"fmt"
)
type Person struct {
Name string
Age int
Position string
@adharris
adharris / postgres_array.go
Created November 28, 2012 19:52
PostgreSQL demo of Array types using Golang
package main
import (
"database/sql"
"errors"
"fmt"
_ "github.com/bmizerany/pq"
"os"
"regexp"
"strings"
@atavener
atavener / ev.ml
Created January 12, 2015 22:55
Safer and easier interface layer atop Tsdl.Sdl.Event
(* __ Interface-layer atop Tsdl.Sdl.Event _______________
*
*
* Rationale for not using Tsdl directly for events:
*
* -Tsdl events are too raw -- easily able to read incorrect fields without
* generating a compile-time error.
*
* -Tsdl events are cumbersome to use: "Sdl.Event.(get e long_field_name)",
* and event container "e" must be in scope.