Skip to content

Instantly share code, notes, and snippets.

Avatar

Peter Hanley hanleybrand

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

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
hanleybrand / java_String_hashcode.py
Last active Aug 18, 2020
python function that produces the same result as java's String.hashCode() found at http://garage.pimentech.net/libcommonPython_src_python_libcommon_javastringhashcode/
View java_String_hashcode.py
def java_string_hashcode(s):
h = 0
for c in s:
h = (31 * h + ord(c)) & 0xFFFFFFFF
return ((h + 0x80000000) & 0xFFFFFFFF) - 0x80000000
@hanleybrand
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
#debug
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
Dropt.list("conquest_drops")
.add(Dropt.rule()
@hanleybrand
hanleybrand / bb-vargrant-notes.sh
Last active Feb 4, 2020
Blackboard vagrant up and away
View bb-vargrant-notes.sh
# start bb vm
cd ~/hackboard
vagrant up
# ssh via vagrant
vagrant ssh
## alternative ssh - use credentials vagrant/vagrant
ssh vagrant@localhost:2222
@hanleybrand
hanleybrand / storage_admin.py
Created Sep 29, 2015
Some fixes for MDID3's storage/admin page
View storage_admin.py
from django.contrib import admin
from models import Storage, Media, ProxyUrl, TrustedSubnet
class StorageAdmin(admin.ModelAdmin):
list_display = ('title', 'name', 'system', 'base', 'urlbase')
# http://stackoverflow.com/questions/9563935/removing-buttons-links-in-django-admin
def get_actions(self, request):
@hanleybrand
hanleybrand / secrit_flags.yaml
Last active Aug 23, 2019
All the secret things in Canvas? *aug 2019
View secrit_flags.yaml
---
google_docs_domain_restriction:
state: hidden
display_name:
features.google_docs_domain_restriction: Google Docs Domain Restriction
description:
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
hanleybrand / requests_image.py
Created Dec 6, 2012
Download images with Requests: HTTP for Humans
View requests_image.py
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 == requests.codes.ok:
@hanleybrand
hanleybrand / make_monthly_pptx.py
Created Jul 23, 2019
Create monthly PPT reports
View make_monthly_pptx.py
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
hanleybrand / clean_attrs.py
Last active Mar 19, 2019
Remove unwanted attributes from tags in HTML snippets with BeautifulSoup (3.21 - might work with BS4)
View clean_attrs.py
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: