Skip to content

Instantly share code, notes, and snippets.

WITH a as (
select zoom('!scale_denominator!') as current_zoom
)
SELECT the_geom_webmercator from roads, a where current_zoom < 8 AND type='Interstate'
UNION
SELECT the_geom_webmercator from roads, a where current_zoom >= 8 AND current_zoom < 12 AND (type='Interstate' OR type='US')
UNION
SELECT the_geom_webmercator from roads where current_zoom >= 12

Backbone basics

4 elements to indetify

  • model / view
  • collection / view collection

model

@javisantana
javisantana / cartodb_yosemite.md
Created December 9, 2014 14:08
installing cartodb on OSX yosemite

cartodb installation on yosemite

if you get the following when you are running bundle on OSX Yosemite:

An error occurred while installing nokogiri (1.6.0), and Bundler cannot continue.
Make sure that `gem install nokogiri -v '1.6.0'` succeeds before bundling.
@javisantana
javisantana / index.html
Created January 16, 2015 14:41
retina_basemap_cartodb.html
<!DOCTYPE html>
<html>
<head>
<title>Leaflet example | 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%;
@javisantana
javisantana / index.html
Created January 27, 2015 15:44
bing maps in cartodb
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Bing Maps + CartoDB.js</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<style>
html, body, #myMap{
height: 100%;
padding: 0;
margin: 0;
vizjson({
"version": "0.1.0",
"title": "fake",
"scrollwheel": true,
"zoom": 3,
"bounds": [
[
-44.46515101351962,
-133.06640625
],
import requests
import json
import random
import urllib
class MapInstance(object):
def __init__(self, definition, url, headers=None):
self.url = url
self.definition = definition
select _postgis_stats('tm_world_borders_s_11'::regclass ,'the_geom');
-[ RECORD 1 ]--+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
_postgis_stats | {"ndims":2,"size":[6,7],"extent":{"min":[-181.8,-90.8679],"max":[181.8,84.4381]},"table_features":246,"sample_features":246,"not_null_features":246,"histogram_features":246,"histogram_cells":42,"cells_covered":246}
test_postgis=# select count(*) from sigpac_47_valladolid_parfe;
count
--------
342691
test_postgis=# select sum(st_memsize(the_geom_webmercator)) from sigpac_47_valladolid_parfe;
sum
-----------
254827296
(1 row)
@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