Skip to content

Instantly share code, notes, and snippets.

View palewire's full-sized avatar

Ben Welsh palewire

View GitHub Profile
@palewire
palewire / clean.sh
Last active March 9, 2021 19:53
Repair and overwrite all shapefiles in the current directory using mapshaper's -clean option
#!/bin/sh
for FILEPATH in ./*.shp; do
FILENAME="$(echo "$FILEPATH" | rev | cut -d "/" -f1 | rev)";
echo "Cleaning $FILENAME";
mapshaper $FILEPATH -clean -o force $FILEPATH;
done
@palewire
palewire / .gitignore
Last active December 2, 2018 01:31
1890 Georgia map
*.csv#
@palewire
palewire / download.py
Last active October 28, 2018 22:14
Download all members of Congress from ProPublica's Represent API
import csv
from congress import Congress
REPRESENT_API_KEY = '<API KEY>'
congress = Congress(REPRESENT_API_KEY)
house = list(congress.members.filter("house")[0]['members'])
reps = [m for m in house if m['title'] == 'Representative']
in_office = [m for m in reps if m['in_office'] is True]
outpath = "members.csv"
print("Writing {} members to {}".format(len(in_office), outpath))
@palewire
palewire / performance.json
Last active October 11, 2018 15:02
the-ichiro-bet.json
{
"last_updated": "2018-10-11 07:00:38.708227",
"mariners_stats": {
"mariners_games_played": 162
},
"steamer": 44,
"thebat": 0,
"zips": 44,
"depthcharts": 0,
"ichiro_totals": {
@palewire
palewire / notebook.ipynb
Last active August 3, 2018 01:37
pandas-string-slice-example
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@palewire
palewire / inglewood-lunches.geojson
Last active August 10, 2019 23:23
@LATdatadesk's Inglewood lunch inventory
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@palewire
palewire / notebook.ipynb
Last active July 12, 2025 07:35
Rotating proxy scraper example
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@palewire
palewire / README.md
Last active August 6, 2018 12:58
Simple COPY examples

Simple COPY examples

Two simple examples of quickly loading data into PostgreSQL with the COPY command.

  • First, loading data to a database on your own computer in localhost.sh
  • Second, loading data to a database hosted on the Internet in cloud.sh

Much more sophisticated stuff is possible. Refer to the official docs and consider adopting a wrapper like django-postgres-copy for more complicated tasks.

@palewire
palewire / pg_to_rds.sh
Last active July 16, 2018 19:45
Migrate PostgreSQL databases to Amazon RDS
pg_dump -Fc --no-acl --no-owner -h localhost -U <YOUR LOCAL DATABASE USER> <YOUR LOCAL DATABASE NAME> > <YOUR LOCAL DATABASE NAME>.dump;
pg_restore -v -h <YOUR RDS IP ADDRESS> -U <YOUR RDS DATABASE USER> -d <YOUR RDS DATABASE NAME> <YOUR LOCAL DATABASE NAME>.dump;
@palewire
palewire / README.md
Created May 7, 2018 04:15
Iowa net electricity generation by source