Skip to content

Instantly share code, notes, and snippets.

@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 / model.py
Created September 7, 2011 12:58
Google App engine Datastore plus pre/post hooks, unique constraints
import hashlib
import logging
from werkzeug import cached_property
from flask.signals import Namespace
from ndb import model, tasklets, query, key
from ndb.key import Key as BaseKey
class Error(Exception):
@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.
@vmihailenco
vmihailenco / proxy.go
Created November 20, 2011 15:22
Simple TCP proxy in Golang
package main
import (
"bytes"
"encoding/hex"
"flag"
"fmt"
"io"
"log"
"net"
@vmihailenco
vmihailenco / websocket.go
Created November 22, 2011 10:44
WebSocket server
package main
import (
"fmt"
"os"
"http"
"websocket"
)
type subscription struct {