Skip to content

Instantly share code, notes, and snippets.

View hanleybrand's full-sized avatar

Peter Hanley hanleybrand

View GitHub Profile
@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:
#!/usr/bin/env python
"""Command line script to convert a file, usually an image, into a data URI
for use on the web."""
import base64
import mimetypes
import os
import sys
(function() {
var s=document.createElement('script');
s.setAttribute('src','https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js');
if(typeof jQuery!='undefined') {
var msg='This page already using jQuery v' + jQuery.fn.jquery;
} else {
document.getElementsByTagName('head')[0].appendChild(s);
var msg='This page is now jQuerified'
}
@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 / 1.5.1.json
Created May 1, 2013 21:54
So this was one attempt at adding a mod to the new launcher - directory structure was like this: versions/ | --1.5.1-modloader --1.5.1-modloader.jar --1.5.1-modloader.json --1.5.1.jar --1.5.1-natives/ | ----*lib* ---ModLoader/ | -----*.class
{
"id": "1.5.1",
"time": "Apr 28, 2013 3:09:12 PM",
"releaseTime": "Mar 20, 2013 12:00:00 PM",
"type": "release",
"processArguments": "legacy",
"libraries": [
{
"name" : "net.minecraft.src.ModLoader",
// is this the directory the files are in?
@hanleybrand
hanleybrand / typogrid.css
Created May 16, 2013 15:15
made with http://www.gridlover.net Heading 1 Font size 68px 3 on the scale Line height 72px One line is 24px, with 3 lines lines total Margin before 24px 1 lines Margin after 48x 2 lines Heading 2 Font size 42px 2 on the scale Line height 48px One line is 24px, with 2 lines lines total Margin before 48px 2 lines Margin after 24px 1 lines Heading…
body {
font-size: 16px;
line-height: 24px;
}
article {
max-width: 944px;
margin: auto;
}
h1 {
font-size: 68px;
"""
Exports Issues from a specified repository to a CSV file
Uses basic authentication (Github username + password) to retrieve Issues
from a repository that username has access to. Supports Github API v3.
"""
import csv
import requests
@hanleybrand
hanleybrand / auth.ldapauth.py
Last active December 22, 2015 12:09
Drop-in log-chatty replacement for mdid3: rooibos/auth/ldapauth.py that also will handle ldap configurations that require a bind user (see settings_local_fragment.py for the additional settings you need to add.
from django.contrib.auth.models import User
from django.conf import settings
import ldap
from baseauth import BaseAuthenticationBackend
import logging
class LdapAuthenticationBackend(BaseAuthenticationBackend):
def authenticate(self, username=None, password=None):
for ldap_auth in settings.LDAP_AUTH:
@hanleybrand
hanleybrand / rooibos-data-admin.py
Last active January 3, 2016 14:59
replacement for rooibos-data-admin.py
from django.contrib import admin
# from django.contrib.sites.models import Site
from models import MetadataStandard, Field, FieldSet, FieldSetField, Record, FieldValue, Collection, Vocabulary, VocabularyTerm
class MetadataStandardAdmin(admin.ModelAdmin):
pass
class FieldAdmin(admin.ModelAdmin):
@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