This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 datetime import datetime | |
| from pymongo.connection import Connection | |
| import tornado.httpserver | |
| import tornado.ioloop | |
| import tornado.options | |
| import tornado.web | |
| from tornado.options import define, options |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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] |
This file contains hidden or 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
| Had trouble with mod_wsgi and virtual env. | |
| You need to build mod_wsgi yourself or ubuntu will use your default python. | |
| You also need to install the python dev tools (specify the python version). | |
| sudo apt-get install python2.6-dev | |
| source: http://helloit.es/2011/05/mod_wsgi-en-apache/ | |
OlderNewer