Skip to content

Instantly share code, notes, and snippets.

View mheadd's full-sized avatar

Mark Headd mheadd

View GitHub Profile
@mheadd
mheadd / data.sh
Created August 29, 2014 18:48
jq recipe to fetch Healthy Corner Store Locations in Philadelphia
echo 'x_coord,y_coord,name' > my-file.csv
curl -s "http://gis.phila.gov/arcgis/rest/services/PhilaGov/Healthy_Corner_Stores/MapServer/0/query?where=1%3D1&text=&objectIds=&time=&geometry=&geometryType=esriGeometryEnvelope&inSR=&spatialRel=esriSpatialRelIntersects&relationParam=&outFields=&returnGeometry=true&maxAllowableOffset=&geometryPrecision=&outSR=&returnIdsOnly=false&returnCountOnly=false&orderByFields=&groupByFieldsForStatistics=&outStatistics=&returnZ=false&returnM=false&gdbVersion=&returnDistinctValues=false&f=pjson" \
| jq .features[] \
| jq '[.geometry.x, .geometry.y, .attributes.OFFICIAL_S]' \
| jq @csv \
| sed 's/\\//g;s/""/"/g' \
>> my-file.csv
@mheadd
mheadd / civic-id-example.html
Last active August 29, 2015 14:05
An example showing the Civic ID process using jQuery.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<link rel="shortcut icon" href="../../assets/ico/favicon.ico">
@mheadd
mheadd / awesome-civic-reading.md
Last active August 29, 2015 14:05
Some great recent articles / blog posts on civic technology

The Three Levers of Civic Engagement

by Anthea Watson Strong

Over time, I have come to believe that our inability to attract mass usage for our products is, in part, due to a willful ignorance of how users are motivated to civic action. To build the technologies that will transform government and governance, we need to do a better job of designing and building tools for real world users.

Read more.

Let’s build the road network of civic tech.

by Eric Hysen

...let’s stop focusing on the next killer app, but instead on building healthy ecosystems.

@mheadd
mheadd / lives.sh
Last active September 12, 2016 10:02
Shell script to convert CivicData.com JSON to LIVES compliant CSV
##!/bin/bash
URL_BASE="http://www.civicdata.com/api/action/datastore_search_sql?sql=SELECT%20*%20from%20%22"
BUSINESSES_SQL="c8a749e9-dee3-4259-bdb4-7c3e45e0867e"
INSPECTIONS_SQL="19426f05-1814-4447-b63b-23c33b3706a7"
VIOLATIONS_SQL="f230b8d9-5605-422c-a2eb-dac203f62edb"
URL_SUFFIX="%22"
# inspections.csv
echo "business_id,score,date,description,type" > data/inspections.csv
{
"page": {
"hasmore": true,
"limit": 25,
"offset": 0
},
"status": 200,
"result": [
{
"value": "14CAP-00000-00082",
@mheadd
mheadd / links.md
Last active August 29, 2015 14:01
Summer of Open Source: Intro to Git/GitHub Links
@mheadd
mheadd / dataset-management.md
Last active October 12, 2023 07:53
Sample API calls for creating, updating and deleting things in CKAN via the CKAN API.

Get package list

~$ curl http://www.civicdata.com/api/action/package_list

Get package details

~$ curl http://www.civicdata.com/api/action/package_show?id={package_id}

Upload a file to storage

~$ curl http://www.civicdata.com/api/storage/auth/form/testdata/test.csv -H "Authorization: <API-KEY>"
@mheadd
mheadd / Samples.md
Last active August 29, 2015 14:01
Some URLs that can be used to query NYPD Vehicle Crash Data on CivicData.io

Accidents with the greatest number of persons injured in Manhattan (top 10 in descending order).

http://www.civicdata.io/api/action/datastore_search_sql?sql=SELECT%20*%20from%20%22036fcc27-5b0a-401c-aca5-3de5b90143dc%22%20ORDER%20BY%20%22PersonsInjured%22%20DESC%20LIMIT%2010

Total number of accidents in Queens where a cyclist was injured.

http://www.civicdata.io/api/action/datastore_search_sql?sql=SELECT%20COUNT(*)%20from%20%227d6dd1e8-0f86-48c9-80c4-fd0c88a58b3b%22%20WHERE%20%22CyclistsInjured%22%20%3E%200

Total number of pedestrians killed in accidents in Brooklyn.

@mheadd
mheadd / index.html
Last active February 23, 2017 17:53
Template for Bootstrap
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<link rel="shortcut icon" href="../../assets/ico/favicon.ico">
@mheadd
mheadd / bike-share-top-100.sh
Created April 22, 2014 19:20
Get the top 100 NYC bike share riders from July, 2013.
curl -s "http://www.civicdata.com/api/action/datastore_search_sql?sql=SELECT%20*%20from%20%229dd48bd2-fa77-43bb-a433-1227b3a17623%22%20ORDER%20BY%20tripduration%20DESC%20LIMIT%20100" \
| sed 's/birth year/birth_year/g;s/start station name/start_station_name/g;s/end station name/end_station_name/g' \
| jq .result.records[] \
| jq '[.tripduration, .birth_year, .gender, .start_station_name, .end_station_name]' \
| jq @csv \
| sed 's/\\//g;s/""/"/g'