Skip to content

Instantly share code, notes, and snippets.

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 April 21, 2013 21:46
Semidbm performance
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 December 18, 2015 01:29
cpython vs. pypy O(log n) vs. O(n^2)
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 September 5, 2013 03:38
Download all deps of a local python package
#!/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 December 24, 2015 15:29
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.
import datetime
import time
import sys
import threading
import traceback
import subprocess
import random
def clear_screen():
@jamesls
jamesls / py2py3odict.py
Created November 21, 2013 00:12
OrderedDict vs. dict
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 04:32
Javascript sort stability
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 August 29, 2015 14:16
PR Check Script
#!/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 March 28, 2015 23:45
Asyncio and coroutines confusion
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
$ 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)