Skip to content

Instantly share code, notes, and snippets.

View mheadd's full-sized avatar

Mark Headd mheadd

View GitHub Profile
@mheadd
mheadd / hello.cbl
Last active November 27, 2019 02:34
Hello world - Node.js, Express and COBOL
IDENTIFICATION DIVISION.
PROGRAM-ID. CLIOPTIONS.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 argv pic x(100) value spaces.
PROCEDURE DIVISION.
ACCEPT argv FROM argument-value
@mheadd
mheadd / microcivic.json
Last active January 21, 2016 14:55
A JSON format to describe civic data resources & microservices
{
"name": "phl-property-tax-balances",
"keywords": ["tax", "property", "delinquent", "deadbeat"],
"license": "CC0",
"sources": [{
"name": "City of Philadelphia",
"web": "http://opendataphilly.org",
"email": "[email protected]"
}],
"resources": [{
{
"result": [
{
"isForDemo": false,
"hostedACA": true,
"display": "BUTTSCO",
"enabled": true,
"serviceProviderCode": "BUTTSCO",
"name": "BUTTSCO"
},
location_id street_number street_name street_suffix permit_type_code status
760148 00271 RIPKA ST NEWCON COMPLETED
760148 00271 RIPKA ST ENTIRE ACTIVE
760148 00271 RIPKA ST NEWIN EXPIRED
760148 00271 RIPKA ST NEWIN ACTIVE
760148 00271 RIPKA ST EZPLUM ACTIVE
761757 00271 RIPKA ST EZELEC ACTIVE
760148 00271 RIPKA ST WARMA ACTIVE
761757 00271 RIPKA ST EZPLUM COMPLETED

Using Chris Whong's JSON proxy for daycare data, create a CSV file with details of violations for a specific location. Assumes jq is installed.

~$ curl -s http://daycareproxy.herokuapp.com/id/DC20687 \
| jq '.inspections[] | .date as $date | .violations[] | .date |=  $date | .id = "DC20687" | [.id,.date,.status,.subSection,.category,.summary] | @csv' \
| sed 's/\\r\\n//g;s/\\//g;s/""/"/g;s/  //g' \
> > violations.csv

Produces a violations.csv file with the following contents.

{
"result": [
{
"isForDemo": false,
"hostedACA": true,
"display": "BUTTSCO",
"enabled": true,
"serviceProviderCode": "BUTTSCO",
"name": "BUTTSCO"
},
@mheadd
mheadd / Onondaga_County_Restaurant_Inspections_clean.csv
Last active November 12, 2015 20:19
Chunked Transfer Encoding Example
We can make this file beautiful and searchable if this error is corrected: Unclosed quoted field in line 3.
FACILITY,ADDRESS,LAST_INSPECTED,VIOLATIONS,TOTAL_NUM_CRITICAL_VIOLATIONS,TOTAL_NUM_CRIT_NOT_CORRECTED,TOTAL_NUM_NONCRITICAL_VIOLATIONS,DESCRIPTION,LOCAL_HEALTH_DEPARTMENT,COUNTY,FACILITY_ADDRESS,CITY,ZIP_CODE,NYSDOH_GAZETTEER_1980,MUNICIPALITY,OPERATION_NAME,PERMIT_EXPIRATION_DATE,PERMITTED_DBA,PERMITTED_CORP_NAME,PERM_OPERATOR_LAST_NAME,PERM_OPERATOR_FIRST_NAME,NYS_HEALTH_OPERATION_ID,INSPECTION_TYPE,INSPECTOR_ID,INSPECTION_COMMENTS,FOOD_SERVICE_FACILITY_STATE,Location1
Abbotts Frozen Custard ,"4282 Fay ROAD, Syracuse",04/08/2015,No violations found.,0,0,0,Food Service Establishment - Ice Cream Store,Onondaga County,ONONDAGA,4282 Fay ROAD,Syracuse,13219 ,336100,ONONDAGA,Abbotts Frozen Custard,01/31/2016,,"Dixon & Knowles, LLC",Dixon,Douglas,535612,Inspection,,Conditions satisfactory to operate at this time.,NY,"(43.027484, -76.217622)"
Abbott's Village Tavern ,"6 EAST Main STREET, Marcellus",05/01/2015,"Item 8D- Single service items reused, improperly stored, dispensed, not
@mheadd
mheadd / permit-lookup.php
Created October 23, 2015 17:10
A simple Tropo app to lookup permit status using an Open Permit API
<?php
// Open permit API
define("URL_BASE", "http://mdc.openpermit.org/op/permits");
// Simple utility method to make API call.
function getPermitData($num) {
$url = URL_BASE . "?number=" . $num;
$permit_data = file_get_contents($url);
return json_decode($permit_data);
@mheadd
mheadd / get-data.md
Last active October 9, 2015 13:58
Getting vacancy licenses from the Philadelphia L&I API

Download date on vacancy licesnses by month (the API limits resonses to 1000 records per request). For example:

curl -s 'http://services.phila.gov/PhillyApi/Data/v1.0/licenses?$filter=(issued_datetime%20gt%20datetime%272015-01-01%27)%20and%20(issued_datetime%20lt%20datetime%272015-01-31%27)%20and%20(license_type_name%20eq%20%27RESIDENTIAL%20RES_VACANT%27)&$expand=locations&$format=json'

This will return a JSON response like this:

{