Skip to content

Instantly share code, notes, and snippets.

import click
import csv
import json
import requests
from io import StringIO
from datetime import datetime
from kafka import KafkaConsumer
import atexit
def flush(endpoint, datasource_name, token, rows):
rochoa / index.html
Last active Feb 1, 2019
Manhattan buildings by number of floors over the years | CARTO VL
View index.html
<!DOCTYPE html>
<title>Manhattan buildings by number of floors over the years | CARTO VL</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charset="UTF-8">
<!-- Include CARTO VL JS -->
<script src=""></script>
<!-- Include Mapbox GL JS -->
View tile.sql
CREATE OR REPLACE FUNCTION tile (z integer, x integer, y integer, query text) RETURNS TABLE(id int8, geom geometry)
AS $$
sql TEXT;
sql := 'with _conf as (
CDB_XYZ_resolution(' || z || ') as res,
1.0/CDB_XYZ_resolution(' || z || ') as invres,
st_xmin(CDB_XYZ_Extent(' || x || ',' || y || ',' || z ||')) as tile_x,
rochoa /
Last active Mar 31, 2020
CARTO Node.js code test

CARTO Node.js code test


At CARTO, among other things, we render maps, just check this example of Map with countries and USA states.

In order to limit the scope of the challenge, we are gonna use Mapnik and Node.js. Within this repository, we are providing all the pieces you need to reproduce that map. Well, all pieces except the map tile server.

An example of how to create an image with Mapnik:

rochoa / .gitignore
Last active May 16, 2017
node-mapnik variables not used in Grids
View .gitignore

Scaling your API with rate limiters

The following are examples of the four types rate limiters discussed in the accompanying blog post. In the examples below I've used pseudocode-like Ruby, so if you're unfamiliar with Ruby you should be able to easily translate this approach to other languages. Complete examples in Ruby are also provided later in this gist.

In most cases you'll want all these examples to be classes, but I've used simple functions here to keep the code samples brief.

Request rate limiter

This uses a basic token bucket algorithm and relies on the fact that Redis scripts execute atomically. No other operations can run between fetching the count and writing the new count.

rochoa / dot_density.sql
Last active Feb 14, 2017 — forked from stuartlynn/dot_density.sql
View dot_density.sql
-- Source code from
CREATE OR REPLACE FUNCTION cdb_dot_density(geom geometry , no_points Integer, max_iter_per_point Integer DEFAULT 1000)
extent GEOMETRY;
test_point Geometry;
width NUMERIC;
height NUMERIC;
rochoa / .gitignore
Last active Mar 16, 2017
npm shrinkwrap error
rochoa / index.html
Last active Mar 16, 2017
[CARTO] Tangram basic
View index.html
<!doctype html>
Tangram: real-time WebGL rendering for OpenStreetMap
<html lang="en-us">
<meta charset="utf-8">
rochoa / app.js
Last active Aug 2, 2018
[CARTO] basic viewer
View app.js
'use strict';
var DEFAULTS = {
endpoint: '',
sql: 'select * from airbnb_madrid_oct_2015_listings',
cartocss: `#layer['mapnik::geometry_type'=1] {
marker-width: 7;
marker-fill: #EE4D5A;
marker-fill-opacity: 0.9;
marker-line-color: #FFFFFF;
You can’t perform that action at this time.