Skip to content

Instantly share code, notes, and snippets.

Edward Abraham edwardabraham

Block or report user

Report or block edwardabraham

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@edwardabraham
edwardabraham / word_probability.py
Last active May 22, 2019
Example of calculating the probability of a word, from character probabilities
View word_probability.py
# 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])
@edwardabraham
edwardabraham / chemistry.html
Last active Aug 29, 2015
Experiments in D3 - diffusing particles
View chemistry.html
<!DOCTYPE html>
<meta charset="utf-8">
<style>
body {
background: #333;
}
</style>
<body>
@edwardabraham
edwardabraham / timezone_lookup.py
Last active Apr 14, 2017
Get a dictionary mapping timezone abbreviations to names, using pytz
View timezone_lookup.py
""" 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 / git-time-log
Last active Dec 20, 2015
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.
View git-time-log
#!/bin/sh
git log --date='short' --format='%ad %an %s' | grep $1
@edwardabraham
edwardabraham / git_prompt.sh
Last active Dec 18, 2015
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
View git_prompt.sh
# 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 / jpegfield.py
Created Aug 19, 2012 — forked from zmsmith/jpegfield.py
Implementation of a Django ImageField that converts all images to JPEG
View jpegfield.py
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 / hexagon_tiling.sql
Last active Mar 1, 2018
Hexagonal tiling for PostGIS
View hexagon_tiling.sql
-- 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
You can’t perform that action at this time.