Skip to content

Instantly share code, notes, and snippets.

View jontwo's full-sized avatar

Jon Morris jontwo

View GitHub Profile
@jontwo
jontwo / chaos_game.py
Created October 11, 2022 14:10
Chaos game
"""Create a fractal using chaos game."""
import argparse
import os
import random
from collections import namedtuple
# Matplotlib made me do this
import matplotlib
matplotlib.use(os.environ.get('MPL_BACKEND', 'WXAgg'))
@jontwo
jontwo / get_feature_repro.py
Last active June 25, 2022 12:52
Repro case for GDAL GetFID/GetFeature issue https://github.com/OSGeo/gdal/issues/5967
"""Repro case for GetFID/GetFeature bug."""
from osgeo import ogr
# some features in increasing size order
WKT1 = 'POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))'
WKT2 = 'POLYGON ((2 0, 2 2, 4 2, 4 0, 2 0))'
WKT3 = 'POLYGON ((5 0, 5 5, 10 5, 10 0, 5 0))'
WKT4 = 'POLYGON ((12 0, 12 8, 20 8, 20 0, 12 0))'
@jontwo
jontwo / add_border.py
Created December 19, 2021 15:47
Adds a border to image files ready for uploading to Instagram. Required Python Pillow/PIL library to be installed. Output image size, border size, and image size as proportion of output are hardcoded - alter according to your needs!
"""Adds a border to image files ready for uploading to Instagram."""
import os
import sys
from PIL import Image, ImageDraw
# output image and border sizes in pixels
WIDTH = HEIGHT = 3000
BORDER = 0
@jontwo
jontwo / check_geotags.py
Last active May 25, 2020 11:30
Check if any photos have been geotagged. I usually turn off geotagging for privacy reasons, but realised that one or two of my photos were still tagged. This script scans a directory and reads the EXIF tags of any jpgs in there, logging with ones have a location tag. Requires PIL/Pillow library to be installed.
# -*- coding:utf-8 -*-
"""check_geotags.py.
Scans an image folder and logs which jpgs have GPS tags in the EXIF data.
Requires PIL/Pillow to be installed in the current environment.
"""
import os
import sys
@jontwo
jontwo / .gitconfig
Created November 17, 2017 14:33
Default git config settings - delete OS-dependent settings as applicable
[alias]
diffd = diff --diff-filter=d
diffn = diff --name-status
[push]
default = simple
# linux only
[credential]
helper = cache --timeout=999999
[core]
@jontwo
jontwo / .bashrc
Created November 17, 2017 14:26 — forked from justintv/.bashrc
Display git branch in bash prompt
# If you work with git, you've probably had that nagging sensation of not knowing what branch you are on. Worry no longer!
export PS1="\\w:\$(git branch 2>/dev/null | grep '^*' | colrm 1 2)\$ "
# This will change your prompt to display not only your working directory but also your current git branch, if you have one. Pretty nifty!
# ~/code/web:beta_directory$ git checkout master
# Switched to branch "master"
# ~/code/web:master$ git checkout beta_directory
# Switched to branch "beta_directory"
@jontwo
jontwo / toolbox_template.py
Created January 12, 2017 11:35
Generic tool template for ArcGIS commandline script
# ----------------------------------------------------------------------------
# Name: My tool
# Purpose: TODO
#
# Author: Jon Morris
#
# Created: 2017
# Copyright: MY COMPANY 2017
# Licence: ArcGIS for Desktop Advanced
# ----------------------------------------------------------------------------
@jontwo
jontwo / toolbox_template.pyt
Created January 12, 2017 11:32
Generic python toolbox template for ArcGIS
# ----------------------------------------------------------------------------
# Name: My tool
# Purpose: TODO
#
# Author: Jon Morris
#
# Created: 2017
# Copyright: MY COMPANY 2017
# Licence: ArcGIS for Desktop Advanced
# ----------------------------------------------------------------------------
@jontwo
jontwo / ioutils.py
Last active July 31, 2017 09:54
Helper library for commonly-used file IO tasks. Just add to your python path and import.
"""
Name: ioutils.py
Purpose: Utilities module for file read/write/delete/etc.
Author: jpm
Created: 17/03/2016
Copyright: (c) jpm 2016
Licence: GPL v3. See http://www.gnu.org/licenses/
"""
@jontwo
jontwo / get_test_coverage.py
Created July 1, 2016 11:01
C# test coverage
# -*- coding: utf-8 -*-
"""
Name: get_test_coverage.py
Purpose: Analyze C# project to check each class has at least one unit test
Author: jpm
Created: 18/09/2015
Copyright: (c) jpm 2015
Licence: GPL v3. See http://www.gnu.org/licenses/