Skip to content

Instantly share code, notes, and snippets.

@chriswhong
chriswhong / getCurrentView.js
Last active August 29, 2015 14:21
Leaflet initial view helper
//Logs current map center and zoom level for use in map init options
//Use it to find that perfect intial view without having to use trial and error
map.on('dragend',getInit).on('zoomend',getInit);
function getInit() {
var c = map.getCenter();
console.log('center: [' + c.lat + ',' + c.lng + '],\nzoom: ' + map.getZoom());
}
@chriswhong
chriswhong / cartocssmaker.js
Created May 27, 2015 15:26
Torque CartoCSS Maker
//node script for generating complex cartoCSS for torque
//as value increases, duration of marker gets longer,
//radius gets larger, and color moves up the ramp.
var breaks = [0,10,50,100]
var colors = ['#eff3ff','#bdd7e7','#6baed6','#2171b5'];
var data = {
"tableName":"#nepaltrends",
"valueCondition":0,
@chriswhong
chriswhong / sql.txt
Created July 20, 2015 14:08
Gaussian Distribution for Dummy Data in CartoDB
/*
Given a table of census tracts, this query will generate a gaussian distribution of points offset from the tract's centroid.
Based on this example by Paul Ramsey: http://boundlessgeo.com/2014/10/postgis-training-creating-overlays/
*/
WITH tracts AS (
SELECT *, random() AS u1, random() AS u2, 25 AS f, generate_series(1,total_pop/100) FROM chriswhong.nytracts
)
SELECT
<!DOCTYPE html>
<html lang="en">
<head profile="http://www.w3.org/2005/10/profile">
<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 -->
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="./favicon.ico">

##Real-Time Data in CartoDB texasGIS

About Chris: Solutions Engineer, Urbanist, Mapmaker, Open Data Junkie

cwhong@cartodb.com

@chris_whong

@chriswhong
chriswhong / index.html
Created November 13, 2015 05:18
Multiple CartoDB Named Maps on One Leaflet Map
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<link rel="stylesheet" href="http://libs.cartocdn.com/cartodb.js/v3/3.15/themes/css/cartodb.css" />
<style>
#map, html, body {
height:100%;
width:100%;
@chriswhong
chriswhong / alias.txt
Created November 19, 2015 21:59
Create an alias in the terminal to open the current directory in chrome via the local webserver
alias chrome='/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --url "http://localhost/~chriswhong/$(basename $PWD)"'
@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}"
}
}
NYC DOT Live Speed Sensors data:
http://207.251.86.229/nyc-links-cams/LinkSpeedQuery.txt
h/t https://twitter.com/5h15h/status/684116277586100224