Skip to content

Instantly share code, notes, and snippets.

View stuartlynn's full-sized avatar

Stuart Lynn stuartlynn

  • Two Sigma
  • Brooklyn
View GitHub Profile
leave location reamain
40729.0 Aberdeen City 63985.0
62516.0 Aberdeenshire 76445.0
20315.0 Adur 16914.0
31809.0 Allerdale 22429.0
44501.0 Amber Valley 29319.0
26511.0 Angus 32747.0
19202.0 Argyll & Bute 29494.0
56936.0 Arun 34193.0
46720.0 Ashfield 20179.0
create or replace function CDB_INTERP_LINEPOINT_test3(geom geometry, start_date timestamp with time zone, end_date timestamp with time zone, points int)
RETURNS TABLE (the_geom geometry, d timestamp with time zone) as $$
DECLARE
t_step numeric;
d_temp timestamp;
line geometry;
@stuartlynn
stuartlynn / index.md
Created June 9, 2016 04:06
cartodb -> 3d prints plan
@stuartlynn
stuartlynn / index.md
Last active June 8, 2016 15:52
Perfect Sales

Perfect Sales

Aim

Given a number of customer locations with a value field attacted can we place N stores to maximise the potential of those clusters?

Procedure

  • Cluster the points using K-Means
  • Take the resulting cluster definitions and find their value weighted centroids
@stuartlynn
stuartlynn / index.sql
Created June 3, 2016 20:07
Snap To Closest
with nearest as (
SELECT DISTINCT ON(b.cartodb_id) b.cartodb_id as id_point, a.cartodb_id as id_road, a.the_geom
FROM stuartlynn.primaryandsecondaryroads a INNER JOIN stuartlynn.taret b
ON ST_DWithin(CDB_LATLNG(b.dest_lat, b.dest_lng), a.the_geom, 1000)
ORDER BY b.cartodb_id, ST_Distance(a.the_geom, b.the_geom)
),
snap as (
select ST_SNAP(CDB_LATLNG(b.origin_lat, b.origin_lng), a.the_geom ,1.01 ) as the_geom,
id_point as cartodb_id
@stuartlynn
stuartlynn / index.html
Last active June 2, 2016 21:16
County Similarity Finder
<html>
<head>
<link rel="stylesheet" href="http://libs.cartocdn.com/cartodb.js/v3/3.15/themes/css/cartodb.css" />
<style>
html, body{
width: 100%;
height:100%;
margin:0px;
padding:0px;
}
@stuartlynn
stuartlynn / index.md
Created May 17, 2016 13:31
Demo Chapin House
update  stuartlynn.chicago_gardens_1 set seg_10 = (
      SELECT * from OBS_GetUSCensusCategory(
        the_geom, 
        'Spielman-Singleton Segments: 10 Clusters')
   )
WITH
@stuartlynn
stuartlynn / index.html
Created May 13, 2016 01:40
mamata multi
This file has been truncated, but you can view the full file.
<!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">
<script>/**
* @license
* Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
* This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
* The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
* The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
@stuartlynn
stuartlynn / index.html
Created May 13, 2016 01:28
mamata multi map
<!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">
<script>(function () {
function resolve() {
document.body.removeAttribute('unresolved');
}
if (window.WebComponents) {
addEventListener('WebComponentsReady', resolve);
@stuartlynn
stuartlynn / index.html
Created May 10, 2016 21:11
Work in progress full demographics legend
<div class='cartodb-legend category'>
<ul>
<ul style='display:inline-block'>
<li>
Hispanic and kids
<ul>
<li> <div class='bullet' style='background: #99C945'></div> Middle Class, Educated, Suburban, Mixed Race </li>
<li> <div class='bullet' style='background: #a3ce57'></div> Low Income on Urban Periphery</li>
<li> <div class='bullet' style='background: #add468'></div> Suburban, Young and Low-income </li>