Skip to content

Instantly share code, notes, and snippets.

@bahoo
bahoo / CurvedLine.js
Created June 7, 2020 20:38
CurvedLine.js -- curved lines in Leaflet.
// Adapted from https://medium.com/@ryancatalani/creating-consistently-curved-lines-on-leaflet-b59bc03fa9dc
// Drop-in replacement for Leaflet.curve https://github.com/elfalem/Leaflet.curve
// To auto-calculate the midpoint for you and ease code integration a bit.
// Have fun and defund the police 👍
L.CurvedLine = L.Curve.extend({
_setPath: function(path){
@bahoo
bahoo / fixing_extra_white_space_headers_python_requests_urllib3.py
Created August 30, 2019 22:24
Monkeypatch for urllib3 + Python requests dealing with extra trailing white space in HTTP header names
# Python requests and urllib3 ( and PyQuery, and other tools that build on requests )
# will hang if it encounters poorly-formed HTTP headers with trailing white space
# in the header field names.
# this is a deliberate choice on the authors' part,
# in line with the RFC https://greenbytes.de/tech/webdav/rfc7230.html#header.fields
# presumably because extra janky white space can create a security risk.
# the right thing to do in such a situation is to contact the adminstrator
# of the web site and get them to fix this condition,
@bahoo
bahoo / seattle-neighborhoods.txt
Created January 31, 2018 01:27
"An unofficial delineation of neighborhood boundaries used by the City Clerks Office"; per https://data.seattle.gov/dataset/Neighborhoods/2mbt-aqqx/data?pane=manage
Uncategorized:
Bitter Lake
Broadview
Bryant
Crown Hill
Fremont
Georgetown
Green Lake
Greenwood
Harbor Island
@bahoo
bahoo / get_django_schema_from_shapefile.py
Created June 19, 2017 23:52
Turn a shapefile into a Django model / schema quickly.
from django.conf import settings
from django.core.management.base import BaseCommand, CommandError
from dateutil import parser
import os, untangle
class Command(BaseCommand):
ATTRIBUTE_TYPES = {
'OID': 'IntegerField',
@bahoo
bahoo / governors.csv
Last active June 2, 2017 21:43
US Governors Contact Information
We can make this file beautiful and searchable if this error is corrected: It looks like row 9 should actually have 11 columns, instead of 1. in line 8.
state,first_name,last_name,address1,address2,city,state_abbr,zip,phone,fax,url
Alabama,Kay,Ivey,State Capitol,600 Dexter Avenue,Montgomery,AL,36130-2751,334-242-7100,334-353-0004,http://www.governor.alabama.gov/
Alaska,Bill,Walker,State Capitol,P.O. Box 110001,Juneau,AK,99811-0001,907-465-3500,907-465-3532,http://gov.state.ak.us/
American Samoa,Lolo Matalasi,Moliga,Executive Office Building,Third Floor,"Utulei, Pago Pago",AS,96799,011-684-633-4116,011-684-633-2269,https://www.americansamoa.gov/office-of-the-governor
Arizona,Doug,Ducey,State Capitol,1700 West Washington,Phoenix,AZ,85007,602-542-4331,602-542-7601,http://www.governor.state.az.us/
Arkansas,Asa,Hutchinson,State Capitol,Room 250,Little Rock,AR,72201,501-682-2345,501-682-1382,http://www.arkansas.gov/governor/
California,Edmund,Brown,State Capitol,Sute 1173,Sacramento,CA,95814,916-445-2841,916-558-3160,http://gov.ca.gov/
Colorado,John,Hickenlooper,136 State Capitol,,Denver,CO,80203-1792,303-866-2471,303-866-2003,http://www.colorado.gov/governor/
Conn
@bahoo
bahoo / fields.py
Created March 12, 2017 02:59
Simplified Geometry Fields for Django
# usage:
# from django.contrib.gis.db import models
# from fields import CachedMultiPolygonField
#
#
# class MyGeography(models.model):
# name = models.CharField(max_length=128)
# geom = models.MultiPolygonField(srid=4326, null=True, blank=True)
# geom_cache = CachedMultiPolygonField(field_name='geom', simplify=0.0002, precision=4)
@bahoo
bahoo / compress-geodjango-polygons.py
Last active May 6, 2020 07:58
Compression / low bandwidth / lower file size tricks with shapefiles / GeoDjango / GIS / Django
# put lots of SEO friendly terms in the title for Googlers / Stack Overflow crawlers like myself...
# basically, tricks to make pulling down shapefiles much smaller file size, ergo faster web sites
# control test was 1.2MB of GeoJSON for three polygon shapes...
from django.contrib.gis.db.models.functions import AsGeoJSON
from django.db.models.expressions import RawSQL
from django.views.generic import TemplateView
from .models import City
@bahoo
bahoo / export-users-from-slack-channel.py
Created February 2, 2017 21:28
Export users (first name, last name, email address) from a given Slack channel
import requests
SLACK_API_TOKEN = "xoxo-asdfghjkl..." # get one from https://api.slack.com/docs/oauth-test-tokens
CHANNEL_NAME = "general"
channel_list = requests.get('https://slack.com/api/channels.list?token=%s' % SLACK_API_TOKEN).json()['channels']
channel = filter(lambda c: c['name'] == CHANNEL_NAME, channel_list)[0]
channel_info = requests.get('https://slack.com/api/channels.info?token=%s&channel=%s' % (SLACK_API_TOKEN, channel['id'])).json()['channel']
members = channel_info['members']
@bahoo
bahoo / fabfile.py
Created December 8, 2016 03:54
AWS Application Load Balancer-friendly Fabric Deploys using boto3
from awsfabrictasks.ec2.api import *
from fabric.api import *
from functools import wraps
import boto3
import time
def aws_hosts(load_balancers):
@bahoo
bahoo / gofundme.py
Created July 2, 2016 00:31
Scrape fundraising progress from GoFundMe
# do:
# pip install beautifulsoup4 requests
# then this:
import requests
from bs4 import BeautifulSoup
# this cookie triggers / forces its new layout (as of July 1 2016)
headers = {
'Cookie': 'flow=%7B%22DONATION%22%3A%22d_ad_v2a%22%7D'