This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from jinja2 import Environment, FileSystemLoader | |
from line_profiler import LineProfiler | |
@profile | |
def render_template(template_filename, context): | |
return TEMPLATE_ENVIRONMENT.get_template(template_filename).render(context) | |
PATH = os.path.dirname(os.path.abspath(__file__)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# colors | |
export CLICOLOR=1 | |
export TERM=xterm-color | |
export LSCOLORS=gxgxcxdxbxegedabagacad # cyan directories | |
#Giant history | |
export HISTSIZE=99999 | |
# set - same as _ | |
set completion-map-case on |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#-------------- Concept: Lambdas & string splits: -------------- | |
TurnSpacesIntoColonsFunction = lambda x: '::'.join(x.split(" ")) | |
NumberOfWordsFunction = lambda x: len(x.split(" ")) | |
#-------------- Concept: lambdas inside a regex -------------- | |
re.sub('[aeiou]', lambda match: match.group().upper()*3, 'abcdefghijklmnopqrstuvwxyz') | |
#-------------- Concept: crazy function stacking with lambdas -------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LoadHelper: | |
PAGE_SIZE = 10 | |
""" load objects, ordered by a parameter | |
supports next & previous""" | |
def loadByString(self, request, order, filter): | |
next = request.get('next') | |
prev = request.get('prev') | |
query = MyObject.all() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
neighbours = { | |
"A":{"B":3,"C":4}, | |
"B":{"D":2}, | |
"C":{"D":1,"E":1,"F":6}, | |
"D":{"H":1}, | |
"E":{"H":7}, | |
"F":{"G":1}, | |
"G":{}, | |
"H":{"G":3} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
def role(): | |
return int(random.random() * 6) + 1 | |
def main(): | |
hits5plus = 0 | |
hits6 = 0 | |
roles = 10000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from random import random | |
import time | |
def main(): | |
list = [] #[5,6,3,6,8,3,10,0,4] | |
for i in range(0, 1000000): | |
list.append(int( random() * 1000000000 ) ) | |
with_reversed(list) | |
backwards_xrange(list) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
How 2 ruby debug: | |
type debugger in file | |
on cmd line: | |
l - print where i am | |
c - continue | |
n - step over | |
e @var - dump @var as tostring() | |
disp - dump current vars | |
irb - Interactive Ruby Shell |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cheat sheet: | |
http://cheat.errtheblog.com/s/mongo | |
for more on update see: | |
http://www.mongodb.org/display/DOCS/Updating#Updating-update%28%29 | |
======================== DEV ============================== | |
---search by date: | |
db.houses.find({"dateadded": { "$gt" : ISODate("2013-01-01")} } ) | |
-- Get by subdocument key field: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Hashes: | |
def test_combining_hashes | |
hash = { "jim" => 53, "amy" => 20, "dan" => 23 } | |
new_hash = hash.merge({ "jim" => 54, "jenny" => 26 }) | |
def default_value_hash | |
hash2 = Hash.new("default") | |
hash2[:one] = 1 | |
assert_equal 1, hash2[:one] |
OlderNewer