Skip to content

Instantly share code, notes, and snippets.

View jboynyc's full-sized avatar
🍜

John Boy jboynyc

🍜
View GitHub Profile
@jboynyc
jboynyc / ZwartePiet_Analysis.ipynb
Last active August 29, 2015 14:10
A look at 2½ weeks' worth of #zwartepiet tweets
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jboynyc
jboynyc / cheryls-birthday.hy
Created April 25, 2015 15:27
What is Cheryl's birthday?
(def *possible-dates*
["May 15" "May 16" "May 19" "June 17" "June 18" "July 14" "July 16"
"August 14" "August 15" "August 17"])
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn cheryls-birthday [possible-dates]
(filter all-statements possible-dates))
(defn month [date]
@jboynyc
jboynyc / UniqueQueue.py
Created May 19, 2015 09:07
Wrap Beanstalkc to create unique (deduplicated) queues.
import beanstalkc
from redis import Redis
class UniqueQueue(object):
'''Stores a persistent set of added jobs in Redis to keep jobs from being
added to the Beanstalkd queue more than once.'''
def __init__(self, tube_name='default', host='localhost'):
self.beanstalk = beanstalkc.Connection(host=host)
self.beanstalk.use(tube_name)
self.tube = self.beanstalk.using()
@jboynyc
jboynyc / geometry_from_osm.py
Last active November 24, 2016 14:38
Create a geometry from an OpenStreetMap element
import requests
from functools import partial
from collections import OrderedDict
from xml.dom.minidom import parseString as xml_parse
from shapely.geometry import MultiPolygon, Polygon, Point
def osm_getter(element_id, endpoint):
assert endpoint in ('node', 'way', 'relation')
OSM_API_URL = 'http://www.openstreetmap.org/api/0.6/{}/{}'
@jboynyc
jboynyc / idea_of_nature.md
Created March 1, 2016 23:21
Summary of R. G. Collingwood, "The Idea of Nature" (1945)

R. G. Collingwood, The Idea of Nature (Oxford: Clarendon Press, 1945).

Collingwood’s concern in this little book is to clarify the idea of nature as it underlies both natural science and philosophy. Saying that science is “based” on nature does not mean that the idea of nature is worked out first and all further scientific investigation proceeds from it. Rather, the conception of nature is subject to change along with scientific knowledge. Collingwood does not believe that there is one correct view of nature but rather seems to believe with Hegel that “the true is the whole,” that is, that the entire history of the concept and not just the “bottom line” of our modern

import requests
try:
from urllib.parse import urlencode
except ImportError:
from urllib import urlencode
def reverse_geocode(lng, lat, zoom=18):
OSM_API_URL = 'http://nominatim.openstreetmap.org/reverse?'
_headers = {'User-Agent':
@jboynyc
jboynyc / ig_to_json.py
Last active March 30, 2016 13:53
Write an igraph graph to a JSON file for use with Sigma.js
import os
import json
import igraph as ig
def ig_to_json(graph, path):
assert isinstance(graph, ig.Graph)
nodes = []
edges = []
@jboynyc
jboynyc / sintenpietengilde_intochten.py
Created April 4, 2016 10:52
Find Dutch blackface parades
import re
import requests
import pandas as pd
from xml.dom.minidom import parseString as xml_parse
MAP_URL = 'http://sintenpietengilde.nl/Kaart.html'
KML_OUT = 'sintenpietengilde_kaart.kml'
XLS_OUT = 'sintenpietengilde_kaart.xlsx'
@jboynyc
jboynyc / snarf-all-pdfs.py
Last active June 8, 2016 10:23
Easily download all linked PDFs from a web page using the IPython/Jupyter console
from bs4 import BeautifulSoup as bs
r = !curl -s 'https://example.net'
s = bs(''.join(r))
for link in s.findAll('a', {'href': lambda x: x.endswith('pdf')}):
loc = link['href']
!curl -O $loc
@jboynyc
jboynyc / amsterdam_bounds.wkt
Created November 17, 2016 14:03
Amsterdam municipality bounds
MULTIPOLYGON (((4.7567178999999999 52.3778378000000020, 4.7564339000000002 52.3777635000000000, 4.7569860000000004 52.3770463000000030, 4.7575304999999997 52.3761888000000010, 4.7580470000000004 52.3750653000000030, 4.7583805000000003 52.3740153000000030, 4.7585170000000003 52.3732593000000010, 4.7585676000000001 52.3727554000000030, 4.7585964000000001 52.3722175999999990, 4.7585747999999999 52.3715943999999990, 4.7585107999999998 52.3712412000000000, 4.7584413999999997 52.3709575999999970, 4.7579834999999999 52.3692393999999980, 4.7578265000000002 52.3687134999999980, 4.7567178999999999 52.3778378000000020)), ((4.7590846000000004 52.3807575000000010, 4.7590851000000001 52.3807377999999990, 4.7590902000000002 52.3805027000000010, 4.7590915000000003 52.3804415999999970, 4.7590922000000004 52.3804074000000030, 4.7590925999999998 52.3803957000000010, 4.7591020999999998 52.3800388000000010, 4.7591023999999997 52.3800254000000010, 4.7591028000000000 52.3800136999999990, 4.7591124999999996 52.3797112000000030, 4.75