Skip to content

Instantly share code, notes, and snippets.

# 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
[watcher:myapp]
cmd = /home/kenny/env/bin/python
args = /home/kenny/myapp/manage.py run_gunicorn localhost:port
working_dir = /
send_hup = true
(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
SECTION .data
HelloWorld: db "Hello World of Assembly!",10
MsgLen: equ $-HelloWorld
SECTION .bss
SECTION .text
global _start
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
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
# Skip South for unittests
SOUTH_TESTS_MIGRATE = False
# 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])
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:
import time
from collections import deque
def normal_list(d):
start = time.time()
r = []
for i in d:
r.append(i)
end = time.time()
print "normal:"