Skip to content

Instantly share code, notes, and snippets.

View cyberdelia's full-sized avatar

Timothée Peignier cyberdelia

View GitHub Profile
import os
import time
import readline
import ipy_defaults
import IPython.ipapi
import ipy_stock_completers
ip = IPython.ipapi.get()
o = ip.options
Run 1 :
Fill time for adding 1000 entry: 6.247 seconds
Usage per user : [{<<"martin">>,68200},
{<<"boulette">>,99700},
{<<"cstar">>,102100},
{<<"sacha">>,83400},
{<<"helene">>,101300}]
MapRed time=0.508 seconds
Usage : {<<"boulette">>,99700}
MapRed time=0.422 seconds
@agibralter
agibralter / jammit-mustache.js
Created April 19, 2010 22:22 — forked from documentcloud/jammit-mustache.js
Mustache.js templating function for Jammit.
// Add a Mustache.js templating function to your JavaScript:
Mustache.template = function(templateString) {
return function () {
if (arguments.length < 1) {
// With no arguments, return the raw template -- useful for rendering
// partials.
return templateString;
} else {
return Mustache.to_html(templateString, arguments[0], arguments[1]);
## Descriptors
## Anything with __get__ and optionally __set__:
class classinstancemethod(object):
def __init__(self, func):
self.func = func
def __get__(self, obj, type=None):
def repl(*args, **kw):
return self.func(obj, type, *args, **kw)
diff --git a/django_root/django/db/models/base.py b/django_root/django/db/models/base.py
index 37331b3..4da2802 100644
--- a/django_root/django/db/models/base.py
+++ b/django_root/django/db/models/base.py
@@ -5,6 +5,7 @@ from itertools import izip
import django.db.models.manager # Imported to register signal handler.
from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned, FieldError, ValidationError, NON_FIELD_ERRORS
from django.core import validators
+from django.db.models.expressions import ExpressionNode
from django.db.models.fields import AutoField, FieldDoesNotExist
@jacobian
jacobian / deleting_file_field.py
Created March 27, 2011 22:19
DeletingFileField
from django.db import models
from django.db.models import signals
class DeletingFileField(models.FileField):
"""
FileField subclass that deletes the refernced file when the model object
itself is deleted.
WARNING: Be careful using this class - it can cause data loss! This class
makes at attempt to see if the file's referenced elsewhere, but it can get
@jacobian
jacobian / models.py
Created November 3, 2011 20:18
Creating models on-the-fly
"""
NB: this is works-for-me quality code, completely not suitable for production.
Please use it as inspiration, but please test it better than I have before
you use it in your own projects!
"""
from django import db
from django.conf import settings
from django.db import models
"""Parse (absolute and relative) URLs.
urlparse module is based upon the following RFC specifications.
RFC 3986 (STD66): "Uniform Resource Identifiers" by T. Berners-Lee, R. Fielding
and L. Masinter, January 2005.
RFC 2732 : "Format for Literal IPv6 Addresses in URL's by R.Hinden, B.Carpenter
and L.Masinter, December 1999.
@asenchi
asenchi / README.md
Created March 17, 2012 03:01
Sequel::Factory

Sequel::Factory

Sequel::Factory implements a tiny DSL on Sequel::Model that allows you to create factories for objects of a model class. A factory is simply a Ruby block that gets evaluated each time a new object is generated. Inside the block you can call methods that correspond to the names of attributes of the object you're creating. If a value is given to the method, it will set the value for that attribute. Regardless, the method will always return the current value for that attribute.

Factories have names (the default name is :default) and you can include a factory in another. When you do this, the included factory will run first.

A simple factory for a User class might look like this:

User.factory do
@ericflo
ericflo / stripe.py
Created March 21, 2012 00:15
Replaced my use of Stripe's Python API with this
import httplib
import base64
import contextlib
import simplejson
import urllib
from django.conf import settings
def stripe_fetch(resource, method='GET', params=None, secret=settings.STRIPE_SECRET, prefix='/v1'):