Install the line_profiler
module:
[driti@ubuntu ]$ pip install line_profiler
Add the @profile
decorator and run:
[driti@ubuntu ]$ kernprof.py -l -v example.py
""" | |
Came up with this for satchmo's downloadable product migration, 0001_split. | |
""" | |
def db_table_exists(table, cursor=None): | |
try: | |
if not cursor: | |
from django.db import connection | |
cursor = connection.cursor() | |
if not cursor: | |
raise Exception |
# Public Domain, i.e. feel free to copy/paste | |
# Considered a hack in Python 2 | |
import inspect | |
def caller_name(skip=2): | |
"""Get a name of a caller in the format module.class.method | |
`skip` specifies how many levels of stack to skip while getting caller | |
name. skip=1 means "who calls me", skip=2 "who calls my caller" etc. |
from bitarray import bitarray | |
import mmh3 | |
class BloomFilter: | |
def __init__(self, size, hash_count): | |
self.size = size | |
self.hash_count = hash_count | |
self.bit_array = bitarray(size) | |
self.bit_array.setall(0) |
#!/bin/bash | |
FILES=`git ls-tree --name-only HEAD .` | |
MAXLEN=0 | |
IFS=$(echo -en "\n\b") | |
for f in $FILES; do | |
if [ ${#f} -gt $MAXLEN ]; then | |
MAXLEN=${#f} | |
fi | |
done |
Install the line_profiler
module:
[driti@ubuntu ]$ pip install line_profiler
Add the @profile
decorator and run:
[driti@ubuntu ]$ kernprof.py -l -v example.py
import time | |
from pycallgraph import PyCallGraph | |
from pycallgraph.output import GraphvizOutput | |
class CallgraphMiddleware(object): | |
def process_view(self, request, callback, callback_args, callback_kwargs): | |
if settings.DEBUG and 'graph' in request.GET: | |
pycallgraph = PyCallGraph(output=GraphvizOutput(output_file='callgraph-' + str(time.time()) + '.png')) |
def hexdump( src, length=16, sep='.' ): | |
''' | |
@brief Return {src} in hex dump. | |
@param[in] length {Int} Nb Bytes by row. | |
@param[in] sep {Char} For the text part, {sep} will be used for non ASCII char. | |
@return {Str} The hexdump | |
@note Full support for python2 and python3 ! | |
''' | |
result = []; |
var externalObj = {key: 'value'}; | |
var items = { | |
obj: { | |
'string prop': 'string val', | |
5: 10, | |
nested: [[3, [5, 2]]], | |
'function': function(){return true;}, | |
reference: externalObj | |
}, |
(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
""" | |
Physics simulation with PyODE followed by a (basic) rendering with Vapory | |
See the result here: http://i.imgur.com/TdhxwGz.gifv | |
Zulko 2014 | |
This script is placed in the Public Domain (Licence Creative Commons 0) | |
""" |