Skip to content

Instantly share code, notes, and snippets.

func copyHeader(dst, src http.Header) {
for k, vv := range src {
for _, v := range vv {
dst.Add(k, v)
}
}
}
func cloneReq(req *http.Request) *http.Request {
outreq := new(http.Request)
package sharding
import (
"sync"
"github.com/golang/groupcache/consistenthash"
"gopkg.in/redis.v1"
)
const replicas = 100
package main
import (
"fmt"
"net/http"
"reflect"
"runtime"
"github.com/codegangsta/negroni"
"gopkg.in/airbrake/gobrake.v2"
@vmihailenco
vmihailenco / authentication.py
Created June 15, 2011 17:49 — forked from zyegfryed/gist:814432
Tastypie OAuth
import logging
from tastypie.authentication import Authentication
import oauth2
from oauth_provider.consts import OAUTH_PARAMETERS_NAMES
from oauth_provider.store import store
from oauth_provider.store import Error as OAuthError
from oauth_provider.utils import get_oauth_request
from oauth_provider.utils import get_oauth_server
@vmihailenco
vmihailenco / cached_property.py
Created July 2, 2011 08:29
cached_property.py
class cached_property(object):
def __init__(self, func):
self.func = func
def __get__(self, obj, type=None):
if obj is None:
return self
obj.__dict__[self.func.__name__] = value = self.func(obj)
return value
@vmihailenco
vmihailenco / set_tags.py
Created July 3, 2011 13:30
Django set template tag
from django import template
register = template.Library()
class SetNode(template.Node):
def __init__(self, key, nodelist, return_result=False):
self.key = key
self.nodelist = nodelist
@vmihailenco
vmihailenco / aform.coffee
Created July 11, 2011 09:15
aform.coffee
exports = exports ? @
aform = {}
exports.aform = aform
aform.render_form_errors = ($form, fieldErrors, prefix='') ->
if prefix?
prefix = prefix += '-'
for name, errors of fieldErrors
$field = $ "#id_#{prefix}#{name}"
$(document).ajaxSend (event, xhr, settings) ->
getCookie = (name) ->
name += '='
if document.cookie and document.cookie != ''
cookies = document.cookie.split ';'
for cookie in cookies
cookie = jQuery.trim cookie
# Does this cookie string begin with the name we want?
if cookie.substring(0, name.length) == name
return decodeURIComponent cookie.substring(name.length)
@vmihailenco
vmihailenco / pagination.py
Created August 18, 2011 19:01
Google App Egnine Datastore plus pagination
import hashlib
from google.appengine.api import memcache, datastore_errors
from google.appengine.datastore.datastore_query import Cursor
from flask import request
from ndb import tasklets
class BasePager(object):
def __init__(self, **kwargs):
@vmihailenco
vmihailenco / assets.py
Created October 23, 2011 16:00
AppEngineBundle for WebAssets
"""
This gist adds url expiration functionality to flask-webassets on App Engine.
Few hints how to use it:
- Disable updater: ASSETS_UPDATER = False.
- Use AppEngineBundle instead of standard webassets Bundle.
- Rebuild assets manually:
* manage.py assets watch for development.
* manage.py assets rebuild for deployment.