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
>>> f1 = lambda i: '%s' % i | |
>>> f2 = lambda i: '%s'.format(i) | |
>>> import dis | |
>>> dis.dis(f1) | |
1 0 LOAD_CONST 1 ('%s') | |
3 LOAD_FAST 0 (i) | |
6 BINARY_MODULO | |
7 RETURN_VALUE | |
>>> dis.dis(f2) | |
1 0 LOAD_CONST 1 ('%s') |
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
# Python 2.7.3 | |
$ python -m timeit -s 'a=5' 'str(a)' | |
10000000 loops, best of 3: 0.177 usec per loop | |
$ python -m timeit -s 'a=5' '`a`' | |
10000000 loops, best of 3: 0.0571 usec per loop # Fastest, but seems like it's not good practice | |
$ python -m timeit -s 'a=5' '"%s".format(a)' | |
1000000 loops, best of 3: 0.236 usec per loop # Slowest | |
$ python -m timeit -s 'a=5' '"%s" % a' | |
10000000 loops, best of 3: 0.159 usec per loop | |
$ python -m timeit -s 'a=5' 'repr(a)' |
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
Index: src/array.js | |
=================================================================== | |
--- src/array.js (revision 12923) | |
+++ src/array.js (working copy) | |
@@ -1239,8 +1239,8 @@ | |
var accumulator = new InternalArray(length); | |
if (%DebugCallbackSupportsStepping(f)) { | |
for (var i = 0; i < length; i++) { | |
- if (i in array) { | |
- var element = array[i]; |
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
json = raw_response.json | |
type_ = json['type'] | |
cls = type(str(type_), (Response,), {}) | |
response = cls() | |
func = functools.partial(setattr, response) | |
map(lambda t: func(*t), json.iteritems()) |
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
diff --git a/django/db/models/query.py b/django/db/models/query.py | |
index da4c69f..591ccfa 100644 | |
--- a/django/db/models/query.py | |
+++ b/django/db/models/query.py | |
@@ -139,33 +139,22 @@ class QuerySet(object): | |
def __contains__(self, val): | |
# The 'in' operator works without this method, due to __iter__. This | |
- # implementation exists only to shortcut the creation of Model | |
- # instances, by bailing out early if we find a matching element. |
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 a(): | |
print("a") | |
return True | |
def b(): | |
print("b") | |
return True | |
print(any((a(), b()))) # :( | |
print("") |
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
try: | |
# Hang until we exit the script | |
while 1: | |
time.sleep(5) | |
except KeyboardInterrupt: | |
pass |
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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import sys | |
import time | |
import urllib2 | |
import boto | |
try: | |
import simplejson as json | |
except ImportError: |
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
#!/usr/bin/env sh | |
INSTALL_DIR=`pwd`/maxmind | |
log() { | |
printf "\033[90m...\033[0m $@\n" | |
} | |
abort() { | |
printf "\033[31mError: $@\033[0m\n" && exit 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
publish: | |
python setup.py sdist upload | |
clean: | |
rm -rf *.egg-info | |
rm -rf dist | |
rm -rf build | |
.PHONY: publish clean |