Skip to content

Instantly share code, notes, and snippets.

#Newbie programmer
def factorial(x):
if x == 0:
return 1
else:
return x * factorial(x - 1)
print factorial(6)
#First year programmer, studied Pascal
'''
If you allways endup googleing how to code down relative paths inside django's
settings.py file using the os.path module, you should consider bookmarking this
code snippet
Usage inside settings.py:
SITE_ROOT = site_root_path(__file__)
.
.
.
import difflib
# initialize
matcher = difflib.SequenceMatcher()
ret = ['this', 'is', 'sparta']
rel = ['this', 'here', 'is','not','acutally', 'sparta']
# calculate matching blocks
matcher.set_seqs(ret, rel)
matches = matcher.get_matching_blocks()[:-1]
@tomazk
tomazk / preprocess.log
Created April 12, 2011 18:52
preprocessing log of google news dataset
root : WARNING no content attribute in meta http-equiv tag in 56062aa5-b833-4f50-a1f0-77e75ca29c2c.html: <meta http-equiv="Content-Type" conte="conte" />
root : WARNING no content attribute in meta http-equiv tag in e3a8cc42-09a1-470a-a705-d1d7dc5afd7a.html: <meta http-equiv="Content-Type" conte="conte" />
root : WARNING no content attribute in meta http-equiv tag in 91f7a641-0abf-4700-9392-56d1cdb9c1f5.html: <meta http-equiv="Content-Type" conte="conte" />
root : WARNING no content attribute in meta http-equiv tag in fc246c87-b4c6-4a7b-a77f-627c7fa18004.html: <meta http-equiv="Content-Type" conte="conte" />
root : WARNING no content attribute in meta http-equiv tag in 09988ff6-80a0-47c4-9b1d-d7861227461b.html: <meta http-equiv="Expires" conten="CONTEN" />
root : WARNING no content attribute in meta http-equiv tag in 3006baa7-a951-4b4f-a692-ce47f746f80e.html: <meta http-equiv="Content-Type" conte="conte" />
root : WARNING no content attribute in meta htt
@tomazk
tomazk / helper.sh.txt
Created May 24, 2011 14:28
Thrift compiler via Maven
# we use antrun:run goal and bind it to the generate-sources lifecycle
# to generate java source files via thrift compiler
$ mvn generate-sources
# or just use
$ mvn compile
@tomazk
tomazk / logging.py
Created January 1, 2012 12:56
Better logging levels
'''
Real life logging levels. Use this module instead of built-in logging throughout your project.
'''
from logging import *
fyi = debug
ewbte = info # everything went better than expected
lolwat = warn
omg = error
fml = critical