Skip to content

Instantly share code, notes, and snippets.

@bootandy
bootandy / profile_jinja.py
Created November 6, 2014 00:09
How 2 line_profiler test a jinja2 template
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__))
@bootandy
bootandy / bash_aliases.sh
Created August 12, 2015 09:55
basic bash script to drop on a new box
# 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
@bootandy
bootandy / lambdas.py
Created November 4, 2011 11:16
Python - lambdas
#-------------- 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 --------------
@bootandy
bootandy / DataLoaderNextPrevious.py
Created November 15, 2011 11:48
GAE Python Data Loader that handles Next & Previous correctly
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()
@bootandy
bootandy / ShortestPath.py
Created January 20, 2012 15:13
Python Shortest Path & Tuples
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}
}
@bootandy
bootandy / dice.py
Created February 12, 2012 11:43
Python. Random dice rolling sim.
import random
def role():
return int(random.random() * 6) + 1
def main():
hits5plus = 0
hits6 = 0
roles = 10000
@bootandy
bootandy / looping.py
Created February 12, 2012 12:53
Python. Backwards Loops: reversed > xrange > range
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)
@bootandy
bootandy / basics.rb
Created February 28, 2012 14:13
Ruby Basics
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
@bootandy
bootandy / mongodb
Last active October 1, 2015 05:58
monogo notes
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:
@bootandy
bootandy / ruby_basics.rb
Created March 15, 2012 16:55
basics of ruby
#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]