Skip to content

Instantly share code, notes, and snippets.

View ojii's full-sized avatar

Jonas Obrist ojii

View GitHub Profile
@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'
@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 / 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 / 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 / multi_hex_color_code_re.py
Created October 18, 2011 13:06
multi_hex_color_code_re.py
import re
GOOD = {
"#abc": ['abc'],
"#abc,#123": ['abc', '123'],
"567": ['567'],
"abc,123": ['abc', '123'],
"abc,#611": ['abc', '611'],
"#aaff33": ['aaff33'],
"9923cc": ['9923cc'],
@ojii
ojii / cbv_decorator.py
Created October 7, 2011 10:09
Django view decorator to CBV decorator
from django.utils.decorators import method_decorator
def cbv_decorator(decorator):
"""
Turns a normal view decorator into a class-based-view decorator.
Usage:
@cbv_decorator(login_required)
class MyClassBasedView(View):
@ojii
ojii / messages_test_mixin.py
Created October 7, 2011 10:01
django messages framework testing utilities
from contextlib import contextmanager
from django.contrib.messages.storage.base import BaseStorage, Message
from django.test.client import RequestFactory
from django.utils.decorators import method_decorator
class TestMessagesBackend(BaseStorage):
def __init__(self, request, *args, **kwargs):
self._loaded_data = []
super(TestMessagesBackend, self).__init__(request, *args, **kwargs)
@ojii
ojii / autoruntests.sh
Created October 6, 2011 17:34
local mini ci
#!/bin/sh
run_tests()
{
COMMAND TO RUN YOUR TESTS
if [ "$?" != "0" ]
then
notify-send "BUILD FAILED" -i "error"
else
notify-send "Build Successful"
fi
from multiprocessing import Process
from django.core import serializers
from django.core.management import call_command
from StringIO import StringIO
def dump_database():
sio = StringIO()
call_command('dumpdata', stdout=sio, natural=True)
return sio.getvalue()
xrandr: Failed to get size of gamma for output default
Screen 0: minimum 320 x 175, current 1920 x 1080, maximum 1920 x 1080
default connected 1920x1080+0+0 0mm x 0mm
1920x1080 50.0* 51.0
1680x1050 52.0
1600x1024 53.0
1440x900 54.0
1400x1050 55.0
1360x768 56.0 57.0
1280x1024 58.0 59.0