Python notes

Python3 on centos (using scl):

scl enable python33 bash

Design patterns




Unicode, and Encode vs Decode

Coverage usage

Run this:

coverage run scriptname args

Results are stored in .coverage. If the script has different args, backup .coverage, run again and then combine them:

coverage combine .coverage.old .coverage

For a quick summary (-m specifies the missing lines):

coverage report -m

For a report (-d specifies the dest folder):

coverage html -d coverage_html

Decorator example

def my_decorator(func):
    def wrapper(*args, **kwargs):
        # do pre-processing
        ret = func(*args, **kwargs)
        # do post-processing
        return ret
    return wrapper

i.e., return a function (wrapper) that calls func with its args, but do your pre/post stuff within wrapper.

Django notes

Magic number

The python interpreter's magic number is found in:


.pyc file format:

magic number | mtime | size | marshaled code object

Dunder methods

__repr__, __str__, __format__, __bytes__

__abs__, __bool__, __complex__, __int__, __float__, __hash__, __index__

__len__, __getitem__, __setitem__, __delitem__, __contains__

__iter__, __reversed__, __next__


__enter__, __exit__

__new__, __init__, __del__

__getattr__, __getattribute__, __setattr__, __delattr__, __dir__

__get__, __set__, __delete__

__prepare__, __instancecheck__, __subclasscheck__


Staticmethod vs Classmethod

Import files with hyphens

test_cmd = importlib.import_module('test-cmd', None)

Other languages


HTML header

<html lang="en">


.site-nav-header { width: 300 px }
##main-title { color: green }


<label for="nickname">Please enter your nickname</label>
<input type="text" id="nickname" name="nickname">

There are 3 groups of elements in the way the browser stacks them:

tcl: xml parsing example

package require tdom
set dom [dom parse $XML]     
set recording [$dom documentElement]
set datamode [$recording firstChild]
set session [$datamode nextSibling]
$session attributes *
$session getAttribute session_id
set participant [$session nextSibling]
set dom [dom parse $XML]     
set recording [$dom documentElement]

Other study notes


Unicode in DNS:


example of unicode encoding:

example 2:

Levenshtein Distance

Algorithmic Complexity

Notation Type Example
O(1) Constant Time Dict Lookup
O(lg n) Logarithmic Binary Search
O(n) Linear Iterating over a list
O(n log n) Log Linear Optimal sorting of arbitrary values
O(n2) Quadratic Comparing *n* objects to each other
O(n3) Cubic Floyd and Washall's algorithms
O(nk) Polynomial *k* nested loops over *n*
O(n!) Factorial Producing every ordering of *n* values