Skip to content

Instantly share code, notes, and snippets.

@gthank
gthank / numpy-ified-great-circle.py
Created September 16, 2016 11:44
numpy-based method for calculating (great circle) distance between two series of points.
import numpy as np
import pandas as pd
from geopy.distance import EARTH_RADIUS
def numpy_distance(src_lats, src_longs, dest_lats, dest_longs):
"""Calculate distance between (effectively) two Series of points."""
# Convert from degrees to radians.
src_lats = src_lats.apply(np.deg2rad)
src_longs = src_longs.apply(np.deg2rad)
dest_lats = dest_lats.apply(np.deg2rad)
dest_longs = dest_longs.apply(np.deg2rad)
# Works on Py3
def parse_version_failsafe(version_string):
try:
return Version(
unicodedata.normalize('NFKD', six.text_type(version_string))
)
except (UnicodeError, InvalidVersion):
return None
import datetime
def get_date(x):
"""Extract date from the provided timestamp.
Useful because the Pandas data model makes it hard to invoke
instance methods of values directly."""
return x['Occurred Date or Date Range Start'].date()
@gthank
gthank / error
Created June 6, 2016 21:16
`pip install jupyter` output
⇒ pip install jupyter [ruby-2.2.1]
Collecting jupyter
Downloading https://dev-infrastructure.rescuetime.com/root/pypi/+f/f81/d039e084c2c0c/jupyter-1.0.0-py2.py3-none-any.whl
Collecting qtconsole (from jupyter)
Downloading https://dev-infrastructure.rescuetime.com/root/pypi/+f/046/29b6bfeaa40fd/qtconsole-4.2.1-py2.py3-none-any.whl (104kB)
100% |████████████████████████████████| 112kB 1.4MB/s
Collecting ipykernel (from jupyter)
Downloading https://dev-infrastructure.rescuetime.com/root/pypi/+f/8dc/3c636084d2471/ipykernel-4.3.1-py2.py3-none-any.whl (93kB)
100% |████████████████████████████████| 102kB 1.8MB/s
Collecting nbconvert (from jupyter)
@gthank
gthank / gist:8060790
Created December 20, 2013 20:18
Error from jython-ssl when trying to install setup tools
../../dist/bin/jython ez_setup.py
Downloading https://pypi.python.org/packages/source/s/setuptools/setuptools-2.0.1.tar.gz
Extracting in /var/folders/z0/0wnmjqt16pg547qwlmcw0xdw0000gp/T/tmpiUmmta
Now working in /var/folders/z0/0wnmjqt16pg547qwlmcw0xdw0000gp/T/tmpiUmmta/setuptools-2.0.1
Installing Setuptools
Traceback (most recent call last):
File "setup.py", line 200, in <module>
dist = setuptools.setup(**setup_params)
File "/Users/whg/dev/jython-ssl/dist/Lib/distutils/core.py", line 112, in setup
_setup_distribution = dist = klass(attrs)
@gthank
gthank / snippet.html
Created December 12, 2013 18:29
sample combobox and store
<div data-dojo-type="dojo/store/Memory"
data-dojo-id="vendorStore"
data-dojo-props="[{id: 'spam', name: 'spam'}, {id: 'ham', name: 'ham'}, {id: 'eggs', name: 'eggs'}]">
</div>
<!-- SNIP -->
<input
name="stuffAndStuff"
id="stuffAndStuff"
class="actualExpenseVendorControl"
data-dojo-type="dijit/form/ComboBox"
@gthank
gthank / gist:7909669
Created December 11, 2013 12:35
matplotlib fails to install, because of some (missing?) freetype headers
whg@hanks-mbp:~|⇒ brew doctor
Warning: "config" scripts exist outside your system or Homebrew directories.
`./configure` scripts often look for *-config scripts to determine if
software packages are installed, and what additional flags to use when
compiling and linking.
Having additional scripts in your path can confuse software installed via
Homebrew if the config script overrides a system or Homebrew provided
script of the same name. We found the following "config" scripts:
@gthank
gthank / flair.css
Created July 24, 2013 14:18
balky flair CSS
.flair {
border: none !important;
top: 20px;
padding: 0px;
background: url(%%hawks-flair-partial%%);
display: inline-block; }
.flair-10sharpsmall {
background-position: 0 0;
width: 16px;
± heroku run bundle exec rake clean generate
Running `bundle exec rake clean generate` attached to terminal... up, run.1266
rm -rf .pygments-cache/** .gist-cache/** .sass-cache/** source/stylesheets/screen.css
## Generating Site with Jekyll
create source/stylesheets/screen.css
Configuration from /app/_config.yml
Building site: source -> public
Liquid Exception: incompatible character encodings: UTF-8 and ASCII-8BIT in atom.xml
/app/vendor/bundle/ruby/1.9.1/gems/liquid-2.3.0/lib/liquid/block.rb:92:in `join'
/app/vendor/bundle/ruby/1.9.1/gems/liquid-2.3.0/lib/liquid/block.rb:92:in `render_all'
@gthank
gthank / micro.py
Created July 25, 2012 19:54
list_comp vs. map
#! /usr/bin/env python
import timeit
def main():
list_comp_t = timeit.Timer("y = [math.log10(num) for num in x]", setup="import math; x = [1500, 1049.8, 34, 351]")
map_t = timeit.Timer("z = map(math.log10, x)", setup="import math; x = [1500, 1049.8, 34, 351]")
# Use an absurdly high number of reps because the data is tiny and I want the numbers to be on a reasonably human timescale.
print list_comp_t.timeit(1000000)
print map_t.timeit(1000000)