Skip to content

Instantly share code, notes, and snippets.

{
"version": "2",
"header": {
"title": "NYC 311 Data",
"description": "The last 3 million NYC 311 complaints",
"navigation": [
{
"label": "Download",
"url": ""
}
{
"version": "2",
"header": {
"title": "NYC 311 Data",
"description": "The last 3 million NYC 311 complaints",
"navigation": [
{
"label": "Download",
"url": ""
}
@chriswhong
chriswhong / boro.sql
Created January 29, 2016 20:05
SQL to convert geo_id2 field from Census ACS data to boroct201 from NYCDCP's bytes of the big apple--
--Replace county FIPS code with NYC boro code, concatenate with 6-digit tract ID
SELECT
*,
(
(
CASE WHEN (substring(geo_id2,4,2) = '61')
THEN '1'
WHEN (substring(geo_id2,4,2) = '05')
THEN '2'
@chriswhong
chriswhong / index.html
Last active April 18, 2016 14:51
A simple bootstrap form
<!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">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>Bootstrap 101 Template</title>
<!-- Bootstrap -->
@chriswhong
chriswhong / statenisland.SQL
Created May 17, 2016 21:15
Moving Staten Island to the left of NYC
select geom from nybb WHERE borocode < 5
UNION ALL SELECT ST_Translate(geom,.05,.2,4326) as geom FROM nybb WHERE borocode=5
@chriswhong
chriswhong / sql.txt
Created December 29, 2015 20:27
SQL to Liberate Point Location Data from Proprietary Socrata "Location" Column (PostGIS)
Socrata datasets often include a column of type 'Location', which may include a WGS84 latitude and longitude in parenthesis, separated by a comma. `(latitude,longitude)` This format does not lend itself well to mapping the point data, as most mapping software is expecting separate attribute columns for latitude and longitude. The SQL below is meant for use in a PostGIS database such as CartoDB. It parses the latitude and longitude from the a Socrata location column, and creates a point geometry in `the_geom` using PostGIS' `ST_geomfromtext()` function.
With this function you can liberate point location data from Socrata's unconventional format, and put it to use in maps!
UPDATE tablename
SET the_geom =
ST_setsrid(
ST_geomfromtext(
concat(
'POINT(',
@chriswhong
chriswhong / readme.md
Created October 8, 2016 04:15
CartoDB in Docker Container https issues

We were hosting a site on github pages that needed to use cartodb.js and maps from our self-hosted cartodb server. Because github pages serves over https, there were mixed content errors when doing api calls to cartodb over http.

Adding ssl certificates to the nginx service on the docker host machine worked fine, but because the https traffic hitting nginx is just proxied to the cartodb services that are still running on http internally, the cartodb server is embedding http urls in some of its resources. This will lead to mixed content errors when using the cartodb app.

2 things had to be done to fix it:

  1. Edit cartodb/app/models/user/user_decorator.rb line 100, replace base_url: public_url, with base_url: public_url.sub('http','https'),

This will update the user_data.base_urlglobal which cdb.js uses to build many of the api calls.

@chriswhong
chriswhong / data.json
Created December 7, 2016 19:02
Finding Data in Tableau Public Network Traffic
[
{
"sheetName": "FAR Part & Type of Contract",
"layoutId": "3447568417489532966",
"allowSubscriptions": true,
"allowSubscribeOnDataPresent": true,
"worldUpdate": {
"hyc": {
"ABX": "render-mode-client",
"res": {

#Using NYC geospport linux shared library from Ubuntu 16.04

I have been trying to understand more about geosupport, specifically geosupport desktop edition for linux which contains a linux .so shared library. I would like to eventually write node.js bindings for it so that I can write geocoding scripts that don't require a ton of network traffic.

I am a C noob and this was my first time messing with C and gcc on linux. I was able to write and compile a simple C program that calls the Geosupport shared library with hard-coded arguments.

##What is geosupport?

"Geosupport is a data processing system originally designed to run on IBM mainframes to support geographic processing needs common to New York City agencies." Basically, it's an NYC-specific geocoder released by the NYC department of city planning. It does many things, but at its simplest it can take human-readable address fields and return a point coordinate.

@chriswhong
chriswhong / chunk.sh
Last active March 10, 2017 18:06
Chunk a csv into many files
#!/bin/bash
FILENAME=cpdb_spending.csv
HDR=$(head -1 $FILENAME) # Pick up CSV header line to apply to each file
split -l 200000 $FILENAME xyz # Split the file into chunks of 20 lines each
n=1
for f in xyz* # Go through all newly created chunks
do
if [n -gt 1]
then
echo $HDR > Part${n}.csv # Write out header to new file called "Part(n)"