Skip to content

Instantly share code, notes, and snippets.

View hanleybrand's full-sized avatar

Peter Hanley hanleybrand

View GitHub Profile
@hanleybrand
hanleybrand / java_String_hashcode.py
Last active November 20, 2022 18:09
python function that produces the same result as java's String.hashCode() found at http://garage.pimentech.net/libcommonPython_src_python_libcommon_javastringhashcode/
def java_string_hashcode(s):
h = 0
for c in s:
h = (31 * h + ord(c)) & 0xFFFFFFFF
return ((h + 0x80000000) & 0xFFFFFFFF) - 0x80000000
@hanleybrand
hanleybrand / saved_scryfall_searches.md
Last active July 7, 2021 15:57
scryfall searches
@hanleybrand
hanleybrand / Mac imposm install.md
Last active January 13, 2021 20:39
Install imposm on a mac with all dependencies in a vm, with postgress.app for postgis

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 / ct_extended_glasses.zs
Last active February 25, 2020 18:15
WIP ContentTweaker script to create glowing, reinforced and glowing-reinforced variants of the various glass blocks.
#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
#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 February 4, 2020 16:02
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
hanleybrand / storage_admin.py
Created September 29, 2015 13:21
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')
# http://stackoverflow.com/questions/9563935/removing-buttons-links-in-django-admin
def get_actions(self, request):
@hanleybrand
hanleybrand / secrit_flags.yaml
Last active August 23, 2019 22:01
All the secret things in Canvas? *aug 2019
---
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 December 6, 2012 03:56
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 == requests.codes.ok: