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 Foo(object): | |
... x = 5 | |
... y = Foo() | |
... | |
Traceback (most recent call last): | |
File "<stdin>", line 1, in <module> | |
File "<stdin>", line 3, in Foo | |
NameError: name 'Foo' is not defined | |
>>> |
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 ujson as json | |
>>> jd = json.dumps | |
>>> json_is_ujson = True | |
>>> | |
>>> | |
>>> def dumps(data, sort_keys=False): | |
... if json_is_ujson: | |
... if sort_keys: | |
... raise Exception('ujson does not support sort_keys flag') | |
... return jd(data) |
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
function flash(id) { | |
// Fades the colored panel into 70% opacity on top of an image stored in | |
// the value stored in ".img-holder img". This has the effect of a square | |
// fading into a tinted photograph. | |
... | |
} |
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
Flexibility and productivity are still motivators, but they are not the | |
primary motivators. Safety always trumps other considerations, and | |
performance also tends to rank very highly in the software-conservative's | |
value system. |
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
type comparison = Less | Equal | Greater;; | |
module type ORDERED_TYPE = | |
sig | |
type t | |
val compare: t -> t -> comparison | |
end;; | |
module Set = | |
functor (Elt: ORDERED_TYPE) -> |
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
val service = { | |
path("orders") { | |
authenticate(httpBasic(realm = "admin area")) { user => | |
get { | |
cacheResults(LruCache(maxCapacity = 1000, timeToIdle = Some(30.minutes))) { | |
encodeResponse(Deflate) { | |
completeWith { | |
// marshal custom object with in-scope marshaller | |
getOrdersFromDB}}}} ~ |
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 deco(method): | |
... def wrapped(*a, **kw): | |
... retval = method(*a, **kw) | |
... return retval | |
... return wrapped | |
... | |
>>> | |
>>> def foo(): | |
... return 4 | |
... |
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
>>> m.to_json(encode=False) | |
{'owner': '557554ab-757f-421a-9838-8783d8555df3', '_types': ['Media'], '_cls': 'Media', 'title': u'Misc Media'} | |
>>> p = msgpack.packb(m.to_json(encode=False)) | |
>>> p | |
'\x84\xa5owner\xda\x00$557554ab-757f-421a-9838-8783d8555df3\xa6_types\x91\xa5Media\xa4_cls\xa5Media\xa5title\xaaMisc Media' | |
>>> d = msgpack.unpackb(p) | |
{'owner': '557554ab-757f-421a-9838-8783d8555df3', '_types': ('Media',), '_cls': 'Media', 'title': 'Misc Media'} | |
>>> Movie(**d) |
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 functools | |
>>> def foo(a,b,c): | |
... return a*b*c | |
... | |
>>> times_two = functools.partial(foo, 2) | |
>>> times_two(3,4) | |
24 |
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 requests | |
import gzip | |
class GzipWrap(object): | |
"""The normal gzip interface requires writing / reading from gzipped files | |
on the file system. I think that will cause significant slow-down in | |
performance so this is a wrapper that implements a file-like interface, but | |
works entirely from memory instead. |