Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / gen-inflections.py
Created October 26, 2015 22:39
Show all inflections used in botocore
#!/usr/bin/env python
import botocore.session
from botocore import xform_name
import time
# Original -> xform'd
all_params = {}
total_time = 0
$ 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)
@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
@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 / 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 + " ");