Skip to content

Instantly share code, notes, and snippets.


Peter Hanley hanleybrand

View GitHub Profile
hanleybrand / Mac imposm
Last active Jan 13, 2021
Install imposm on a mac with all dependencies in a vm, with for postgis
View Mac imposm

Installing imposm

So, according to the imposm docs:

Imposm runs with Python 2.5, 2.6 and 2.7 and is tested on Linux and Mac OS X. Other dependencies are:

psycopg2: PostgreSQL adapter for Python

Tokyo Cabinet: File-based key-value database for the internal cache

hanleybrand /
Last active Aug 18, 2020
python function that produces the same result as java's String.hashCode() found at
def java_string_hashcode(s):
h = 0
for c in s:
h = (31 * h + ord(c)) & 0xFFFFFFFF
return ((h + 0x80000000) & 0xFFFFFFFF) - 0x80000000
hanleybrand / ct_extended_glasses.zs
Last active Feb 25, 2020
WIP ContentTweaker script to create glowing, reinforced and glowing-reinforced variants of the various glass blocks.
View ct_extended_glasses.zs
#loader contenttweaker
import mods.contenttweaker.VanillaFactory;
import mods.contenttweaker.Block;
import mods.contenttweaker.Item;
// ref values
// glass/glowstone 0.3 hardness, 1.5 resistance
// hardened glass (education edition), 10 hardness, unknown resistance
View dropt.zs
import mods.dropt.Dropt;
import crafttweaker.item.IItemStack;
// change conquest plant blocks to only drop their items if broken with a hoe in order to
// cut down on inventory bloat
hanleybrand /
Last active Feb 4, 2020
Blackboard vagrant up and away
# start bb vm
cd ~/hackboard
vagrant up
# ssh via vagrant
vagrant ssh
## alternative ssh - use credentials vagrant/vagrant
ssh vagrant@localhost:2222
hanleybrand /
Created Sep 29, 2015
Some fixes for MDID3's storage/admin page
from django.contrib import admin
from models import Storage, Media, ProxyUrl, TrustedSubnet
class StorageAdmin(admin.ModelAdmin):
list_display = ('title', 'name', 'system', 'base', 'urlbase')
def get_actions(self, request):
hanleybrand / secrit_flags.yaml
Last active Aug 23, 2019
All the secret things in Canvas? *aug 2019
View secrit_flags.yaml
state: hidden
features.google_docs_domain_restriction: Google Docs Domain Restriction
google_docs_domain_restriction_description: |-
Google Docs Domain Restriction allows Google Docs submissions and collaborations
to be restricted to a single domain. Students attempting to submit assignments or
join collaborations on an unapproved domain will receive an error message notifying them
hanleybrand /
Created Dec 6, 2012
Download images with Requests: HTTP for Humans
import requests
from io import open as iopen
from urlparse import urlsplit
def requests_image(file_url):
suffix_list = ['jpg', 'gif', 'png', 'tif', 'svg',]
file_name = urlsplit(file_url)[2].split('/')[-1]
file_suffix = file_name.split('.')[1]
i = requests.get(file_url)
if file_suffix in suffix_list and i.status_code ==
hanleybrand /
Created Jul 23, 2019
Create monthly PPT reports
from datetime import date
from string import Template
from pptx import Presentation
# this file must exist
template = 'x_Academic Apps-y.pptx'
prs = Presentation(template)
fy = ['2018', '2019']
hanleybrand /
Last active Mar 19, 2019
Remove unwanted attributes from tags in HTML snippets with BeautifulSoup (3.21 - might work with BS4)
from BeautifulSoup import BeautifulSoup
def clean(html):
whitelist = ['backColor', 'backcolor', 'bgcolor',
'color', 'fg', 'fontName', 'fontSize',
'fontname', 'fontsize', 'href', 'name',
'textColor', 'textcolor']
html.attrs = None
for e in html.findAll(True):
for attribute in e.attrs: