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
| In [10]: SomeModel.objects.create(name='foo') | |
| Out[10]: <SomeModel: SomeModel object> | |
| In [11]: SomeModel.objects.create(name='bar') | |
| Out[11]: <SomeModel: SomeModel object> | |
| In [12]: SomeModel.objects.create(name='foo') | |
| Out[12]: <SomeModel: SomeModel object> | |
| In [13]: SomeModel.objects.distinct() |
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 binascii | |
| import json | |
| def to_int(data): | |
| return int(binascii.hexlify(json.dumps(data)), 16) | |
| def from_int(i): | |
| return json.loads(binascii.unhexlify('%x' % i)) | |
| print to_int({1: 2, 'hello': 'world'}) |
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
| # Old implementation. Can you spot the optimization? | |
| predicates = [lambda x: x.is_rad(), lambda x: x.is_cool(), lambda x: x.is_baller()] | |
| all_products = Product.objects.all() | |
| products = reduce( | |
| lambda filtered_so_far, predicate: filter(predicate, filtered_so_far), | |
| predicates, | |
| all_products | |
| ) | |
| # New implementation |
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
| example_transformations = [ | |
| ["colin, why dont you get it", "mark, why dont you get it"], | |
| ["I eat lots of bananas", "I eat lots of apples"], | |
| ["colin eats lots of bananas", "mark eats lots of apples"], | |
| ["milk tea is the best", "coffee is the best"], | |
| ["milk and tea are both great", "milk and tea are both great"] | |
| ["foo(1, 2)", "foo(1, 2, user=colin)"], | |
| ["foo(9)", "foo(9)"], | |
| ] | |
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
| >>> z=01 | |
| >>> z=02 | |
| >>> z=03 | |
| >>> z=1 | |
| >>> z=0000000000001 | |
| >>> z=0000000000002 | |
| >>> z=0000000000006 | |
| >>> z=8 | |
| >>> z=08 | |
| File "<stdin>", line 1 |
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
| def thing(n): | |
| if n < 10: | |
| thing(n+1) | |
| yield(n) | |
| for x in thing(0): | |
| print x |
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 pyparsing | |
| class Word(object): | |
| def __init__(self, body): | |
| self.body = body | |
| def __repr__(self): | |
| return self.body[0] | |
| class Tag(object): |
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
| module Main where | |
| import UI.NCurses | |
| import Data.Maybe | |
| import Control.Monad | |
| import Control.Monad.State | |
| main :: IO () | |
| main = runCurses $ void (runStateT top []) |
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
| module Main where | |
| import UI.NCurses | |
| import Control.Monad.State | |
| main :: IO () | |
| main = runCurses $ void (runStateT top []) | |
| top = do | |
| lift $ setEcho False |
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
| -- inspired by | |
| -- http://stackoverflow.com/a/23660388/1096146 | |
| --nestedMap f elements = map (\inner -> map f inner) elements | |
| --nestedMap f elements = map (map f) elements | |
| --nestedMap f = map (map f) | |
| --nestedMap f = (map . map) f | |
| --nestedMap = (map . map) | |
| nestedMap = map . map |