Skip to content

Instantly share code, notes, and snippets.

View gist:5157404
wget https://s3.amazonaws.com/jamessar-pycon-2013/shortflask.tar.gz
wget https://s3.amazonaws.com/elasticbeanstalk/cli/AWS-ElasticBeanstalk-CLI-2.3.1.zip
@jamesls
jamesls / semidbmperf1
Created Apr 21, 2013
Semidbm performance
View semidbmperf1
Was trying to optimize sequential writes (fill_sequential benchmark). Showing:
* Current released version
* performance regression with python3 support
* Better performance with binary file format
Benchmark params:
100,000 keys, key size 16 bytes, value size 100 bytes
@jamesls
jamesls / gist:5704452
Last active Dec 18, 2015
cpython vs. pypy O(log n) vs. O(n^2)
View gist:5704452
Time taken to insert elements into the specified data structures.
Left hand column is total number of elements, right hand side is total time.
Recall skiplist insert is O(log n) in average case, binary search insert is O(n) worst case.
python2.7:
Skiplist insert (implemented in pure python):
10: 0.000175
@jamesls
jamesls / dldeps.py
Created Sep 5, 2013
Download all deps of a local python package
View dldeps.py
#!/usr/bin/env python
# Given a local checkout of a python package
# in SOURCE_DIR, this script will download all
# of its deps (transitively) into BUNDLE_DIR.
import os
import shutil
import subprocess
BUNDLE_DIR = '/tmp/bundle'
# Directory of the local package (should contain a setup.py file).
@jamesls
jamesls / misbehave.py
Last active Dec 24, 2015
thread stack traces make it hard to see CPU bound problems. Run the script with no args, and read the bottom comment in each stack trace (there are three threads so you'll see three stack traces). Note that despite taking almost 100% CPU, the stack traces show the worker thread sleeping.
View misbehave.py
import datetime
import time
import sys
import threading
import traceback
import subprocess
import random
def clear_screen():
@jamesls
jamesls / py2py3odict.py
Created Nov 21, 2013
OrderedDict vs. dict
View py2py3odict.py
from collections import OrderedDict
# This will raise a RuntimeError in python3, but will work
# in python2.
regular_dict = dict(a='a', b='c')
for i, j in regular_dict.items():
regular_dict[i + j] = j
# This will create an infinite loop and consume all memory
@jamesls
jamesls / sort.js
Created May 20, 2014
Javascript sort stability
View sort.js
function sortArray(n) {
var array = [];
for (var i = 1; i <= n; i++) {
array.push({key: 10, name: i.toString()});
}
array.sort(function(a, b) {
return a.key - b.key;
});
for(var j = 0; j < n; j++) {
process.stdout.write(array[j].name + " ");
@jamesls
jamesls / pr-check
Last active Aug 29, 2015
PR Check Script
View pr-check
#!/usr/bin/env python
"""Script to do an intial review of a PR.
There are many things that a core dev will look at when reviewing a pull
request. Many of these things will require the expertise of someone who is
familiar with the codebase.
There are also things that can be entirely automated.
That's the point of this script. To get all the checks that can be automated,
@jamesls
jamesls / async-confusing.py
Created Mar 28, 2015
Asyncio and coroutines confusion
View async-confusing.py
import asyncio
@asyncio.coroutine
def coro():
return "foo"
# Writing the code without a list comp works,
# even with an asyncio.sleep(0.1).
@asyncio.coroutine
View gist:e73d0adf20c6460369be
$ make test
go test -v ./...
? github.com/jmespath/jmespath.go/cmd/jp [no test files]
=== RUN TestCompliance
Best: a
--- PASS: TestCompliance (0.02s)
=== RUN TestCanLexTokens
--- PASS: TestCanLexTokens (0.00s)
=== RUN TestLexingErrors
--- PASS: TestLexingErrors (0.00s)