Skip to content

Instantly share code, notes, and snippets.

@chriswhong
chriswhong / gist:a4d1e6305ecaf2ad507a
Created November 20, 2015 21:55
Use cartodb.js to add a torque layer from a named map with auth_tokens enabled
var layerSource = {
type: "torque",
options: {
auth_token: '{yourAuthToken}',
user_name: "{yourCartoDBUsername}",
tile_style:"{torqueCartoCSS}",
named_map: {
name: "{namedmap}"
}
}
@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(',
NYC DOT Live Speed Sensors data:
http://207.251.86.229/nyc-links-cams/LinkSpeedQuery.txt
h/t https://twitter.com/5h15h/status/684116277586100224
{
"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 / index.html
Last active August 28, 2019 18:55
Time block charts wth D3
<!DOCTYPE html>
<html class="html">
<head>
<meta charset="UTF-8">
<title>Document</title>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
<style>
.axis text {
font: 10px sans-serif;
@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
Sub Auto_Open()
Dim oToolbar As CommandBar
Dim oButton As CommandBarButton
Dim MyToolbar As String
' Give the toolbar a name
MyToolbar = "Kewl Tools"
On Error Resume Next
' so that it doesn't stop on the next line if the toolbar's already there