System hooks to insert raw sql.
References on django-developers google group:
* https://groups.google.com/forum/?fromgroups#!topic/django-developers/xN0aMzrmA1Y * https://groups.google.com/forum/?fromgroups#!topic/django-developers/KhsGj1b6rnU
#!/usr/bin/env python | |
__author__ = 'Frank Smit <[email protected]>' | |
__version__ = '0.1.0' | |
import functools | |
import psycopg2 | |
from tornado.ioloop import IOLoop, PeriodicCallback |
[[email protected]][~]% python3 subprocess_ssh.py | |
(0, b'Linux vaio.niwi.be 3.3.2-1-ARCH #1 SMP PREEMPT Sat Apr 14 09:48:37 CEST 2012 x86_64 Intel(R) Core(TM)2 Duo CPU T6600 @ 2.20GHz GenuineIntel GNU/Linux') | |
(0, b'processor\t: 0\nvendor_id\t: GenuineIntel\ncpu family\t: 6\nmodel\t\t: 23\nmodel name\t: Intel(R) Core(TM)2 Duo CPU T6600 @ 2.20GHz\nstepping\t: 10\nmicrocode\t: 0xa07\ncpu MHz\t\t: 2193.716\ncache size\t: 2048 KB\nphysical id\t: 0\nsiblings\t: 2\ncore id\t\t: 0\ncpu cores\t: 2\napicid\t\t: 0\ninitial apicid\t: 0\nfpu\t\t: yes\nfpu_exception\t: yes\ncpuid level\t: 13\nwp\t\t: yes\nflags\t\t: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx lm constant_tsc arch_perfmon pebs bts rep_good nopl aperfmperf pni dtes64 monitor ds_cpl est tm2 ssse3 cx16 xtpr pdcm sse4_1 xsave lahf_lm dts\nbogomips\t: 4389.24\nclflush size\t: 64\ncache_alignment\t: 64\naddress sizes\t: 36 bits physical, 48 bits virtual\npower management:\n |
# -*- coding: utf-8 -*- | |
from gevent import monkey; monkey.patch_all() | |
import gevent | |
from gevent_zeromq import zmq | |
class WebSocketHandler(object): | |
def __init__(self, _id, in_queue, socket): |
import os | |
import fcntl | |
from gevent.core import wait_read, wait_write | |
class GeventFD(object): | |
""" Wrap a file descriptor so it can be used for non-blocking reads and writes with gevent. | |
>>> stdin = GeventFD(sys.stdin.fileno()) | |
>>> stdin.read(5) | |
'hello' |
# -*- coding: utf-8 -*- | |
from django.db.models import signals | |
def model_class_prepared(sender, **kwargs): | |
if sender._meta.app_label == 'auth' and sender._meta.module_name == 'user': | |
print "Monky patching user..." | |
email_field = sender._meta.get_field("email") | |
email_field.max_length = 200 | |
email_field._unique = True |
function Irc(host, port, nick){ | |
this._host = host; | |
this._port = port; | |
this._nick = nick; | |
} | |
Irc.prototype.setChannels = function(channels) { | |
this._chans = channels; | |
} |
from django.core.cache import cache | |
def cacheable(cache_key, timeout=3600): | |
def paramed_decorator(func): | |
def decorated(self): | |
key = cache_key % self.__dict__ | |
res = cache.get(key) | |
if res == None: | |
res = func(self) | |
cache.set(key, res, timeout) |
#from functools import reduce # uncomment if python3+ is used | |
lmb = lambda x, y: x+reduce(lmb, y, []) if isinstance(y, list) else x + [y] | |
reduce(lmb,[1,['a','b'],2,[[1,2, [3]]],'c'], []) |
[3/4.3.17]niwi@vaio:~> python2 savepoint_sqlite3_test.py | |
python version: 2.7.3 (default, Apr 24 2012, 00:00:54) | |
[GCC 4.7.0 20120414 (prerelease)] | |
PySQLite version: 2.6.0 | |
sqlite3 version: 3.7.13 | |
Test with isolation_level = None (autocommit mode) | |
********************************************************************** | |
ROW: (0, 200) |