Skip to content

Instantly share code, notes, and snippets.

View ojii's full-sized avatar

Jonas Obrist ojii

View GitHub Profile
@ojii
ojii / bundle.py
Created October 18, 2011 15:20
Bundle an iterable into a list of tuples
"""
Bundles the iterable `l` into an iterable of tuples of length `x`, filling the last one with `f` if necessary.
Examples:
In [13]: list(bundle([1,2,3,4,5,6], 3, None))
Out[13]: [(1, 2, 3), (4, 5, 6)]
In [14]: list(bundle([1,2,3,4,5,6], 2, None))
Out[14]: [(1, 2), (3, 4), (5, 6)]
@ojii
ojii / countries.py
Created October 20, 2011 12:27
Countries list for Django models
# -*- coding: utf-8 -*-
# SOURCE: http://www.iso.org/iso/country_codes/iso_3166_code_lists.htm
from django.utils.translation import ugettext_lazy as _
COUNTRIES = [
(_(u"Afghanistan"), u"AF"),
(_(u"Åland Islands"), u"AX"),
(_(u"Albania"), u"AL"),
(_(u"Algeria"), u"DZ"),
(_(u"American Samoa"), u"AS"),
@ojii
ojii / pypy
Created October 25, 2011 17:00
Python2.7 vs Pypy Nightly dulwich
(pypyenv)jonas@jonas-Serval-Professional:~/workspace/gitstats.ep.io$ time pypy run.py /home/jonas/workspace/django-cms
real 0m2.493s
user 0m2.376s
sys 0m0.100s
@ojii
ojii / common.py
Created October 26, 2011 14:18
requests vs sockets
URL = 'http://httpbin.org/status/200'
def check(status_code, headers, content):
assert status_code == 200
assert headers['Content-Length'] == '0'
assert headers['Content-Type'] == 'text/html; charset=utf-8'
assert headers['Connection'] == 'close'
print 'OK'
"""
Dummy code for my thoughts described in https://groups.google.com/forum/#!topic/django-cms-developers/bFbhE1a-rTs
Note that this pseudo-implementation has problems where between `cache.get(...)`
in `get_cached` and `cache.set(...)` the value *could* have changed in the cache,
so some kind of better way to prevent overwriting changes done by others should
be implemented.
"""
# the local python in-memory cache
LOCAL_CACHE = {}
@ojii
ojii / gist:1328081
Created October 31, 2011 17:29 — forked from evildmp/gist:1328038
Attempt to understand the menu system
=========================
How the menu system works
=========================
Basic concepts
==============
Registration
------------
@ojii
ojii / base.py
Created November 1, 2011 10:36
My scripts
# -*- coding: utf-8 -*-
# IS IN FOLDER ./src/ (github doesn't allow slashes in filenames on gists)
import os
import re
DEBUG = False
TEMPLATE_DEBUG = DEBUG
DEBUG_PROPAGATE_EXCEPTIONS = False
IS_DEV_SERVER = False
PREPEND_WWW = False
@ojii
ojii / managers.py
Created November 3, 2011 10:59
Django Model Managers
# -*- coding: utf-8 -*-
from django.db import models
from django.db.models.query import QuerySet
class ChainableManager(models.Manager):
"""
A manager that allows chaining of all methods defined on it.
Example:
@ojii
ojii / jquery.doubleoptin.js
Created November 8, 2011 15:54
double-opt-in buttons
$.fn.doubleOptIn = function(){
return this.each(function(){
var ele = $(this);
ele.bind('click', function(event){
event.preventDefault();
if (ele.attr('type') == 'submit'){
ele.val(ele.attr('x-opt-in-text'));
} else {
ele.text(ele.attr('x-opt-in-text'));
}
@ojii
ojii / gist:1447997
Created December 8, 2011 18:45
my stylebot style for facebook
#blueBarHolder {
position: fixed;
top: 0;
}
#globalContainer {
padding-top: 38px;
}
#leftCol {