Skip to content

Instantly share code, notes, and snippets.

Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/home/lion/.virtualenvs/test/lib/python2.6/site-packages/django/db/models/query.py", line 69, in __repr__
data = list(self[:REPR_OUTPUT_SIZE + 1])
File "/home/lion/.virtualenvs/test/lib/python2.6/site-packages/django/db/models/query.py", line 84, in __len__
self._result_cache.extend(self._iter)
File "/home/lion/.virtualenvs/test/lib/python2.6/site-packages/django/db/models/query.py", line 273, in iterator
for row in compiler.results_iter():
File "/home/lion/.virtualenvs/test/lib/python2.6/site-packages/django/db/models/sql/compiler.py", line 680, in results_iter
for rows in self.execute_sql(MULTI):
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <ctime>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
class MetaA(type):
def __call__(cls, *args, **kwargs):
for name, class in cls.__dict__.iteritems():
if issubclass(class.__class__, B):
# Do something
return # class A with modified fields
class B(object):
....
wlp2s0 IEEE 802.11bgn ESSID:"ASDF"
Mode:Managed Frequency:2.437 GHz Access Point: 123
Bit Rate=54 Mb/s Tx-Power=16 dBm
Retry long limit:7 RTS thr:off Fragment thr:off
Encryption key:off
Power Management:off
Link Quality=57/70 Signal level=-53 dBm
Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0
Tx excessive retries:0 Invalid misc:28 Missed beacon:0
Description='A wpa_supplicant configuration file based wireless connection'
Interface=wlp2s0
Connection=wireless
Security=wpa-config
WPAConfigFile='/etc/wpa_supplicant/wpa_supplicant.conf'
IP=dhcp
@jakab922
jakab922 / gist:5904427
Created July 1, 2013 20:41
preserve order unique
your_list
unique_d = {}
for i, el in enumerate(your_list):
unique_d.setdefault(el, i)
preserved_order_unique = map(lambda x: x[0], sorted([(key, val) for key, val in unique_d.iteritems()], lambda y: y[1]))
@jakab922
jakab922 / metaclass_reminder.py
Last active May 5, 2018 19:27
Python metaclass reminder
class MetaClass(type):
counter = 1
def __new__(meta, name, bases, dct):
""" Gets called when we read in the class definition for which this is the metaclass of"""
print "MetaClass.__new__(%s, %s, %s, %s)" % (meta, name, bases, dct)
dct['class_num'] = meta.counter
meta.counter += 1
return super(MetaClass, meta).__new__(meta, name, bases, dct)
@jakab922
jakab922 / cache_decorator.py
Last active July 5, 2018 11:51
Caching decorator with timeout. Might not be good for class instance/class methods.
from functools import wraps
from json import dumps
from datetime import datetime
def timeout_cache(max_timeout):
def timeout_cache_inner(fn):
fn._cache = {}
fn._timeout = max_timeout
@wraps(fn)
@jakab922
jakab922 / measure_decorator.py
Created September 18, 2013 15:19
Measure decorator and context manager, for measuring execution time. For multiple processes, multiple instances are needed.
class Measure(object):
def __init__(self):
self.__elapsed = None
def __enter__(self):
self.__start = time()
def __exit__(self, *args):
self.__elapsed = time() - self.__start
@jakab922
jakab922 / decla_mock.py
Last active December 23, 2015 17:39
Declarative mock definitions for tests on a Test class.
from unittest import TestCase
from mock import patch
class IDontNeedTheRest(Exception):
pass
DEBUG = False