Skip to content

Instantly share code, notes, and snippets.

@perrygeo
perrygeo / der.py
Created March 9, 2017 23:56
der, the human-readable dir() with types and interfaces
from __future__ import print_function
from collections import OrderedDict
from numbers import Number
import collections
import sys
PY3 = sys.version_info[0] == 3
if PY3:
string_types = str,
from __future__ import print_function, division
from collections import defaultdict
from functools import wraps
import os
import json
import logging
import threading
import time
import psutil
@perrygeo
perrygeo / xtr
Created February 10, 2017 18:44
#!/usr/bin/env python
# pylint: disable=W0621
import json
import math
import re
import sys
# From mercantile
def ul(*tile):
from concurrent import futures
from datetime import datetime
import requests
def threadmap(func, seq, concurrency=8):
"""Apply function to each item in seq in a concurrent threadpool
Only beneficial for IO-bound tasks because of the GIL
Parameters:

Raw script

/bin/timber

#!/usr/bin/env python

if __name__ == '__main__':
    from timber.scripts.cli import cli
    cli()
Year Punxsutawney Phil February Average Temperature February Average Temperature (Northeast) February Average Temperature (Midwest) February Average Temperature (Pennsylvania) March Average Temperature March Average Temperature (Northeast) March Average Temperature (Midwest) March Average Temperature (Pennsylvania)
1886 No Record
1887 Full Shadow
1888 Full Shadow
1889 No Record
1890 No Shadow
1891 No Record
1892 No Record
1893 No Record
1894 No Record
@perrygeo
perrygeo / fstring_benchmark.py
Created December 24, 2016 23:15
Are f-strings or .format faster?
#!/usr/bin/env python3.6
import time
n = 1_000_000
print("Using .format")
start = time.time()
template = "This is a new {thing} with {x} properties"
for thing, x in zip('abcdefghijklmnopqrstuvwxyz' * int(n/26), range(n)):
_ = template.format(thing=thing, x=x)
@perrygeo
perrygeo / coords-for.sh
Created December 20, 2016 13:05
Geocode coordinates in `lat/lon` format for Mapbox web URIs
function coords-for {
if [ $# -lt 1 ]; then
echo "Usage: coords-for LOCATION"
fi
local location=$1
mapbox geocoding "$location" --features --limit 1 \
| jq -c ".center|[.[1],.[0]]" \
| sed 's/\[//g' | sed 's/\]//g' | sed 's/,/\//g'
}
@perrygeo
perrygeo / mercator.hs
Created December 11, 2016 16:19
Haskell experiment, mercator point projection
{-# LANGUAGE NamedFieldPuns #-}
-- ^^ allows us to write cleaner Record destructuring
-- func (Point {x, y}) =
-- instead of
-- func (Point {x=x, y=y}) =
-- consts
earthRadius = 6378137 -- meters
-- trig
]0;IPython: work/rasterioTest data present.
============================= test session starts ==============================
platform darwin -- Python 3.5.2, pytest-3.0.2, py-1.4.31, pluggy-0.3.1 -- /Users/mperry/env/mapbox35/bin/python3.5
cachedir: .cache
rootdir: /Users/mperry/work/rasterio, inifile: setup.cfg
plugins: xdist-1.15.0, mypy-0.2.0, ipdb-0.1.dev2, flake8-0.8.1, cov-2.3.1, hypothesis-3.5.2
collecting ... collected 76 items
tests/test_warp.py::test_transform PASSED
tests/test_warp.py::test_transform_bounds PASSED