Skip to content

Instantly share code, notes, and snippets.

@om-henners
om-henners / Calculate your 5km travel bubble.ipynb
Created September 6, 2020 02:11
Quick bit of Python code to calculate a 5km travel buffer given as a talk at PyConlineAU 2020!
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@om-henners
om-henners / Area of Australian fires vs countries.ipynb
Created January 3, 2020 12:58
Compare the area burnt by Australia's fires to the area of countries and plot out a quick comparison
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@om-henners
om-henners / filter.jq
Last active October 7, 2019 01:52
jq https://stedolan.github.io/jq/ filter to transform GeoJSON Geometry Collection into Feature Collection
.properties as $propertiess | {
"type": "FeatureCollection",
"features": [
(.geometries[] |
{
"type": "Feature",
"properties": (.properties + $propertiess),
"geometry": del(.properties)
}
@om-henners
om-henners / podcast_app.py
Created July 3, 2019 14:02
Simple flask app to dummy up a Podcast RSS feed using Flask and feedgen. Written with Python 3.7
"""
Simple app that generates a podcasst XML feed for Radicalized
To be fair this could be easily adapted to any audiobook / set of NP3s - you'd
just need to change the image, the path to the music and all the descriptions.
Requires:
- feedgen
- flask
@om-henners
om-henners / h3_grid_generation.sh
Created April 28, 2019 14:30
Generate KML files for the first three levels of resolution using Uber Eng's h3 (https://github.com/uber/h3)
mkdir -p KML
for resolution in $(seq 1 3); do
h3ToHier ${resolution} | h3ToGeoBoundary 1 res${resolution}cells.kml "Res ${resolution} Cells" > KML/res${resolution}cells.kml
h3ToHier ${resolution} | h3ToGeo 1 res${resolution}centers.kml "Res ${resolution} Centers" > KML/res${resolution}centers.kml
done
@om-henners
om-henners / serializer_utils.py
Created November 19, 2018 13:51
Marshmallow serializers for turning fields into GeoJSON objects based on flask-sqlalchemy and geoalchemy2
"""
Marshmallow wrappers to produce GeoJSON instead of a flat dictionary.
"""
from flask_marshmallow import Marshmallow
import geoalchemy2
from geoalchemy2.shape import from_shape, to_shape
from marshmallow import fields, pre_load, post_dump, ValidationError
import marshmallow_sqlalchemy as msqla
from shapely import geometry
@om-henners
om-henners / poster_text.inx
Last active October 12, 2021 12:37
Inkscape extension to dump source code text on a page, Lorem Ipsum style. Inspired by http://www.east5th.co/blog/2017/02/13/build-your-own-code-poster-with-elixir/ To install, drop these to files in your ~/.config/inkscape/extensions folder, restart inkscape and it's in the Extensions > Text menu.
<?xml version="1.0" encoding="UTF-8"?>
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
<_name>Source Code Text</_name>
<id>org.henry.poster_text</id>
<dependency type="executable" location="extensions">poster_text.py</dependency>
<dependency type="executable" location="extensions">inkex.py</dependency>
<param name="tab" type="notebook">
<page name="Options" _gui-text="Options">
<param name="directory" type="string" _gui-text="Directory to search for code:">~/</param>
<param name="pattern" type="string" _gui-text="Filename pattern to match:">py</param>
@om-henners
om-henners / pyconau_2016_tweets.py
Last active August 15, 2016 22:03
Download pyconau tweets with Twython. Because of twitter's rate limiting this will take a while to execute. Also, the files wind up pretty large (~300mb per rate limited block)
# coding: utf-8
from __future__ import print_function
from datetime import date, timedelta, datetime
import json
from time import sleep
from twython import Twython, TwythonRateLimitError
APP_KEY = 'YOUR_APP_KEY'
@om-henners
om-henners / arcpy_dataframe.py
Created August 11, 2016 05:38
Quick sample of converting an ArcGIS feature class to a pandas dataframe using arcpy.
import arcpy
import pandas as pd
def build_df_from_arcpy(table, index_col=None):
"""
Build a pandas dataframe from an ArcGIS Feature Class.
Uses the arcpy Search Cursor to loop over a feature class in pandas and
generate a pandas dataframe. If the dataset is a feature class with a
station date mm
Footscray 8/3/15 0.20
Footscray 15/3/15 0.00
Footscray 22/3/15 1.60
Footscray 29/3/15 0.80
Footscray 5/4/15 0.00
Footscray 12/4/15 5.20
Footscray 19/4/15 8.00
Footscray 26/4/15 8.00
Footscray 3/5/15 0.60