This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
RE_LOG = re.compile( | |
'(?P<ip>[(\d\.)]+) ' | |
'- - ' | |
'\[(?P<timestamp>.*?)\] ' | |
'"(?P<request>.*?)" ' | |
'(?P<status>\d+) ' | |
'(?P<size>\d+) ' | |
'"(?P<referrer>.*?)" ' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
import hashlib | |
import unstdlib | |
RE_WALLET_ADDRESS = re.compile('^[a-zA-Z1-9]{27,35}$') | |
ALPHABET_BASE58 = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz' | |
class NETWORK_VERSIONS: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Import from an imaginary package I wish existed... | |
from keyspace import KeySpace, Key, Prefix | |
class MyKeys(KeySpace): | |
prefix_users = Prefix('u') | |
user_set = Key('users') | |
KEYS = MyKeys(prefix='prod', delim=':') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func AccountConnectHandler(w http.ResponseWriter, r *http.Request) { | |
// TODO: Check state? r.FormValue("state") | |
transport := &oauth.Transport{ | |
Config: &config, | |
Transport: &urlfetch.Transport{ | |
Context: appengine.NewContext(r), | |
}, | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package foo | |
import ( | |
"appengine" | |
"appengine/urlfetch" | |
"code.google.com/p/goauth2/oauth" | |
"code.google.com/p/google-api-go-client/analytics/v3" | |
"code.google.com/p/google-api-go-client/oauth2/v2" | |
"github.com/gorilla/sessions" | |
"html/template" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"errors" | |
"fmt" | |
"reflect" | |
"runtime" | |
) | |
var ErrMissedCache = errors.New("Memoizer: Missed cache.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Without caching, or with a memoization wrapper: | |
func (c *Context) FooApi() (*Result, error) { | |
return c.apiClient.someGoogleApiQuery.Do() | |
} | |
func (c *Context) BarApi(someArg string) (*Result, error) { | |
return c.apiClient.someGoogleApiQuery.Filter(someArg).Do() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Based on code of dogpile.cache.util.function_key_generator(...) but adds support for kw. | |
Related dogpile.cache bug: https://bitbucket.org/zzzeek/dogpile.cache/issue/43/kw-support-in-function_key_generator | |
Usage: | |
from dogpile.cache import make_region | |
my_region = make_region( | |
function_key_generator=make_key_generator, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from dogpile.cache.api import CacheBackend, NO_VALUE | |
class DisabledBackend(CacheBackend): | |
def __init__(self, arguments): | |
pass | |
def get(self, key): | |
return NO_VALUE | |
def set(self, key, value): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
from unstdlib import html | |
_Default = object() | |
RE_HUMAN_URL = re.compile('^(\w*://)?(www\.)?(.+)/?$') | |
def human_url(s, max_length=None): |