Skip to content

Instantly share code, notes, and snippets.

import time
from collections import deque
def normal_list(d):
#start = time.time()
r = []
for i in d:
r.append(i)
start = time.time()
while len(r) > 0:
# other imports
import difflib
# So I have a model where I want to search by a text field
results = MyModel.objects.filter(some_field__icontains=query)
# We may get usually a couple of results at least, but the deal is for a case I'm working on, I only want 1 object
# difflib.get_close_matches will text a first arg, then a collection, and n=? for max number of results)
result = results.filter(some_field=difflib.get_close_matches(query, [r.some_field for r in results], 1)[0])
# Skip South for unittests
SOUTH_TESTS_MIGRATE = False
class TransactionManager(models.Manager):
# ...
def some_manager_method(self, transaction_id):
try:
tran = super(TransactionManager, self).get_query_set().get(id=transaction_id)
except self.model.DoesNotExist:
tran = None
return tran
var nWheel=1
// was 0
var modeval=1
//modeval is 1 for gear inches, 12.532 for meters, crank _diam._ for gain ratio
//this currently is not working
SECTION .data
HelloWorld: db "Hello World of Assembly!",10
MsgLen: equ $-HelloWorld
SECTION .bss
SECTION .text
global _start
(gdb) break 11
(gdb) # some output from gdb confirming we laid a breakpoint
(gdb) run
(gdb) # gdb output, runs program till line 11
(gdb) # let's check register EAX
(gdb) p/x $eax
$1 = 0x0
(gdb) # let's run a few "stepi" till that line "mov eax,4" is executed
(gdb) stepi
(gdb) stepi
[watcher:myapp]
cmd = /home/kenny/env/bin/python
args = /home/kenny/myapp/manage.py run_gunicorn localhost:port
working_dir = /
send_hup = true
# Getting a GET value
pageNumber = int(request.GET.get('page', 1))
# But some doofus goes and change /?page=n, n to some weird char and ValueError
# Fixed
try:
pageNumber = int(request.GET.get('page', 1))
except ValueError:
pageNumber = 1
[Thu Jun 14 16:57:24 2012] [error] [client 127.0.0.1] mod_wsgi (pid=10827): Exception occurred processing WSGI script '/home/kenny/someapp/wsgi.py'.
[Thu Jun 14 16:57:24 2012] [error] [client 127.0.0.1] Traceback (most recent call last):
[Thu Jun 14 16:57:24 2012] [error] [client 127.0.0.1] File "/usr/lib/pymodules/python2.6/django/core/handlers/wsgi.py", line 230, in __call__
[Thu Jun 14 16:57:24 2012] [error] [client 127.0.0.1] self.load_middleware()
[Thu Jun 14 16:57:24 2012] [error] [client 127.0.0.1] File "/usr/lib/pymodules/python2.6/django/core/handlers/base.py", line 42, in load_middleware
[Thu Jun 14 16:57:24