Skip to content

Instantly share code, notes, and snippets.

View urschrei's full-sized avatar
💭
🌒

Stephan Hügel urschrei

💭
🌒
View GitHub Profile
@urschrei
urschrei / factorial_bees.py
Last active August 29, 2015 14:02
Generate Factorial Emoji Bees
# -*- coding: utf8 -*-
def countdown(counter, s):
"""
Print factorial numbers of emoji beasts
Inspired by @direlog
"""
if counter < 1:
return
else:
@urschrei
urschrei / glasshole.sh
Created May 31, 2014 14:13
The below script will find and detect Google Glass on the local network and kick them off. Read the comments for more details.
#!/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:
@urschrei
urschrei / jenks_breaks_notnull.py
Last active August 29, 2015 13:57
Calculate Jenks Natural Breaks on complete and NaN-containing datasets, using PySAL
from pysal.esda.mapclassify import Natural_Breaks as nb
# Calculate Jenks natural breaks
# Assumes that there are no NaN values in Series
breaks = nb(
df['column'].values,
initial=300,
k=5)
jb = pd.DataFrame({'jenks_bins': breaks.yb}, index=df['column'].index)
@urschrei
urschrei / ci.py
Created January 31, 2014 12:15
Calculate and plot Statsmodels OLS and WLS confidence intervals
from statsmodels.stats.outliers_influence import summary_table
from statsmodels.sandbox.regression.predstd import wls_prediction_std
# carry out yr fit
# ols cinv
st, data, ss2 = summary_table(ols_fit, alpha=0.05)
fittedvalues = data[:,2]
predict_mean_se = data[:,3]
@urschrei
urschrei / jenks_zero.py
Created September 22, 2013 17:45
Calculate Jenks natural breaks on a dataset containing zero values, using Pandas and Pysal
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
@urschrei
urschrei / jenks2.py
Created September 22, 2013 00:28 — forked from llimllib/jenks2.py
import json
from pprint import pprint as pp
def jenks_matrices_init(data, n_classes):
#fill the matrices with data+1 arrays of n_classes 0s
lower_class_limits = []
variance_combinations = []
for i in xrange(0, len(data)+1):
temp1 = []
temp2 = []
@urschrei
urschrei / shapefile.py
Last active September 29, 2021 08:24
Open a shapefile using Fiona, and plot its features using Matplotlib and Descartes
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'])
@urschrei
urschrei / basemap_descartes.py
Last active November 6, 2020 02:49
How to plot Shapely Points using Matplotlib, Basemap, and Descartes
"""
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
@urschrei
urschrei / map.geojson
Created August 22, 2013 18:32
via:geojson.io
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@urschrei
urschrei / call.txt
Last active December 19, 2015 19:49
This gist is now a proper repo: https://github.com/urschrei/lovecraft
Iä!