Skip to content

Instantly share code, notes, and snippets.

View edwardabraham's full-sized avatar

Edward Abraham edwardabraham

View GitHub Profile
@edwardabraham
edwardabraham / hexagon_tiling.sql
Last active March 1, 2018 07:16
Hexagonal tiling for PostGIS
-- Hexagonal tiling for PostGIS
-------------------------------
-- Edward Abraham, Dragonfly Science
-- Use freely
-- Functions for generating tiles in a hexagonal tiling, from cartesian
-- coordinates. The tiling is made of hexagons defined by their 'width'
-- (the distance bewteen two parallel sides). The hexagon with index (0, 0)
-- is centered on the point x=0, y=0, and is oriented so that it points
-- upwards. Hexagons in the same row have the same j-coordinate, and hexagons
@edwardabraham
edwardabraham / jpegfield.py
Created August 19, 2012 05:55 — forked from zmsmith/jpegfield.py
Implementation of a Django ImageField that converts all images to JPEG
import os
from PIL import Image
import cStringIO
from django.core.files.base import ContentFile
from django.db.models import ImageField
from django.db.models.fields.files import ImageFieldFile
class JPEGImageFieldFile(ImageFieldFile):
@edwardabraham
edwardabraham / git_prompt.sh
Last active December 18, 2015 17:29
A git aware bash prompt for ubuntu, that shows what branch you are on, and whether you have anything to commit. Add to your .bashrc file. Works with git version 1.7.9.5. Initially taken from http://www.intridea.com/blog/2009/2/2/git-status-in-your-prompt
# A git aware bash prompt for ubuntu, that shows what branch you are on, and whether you have anything to commit.
# Add to your .bashrc file.
# Works with git version 1.7.9.5.
#
# Based on http://www.intridea.com/blog/2009/2/2/git-status-in-your-prompt
function parse_git_dirty {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "*"
}
function parse_git_branch {
@edwardabraham
edwardabraham / git-time-log
Last active December 20, 2015 13:08
I sometimes need to work out when I worked on a project. This is a one-liner bash script that gives me a list of all my commits on a project that I can use to reconstruct my time-sheets.
#!/bin/sh
git log --date='short' --format='%ad %an %s' | grep $1
@edwardabraham
edwardabraham / timezone_lookup.py
Last active January 30, 2020 08:49
Get a dictionary mapping timezone abbreviations to names, using pytz
""" Make a dictionary that maps timezone abbreviations to timezone names.
The timezone_lookup module supplies a single dictionary, timezone_lookup. For example,
>>> timezone_lookup['EST']
'US/Michigan'
"""
from datetime import datetime
import pytz
@edwardabraham
edwardabraham / chemistry.html
Last active August 29, 2015 14:07
Experiments in D3 - diffusing particles
<!DOCTYPE html>
<meta charset="utf-8">
<style>
body {
background: #333;
}
</style>
<body>
@edwardabraham
edwardabraham / word_probability.py
Last active May 22, 2019 02:53
Example of calculating the probability of a word, from character probabilities
# A python example of calculating the probability of the word 'hine'
# See https://discourse.mozilla.org/t/quick-heads-up-on-some-metadata-confidence-estimate-work-were-doing/40618/2
# The probability that a word is incorrect before the nth letter:
def p_not_word(n, probabilities):
if n == 0:
return 0
else:
return probabilities[n - 1] * p_not_word(n - 1, probabilities) + \
(1 - probabilities[n - 1])