Skip to content

Instantly share code, notes, and snippets.

View davidwtbuxton's full-sized avatar

David Buxton davidwtbuxton

View GitHub Profile
@davidwtbuxton
davidwtbuxton / sdk-1969-1970.diff
Created May 29, 2018 18:56
Latest changes from Google App Engine SDK 1.9.70
diff -u -r 1.9.69/google_appengine/VERSION 1.9.70/google_appengine/VERSION
--- 1.9.69/google_appengine/VERSION 2018-05-29 11:48:16.000000000 -0700
+++ 1.9.70/google_appengine/VERSION 2018-05-29 11:47:31.000000000 -0700
@@ -1,5 +1,5 @@
-release: "1.9.69"
-timestamp: 1523300407
+release: "1.9.70"
+timestamp: 1526501368
api_versions: ['1']
supported_api_versions:
@davidwtbuxton
davidwtbuxton / traceback.sh
Created April 18, 2018 22:26
Error when trying to use the remote sandbox with Djangae and SDK 1.9.57
(venv) foo-proj david$ ./manage.py --sandbox=remote --app_id=foo-proj loadconfig
ERROR 2018-04-18 14:52:43,440 sandbox.py:321] Unable to use oauth2 falling back to username/password
Traceback (most recent call last):
File "/Users/david/foo-proj/sitepackages/prod/djangae/sandbox.py", line 294, in _remote
from google.appengine.tools.appcfg import APPCFG_CLIENT_ID, APPCFG_CLIENT_NOTSOSECRET
File "/Users/david/foo-proj/sitepackages/dev/google_appengine/google/appengine/tools/appcfg.py", line 58, in <module>
from oauth2client import devshell
ImportError: cannot import name devshell
Google Account Login: david@example.com
Password:
@davidwtbuxton
davidwtbuxton / sdk-1967-1968.diff
Created April 4, 2018 04:44
Changes between Google App Engine SDK version 1.9.67 and 1.9.68
diff -u -r 1.9.67/google_appengine/VERSION 1.9.68/google_appengine/VERSION
--- 1.9.67/google_appengine/VERSION 2018-03-09 20:05:16.000000000 -0800
+++ 1.9.68/google_appengine/VERSION 2018-04-03 21:35:02.000000000 -0700
@@ -1,5 +1,5 @@
-release: "1.9.67"
-timestamp: 1518475832
+release: "1.9.68"
+timestamp: 1519259623
api_versions: ['1']
supported_api_versions:
@davidwtbuxton
davidwtbuxton / requirements.txt
Created January 29, 2018 16:35
Specify Python source dependencies for pip with an archive instead of a checkout
# If you are pip installing from a repo instead of pypi, archives are faster than git checkouts.
# Fast.
https://github.com/potatolondon/djangae/archive/6e23d264badd1c7a46a5dc64ef99ea9dc77b20ff.zip
# Slow.
# git+https://github.com/potatolondon/djangae.git@6e23d264badd1c7a46a5dc64ef99ea9dc77b20ff
@davidwtbuxton
davidwtbuxton / example.sh
Created January 9, 2018 18:00
you can't sub-class cStringIO.StringIO on Python 2.7
$ python
Python 2.7.14 (default, Sep 22 2017, 00:06:07)
[GCC 4.2.1 Compatible Apple LLVM 8.1.0 (clang-802.0.42)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import cStringIO, StringIO, io
>>> class Foo(io.StringIO): pass
...
>>> class Bar(StringIO.StringIO): pass
...
>>> class Baz(cStringIO.StringIO): pass
@davidwtbuxton
davidwtbuxton / chunker.py
Created January 8, 2018 18:52
Recipe for chunking an iterable
import itertools
def chunker(iterable, n):
"""Collect data into chunks.
This is different to the grouper recipe in itertools in that the final
chunk may be shorter.
>>> chunks = chunker('abcde', 2)
>>> list(chunks)
@davidwtbuxton
davidwtbuxton / testing.sh
Last active December 21, 2017 01:01
Testing a variable matches 1 of 2 values (Python 2.7)
$ python -m timeit -s "v = 'foo'" "v == 'foo' or v == 'bar'"
10000000 loops, best of 3: 0.163 usec per loop
$ python -m timeit -s "v = 'bar'" "v == 'foo' or v == 'bar'"
1000000 loops, best of 3: 0.233 usec per loop
$ python -m timeit -s "v = 'baz'" "v == 'foo' or v == 'bar'"
1000000 loops, best of 3: 0.241 usec per loop
$ python -m timeit -s "v = 'foo'" "v in ('foo', 'bar')"
10000000 loops, best of 3: 0.145 usec per loop
$ python -m timeit -s "v = 'bar'" "v in ('foo', 'bar')"
10000000 loops, best of 3: 0.155 usec per loop
@davidwtbuxton
davidwtbuxton / copying.sh
Created December 15, 2017 19:39
Ways of copying a list in Python 2.7
$ python -m timeit -s 'seq = list(range(10))' '[o for o in seq]'
1000000 loops, best of 3: 1.75 usec per loop
$ python -m timeit -s 'seq = list(range(100))' '[o for o in seq]'
100000 loops, best of 3: 13.2 usec per loop
$ python -m timeit -s 'seq = list(range(1000))' '[o for o in seq]'
10000 loops, best of 3: 115 usec per loop
$ python -m timeit -s 'seq = list(range(10))' 'list(seq)'
1000000 loops, best of 3: 0.372 usec per loop
$ python -m timeit -s 'seq = list(range(100))' 'list(seq)'
1000000 loops, best of 3: 0.609 usec per loop
@davidwtbuxton
davidwtbuxton / gist:9af0250ce66ccb64eee4214ab4ab070e
Last active December 14, 2017 18:50
Profiling different ways for testing if there's an empty string value
$ python -m timeit -s "a, b, c, d, e, f = 'abcdef'" "any(v for v in (a, b, c, d, e, f) if v == '')"
1000000 loops, best of 3: 1.51 usec per loop
$ python -m timeit -s "a, b, c, d, e, f = 'abcdef'" "'' in (a, b, c, d, e, f)"
1000000 loops, best of 3: 0.36 usec per loop
$ python -m timeit -s "a, b, c, d, e, f = ' bcdef'" "any(v for v in (a, b, c, d, e, f) if v == '')"
1000000 loops, best of 3: 1.52 usec per loop
$ python -m timeit -s "a, b, c, d, e, f = ' bcdef'" "'' in (a, b, c, d, e, f)"
1000000 loops, best of 3: 0.354 usec per loop
$ python -m timeit -s "a, b, c, d, e, f = 'abcde '" "any(v for v in (a, b, c, d, e, f) if v == '')"
1000000 loops, best of 3: 1.49 usec per loop
@davidwtbuxton
davidwtbuxton / memory_vs_disk.py
Last active December 7, 2017 19:50
Seeing how reading an image file from disk compares to constructing it in memory
import io
import os
import tempfile
import timeit
# A valid PNG file.
png_bytes = (
'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x01\x00\x00\x00\x01\x08'
'\x06\x00\x00\x00\x1f\x15\xc4\x89\x00\x00\x00\nIDATx\x9cc\x00\x01\x00\x00'