Skip to content

Instantly share code, notes, and snippets.

View jsanz's full-sized avatar
🗺️
Mapping

Jorge Sanz jsanz

🗺️
Mapping
View GitHub Profile
@bruth
bruth / README.md
Last active November 23, 2022 21:54
Postgres push notification

Postgres push triggers

Watch a table for changes and push a notification with a payload describing the change.

Example

In the Postgres shell:

-- Create the functions
@pramsey
pramsey / cdb_delayed_invalidate.sql
Created November 12, 2015 17:59
Delayed Invalidation Trigger
CREATE OR REPLACE FUNCTION public.CDB_Delayed_TableMetadata_Trigger()
RETURNS trigger AS $$
DECLARE upd timestamp;
BEGIN
IF TG_RELID = 'cartodb.CDB_TableMetadata'::regclass::oid THEN
RETURN NULL;
END IF;
SELECT updated_at INTO upd
FROM cartodb.CDB_TableMetadata WHERE tabname = TG_RELID::regclass;
IF upd IS NOT NULL AND (now() - upd) > '20m'::interval THEN
@andy-esch
andy-esch / README.md
Last active September 16, 2016 03:59
CartoCamp Elections

Election Mapping Bonanza

With Mamata Akella (@mamataakella) and Andy Eschbacher (@MrEPhysics)

Presentations here

Part 1: Importing our Datasets

We are going to be using a dataset of 2012 Presidential Election Results from Data.gov. To make it easier tonight, we made a simplified version.

@andrewxhill
andrewxhill / harvest_a_game.ipynb
Last active September 1, 2015 12:38
Use Goldberry to harvest a single basketball game and push it to CartoDB. WARNING This will pull ~2-3,000,000 points, so probably not for your typical free CartoDB account :)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@javisantana
javisantana / speed.sql
Created August 12, 2015 11:05
speed from a track table
WITH deltas as (
SELECT
st_distance(the_geom::geography, lag(the_geom::geography, 1) over(order by timestamp)) as ddist,
timestamp - lag(timestamp, 1) over(order by timestamp) as dt
from out_2 offset 1000
)
select avg(ddist/dt) as speed from deltas
@auremoser
auremoser / hasadna.md
Last active August 29, 2015 14:24
Hasadna Workshop

Hasadna: Pollution Mapping + CartoDB

Aurelia Moser, CartoDB Workshop - Hasadna, IL

July 6, 2015

Find this document here:

  • Stackedit:
@andrewxhill
andrewxhill / change_log.sql
Last active August 29, 2015 14:23
Create a table to store changes from any of your tables in a log table.
--
-- Create a table in your CartoDB editor called 'version_control'
-- Run the following SQL in your editor to create the needed columns
--
ALTER TABLE version_control ADD COLUMN data json;
ALTER TABLE version_control ADD COLUMN source_id integer;
ALTER TABLE version_control ADD COLUMN table_name text;
ALTER TABLE version_control ADD COLUMN tg_op text;
@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,
@danicarrion
danicarrion / README.md
Last active January 12, 2016 15:08
Script that reads from a CartoDB table, geocode each row with Google's geocoder and put them back into CartoDB

This script reads a table fom CartoDB using the SQL API, geocodes one of its fields using Google's geocoder and updates the data on CartoDB.

If no valid credentials are provided for Google's geocoder, the free limits will apply.

TODO: multithread support

@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());
}