Skip to content

Instantly share code, notes, and snippets.

View andrewxhill's full-sized avatar

Andrew W. Hill andrewxhill

View GitHub Profile
@andrewxhill
andrewxhill / index.html
Created November 16, 2014 20:13
ecohack example
<!DOCTYPE html>
<html>
<head>
<title>Animals | CartoDB.js</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<link rel="shortcut icon" href="http://cartodb.com/assets/favicon.ico" />
<style>
html, body, #map {
height: 100%;
let beforeCommute = SetSDK.Context(
notificationTiming: .upon,
eventAction: .exit,
eventState: .place(type: .home),
timeOfDay: .morning
)
SetSDK.register(context: beforeCommute) { event as
// Send new information or an opportunity that will be valuable
let content = UNMutableNotificationContent()
content.title = "Weather Alert!"
// ...
}
@andrewxhill
andrewxhill / rivers.md
Last active April 28, 2017 17:29
Steps used to make map of California rivers
class RideFinderViewController: UIViewController {
...
override func viewDidAppear(_ animated: Bool) {
// this view indicates an intent to go someplace
super.viewDidAppear(animated)
// Get the user's likely destinations using the SetSDK
// For custom control of starting location, see: http://bit.ly/getDestinationV1
class RideFinderViewController: UIViewController, CLLocationManagerDelegate {
let locationManager = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters
locationManager.startUpdatingLocation()
SetSDK.instance.onDeparture(.home) { departure in
// Turn off lights, kill the music, lock the doors
}
// departure subscription
SetSDK.instance.onDeparture(.home) { departure in
// on departure, predict their likely destination
if let destinations = SetSDK.instance.getDestination(fromLocation: departure.location, fromTimestamp: departure.date), let destination = destinations.first {
// Process the top destination predictions
}
}
@andrewxhill
andrewxhill / pluto_reverse_geocode.sql
Created August 14, 2013 15:59
PLUTO reverse geocode SQL
CREATE TYPE pluto_reverse_geocode_result AS (address text, ownername text,distance float);
CREATE OR REPLACE FUNCTION pluto_reverse_geocode(float,float,int) RETURNS SETOF pluto_reverse_geocode_result
AS '
WITH subq as (SELECT address,the_geom,ownername
FROM nyc_mappluto_13v1
ORDER BY the_geom <-> CDB_LatLng($1,$2) LIMIT 20)
SELECT address,ownername,
ST_Distance(the_geom::geography, CDB_LatLng($1,$2)::geography) as distance
FROM subq
WHERE ST_Distance(the_geom::geography, CDB_LatLng($1,$2)::geography) < $3
@andrewxhill
andrewxhill / index.html
Last active March 22, 2017 13:07
Use Leaflet Draw to filter and style a CartoDB layer
<!DOCTYPE html>
<html>
<head>
<title>Leaflet.draw drawing and editing tools</title>
<link
rel="stylesheet"
href="http://cdn.leafletjs.com/leaflet-0.7/leaflet.css"
/>
<link rel="stylesheet" href="http://libs.cartocdn.com/cartodb.js/v3/themes/css/cartodb.css" />
<link