This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
from matplotlib.collections import PatchCollection | |
from descartes import PolygonPatch | |
import fiona | |
from shapely.geometry import Polygon, MultiPolygon, shape | |
# We can extract the London Borough boundaries by filtering on the AREA_CODE key | |
mp = MultiPolygon( | |
[shape(pol['geometry']) for pol in fiona.open('data/boroughs/boroughs.shp') | |
if pol['properties']['AREA_CODE'] == 'LBO']) |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
required packages: | |
numpy | |
matplotlib | |
basemap: http://matplotlib.org/basemap/users/installing.html | |
shapely: https://pypi.python.org/pypi/Shapely | |
descartes: https://pypi.python.org/pypi/descartes | |
random | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
""" | |
excel_things.py | |
Created by Stephan Hügel on 2011-05-07 | |
Read XLS or CSV files, and return contents as unicode strings in nested lists | |
One row per list item, one column per nested list item: | |
[[u'foo', u'bar'], [u'baz', u'abc123'], … ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
def bng(input_lat, input_lon): | |
""" | |
Convert WGS84 lat and long (ie. from GPS) to OSGB36 (BNG) | |
Expects two floats as input | |
Returns a tuple of Easting, Northing floats | |
Accurate to ~5m | |
For testing purposes: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
# Requires PIL (pillow) and NumPy | |
# Copyright (C) Stephan Hügel, 2016 | |
# License: MIT | |
import sys | |
from PIL import Image | |
import numpy as np |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import numpy as np | |
from pysal.esda.mapclassify import Natural_Breaks as nb | |
df = pd.DataFrame({'density': np.random.randint(0, 10, 500)}) | |
# replace zero values with NaN | |
df.replace(to_replace={'density': {0: np.nan}}, inplace=True) | |
breaks = nb(df[df['density'].notnull()].density.values, k=5) | |
# this index will allow us to perform the join correctly |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Given a string, how do you determine whether it's an anagram of a palindrome? | |
// Solution: Given the unique set of chars, at most 1 should appear in the string | |
// an odd number of times. | |
// chars() returns Unicode Scalar Values, and these might not match up | |
// with grapheme clusters, so this can't be assumed to work correctly | |
// for anything other than (extended) ASCII | |
fn unique_chars(s: &str) -> String { | |
let mut v: Vec<char> = s.chars().collect(); | |
// dedup removes consecutive identical elements, so we need a sort first |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# needs Pandas, Geopandas, Shapely. Should work on 2.7.x and 3.6.x | |
# this will only dump properties that are open or partially open today | |
# this can be adjusted by commenting out or altering the values given to isin() | |
from datetime import date | |
import geopandas as gp | |
import pandas as pd | |
from shapely.geometry import Point, LineString, Polygon, MultiPolygon, MultiPoint, box |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# original: http://julianoliver.com/output/log_2014-05-30_20-52 | |
# GLASSHOLE.SH | |
# | |
# Find and kick Google Glass devices from your local wireless network. Requires | |
# 'beep', 'arp-scan', 'aircrack-ng' and a GNU/Linux host. Put on a BeagleBone | |
# black or Raspberry Pi. Plug in a good USB wireless NIC (like the TL-WN722N) | |
# and wear it, hide it in your workplace or your exhibition. | |
# | |
# Save as glasshole.sh, 'chmod +x glasshole.sh' and exec as follows: |