Skip to content

Instantly share code, notes, and snippets.


Javier de la Torre jatorre

View GitHub Profile
View index.html
<!DOCTYPE html>
<meta charset='utf-8' />
<title>Load a public CARTO Builder URL dynamically</title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script src=''></script>
<link href='' rel='stylesheet' />
body { margin:0; padding:0; }
View index.html
<!DOCTYPE html>
<meta charset='utf-8' />
<title>OpenLayers – Vector tiles – Points aggregation | CARTO</title>
<link rel="stylesheet" href="" type="text/css">
<script src=""></script>
<script src=""></script>
jatorre /
Created Apr 24, 2011
A python script to detect encoding and SRID of a shapefile GUESSING its best
from chardet.universaldetector import UniversalDetector
import os.path
import sys
import dbfUtils
import sys
from osgeo import osr
from urllib import urlencode
from urllib2 import urlopen
import json
jatorre / carto-basemap.json
Last active Jun 8, 2017
Testing CARTO Vector Tiles
View carto-basemap.json
"tiles": ["{z}/{x}/{y}.vt?api_key=de0f3965167a84e25fb5573409f071e7406619ef",
"name": "CARTO Map Tiles",
"format": "pbf",
"basename": "v3.5.mbtiles",
"id": "openmaptiles",
View index.html
<!DOCTYPE html>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<link rel="stylesheet" href="">
<link rel="stylesheet" href="">
jatorre / gist:3892665
Created Oct 15, 2012
How to do many updates in a single query WAY faster
View gist:3892665
UPDATE counties_results o SET pres_dem_pct = n.pres_dem_pct, pres_gop_pct = n.pres_gop_pct,
pres_oth_pct = n.pres_oth_pct, pres_pctrpt = n.pres_pctrpt
(48.51, 39.69, 11.8, 100, 'AK', '02000'),
(51.65, 41.67, 6.68, 100 , 'AL' , '01001' ),
(52.14, 42.4, 5.46, 100 , 'AL' , '01003' ),
(51.94, 42.24, 5.82, 100 , 'AL' , '01005' ),
(60.28, 34.95, 4.76, 100 , 'AL' , '01007' ),
(53.19, 42.04, 4.77, 100 , 'AL' , '01009' ),
(45.07, 50.85, 4.08, 100 , 'AL' , '01011' ),
jatorre / gist:7401056
Created Nov 10, 2013
Removing the requirement for xml support on resolving tables function
View gist:7401056
-- Return an array of table names scanned by a given query
-- Requires PostgreSQL 9.x+
RETURNS name[]
AS $$
exp JSON;
tables NAME[];
View gist:7336704
WITH summary_groups as(
WITH summary as (
select (row_number() over (order by time asc nulls last)+1)/2 as rownum,time
from sensor_log_2013_10_27_12_01
order by time asc)
max(time) OVER(PARTITION BY rownum) -
min(time) OVER(PARTITION BY rownum) diff
FROM summary)
jatorre / gist:7210438
Created Oct 29, 2013
Geocoder/Reverse geocoder inside SQL
View gist:7210438
CREATE TYPE geocode_response AS (match_level text, latitude float, longitude float, address text, the_geom geometry);
CREATE OR REPLACE FUNCTION cdb_geocode(text) RETURNS SETOF geocode_response
token text :='xxxx';
app_id text :='xxxx';
RETURN QUERY WITH geocode_response AS (
SELECT status, content_type,
content::json->'Response'->'View'->0->'Result'->0 as geocode_result
View gist:6623354
curl '' -H 'Pragma: no-cache' -H 'Origin:' -H 'Accept-Encoding: gzip,deflate,sdch' -H 'Host:' -H 'Accept-Language: en-US,en;q=0.8' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.37 Safari/537.36' -H 'Content-Type: application/json' -H 'Accept: application/json, text/javascript, */*; q=0.01' -H 'Cache-Control: no-cache' -H 'Referer:' -H 'Connection: keep-alive' --data-binary '{"version":"1.0.1","stat_tag":"f8515466-04da-11e3-ad81-938373fbfdcf","layers":[{"type":"cartodb","options":{"sql":"Select * FROM wahlen_by_2013","cartocss":"#wahlen_by_2013{ polygon-fill: #dedcd0; line-opacity: 1; polygon-comp-op: multiply; line-width: .5; line-color: #fff; polygon-opacity: 0;} ","cartocss_version":"2.1.0","interactivity":["cartodb_id"]}},{"type":"cartodb","options":{"sql":"Select * FROM wahle
You can’t perform that action at this time.