Skip to content

Instantly share code, notes, and snippets.

View alasarr's full-sized avatar

Alberto Asuero alasarr

View GitHub Profile
@alasarr
alasarr / redshift-concurrency.js
Last active October 6, 2023 17:48
Testing concurrency
const { Pool } = require('pg');
const N_REQUESTS = 32;
const CONCURRENCY = 32;
// Replace these with your Redshift cluster details
const config = {
user: 'XXXX',
host: 'XXX',
@alasarr
alasarr / bigquery-conn-reset.js
Last active March 17, 2023 17:00
BigQuery connection reset bug snippet
const fetch = require('node-fetch')
const tilebelt = require('@mapbox/tilebelt')
const accessToken = ''
const projectId = 'carto-dev-data'
const url = `https://bigquery.googleapis.com/bigquery/v2/projects/${projectId}/queries`
async function runRequest (query) {
const body = {
@alasarr
alasarr / README.md
Last active November 13, 2022 20:24

Create an API using CARTO as a backend

Imagine you're going to build a backend to analyze the air quality of a region in Madrid.

You have the following two public datasets in BigQuery ready to be consumed:

  • cartodb-gcp-backend-data-team.code_test.airquality_stations. It has the info of the airquality stations and its location.

  • cartodb-gcp-backend-data-team.code_test.airquality_measurements. Measurements of each_station:

  • timeinstant: time of the observation.

@alasarr
alasarr / pharmacies.md
Last active September 18, 2022 18:59
Pharmacies H3 Analysis

## 

create or replace table `cartodb-on-gcp-backend-team.deckgl_summit.pharmacies` cluster by geom as 
select * from carto-demo-data.demo_tables.osm_pois_usa where subgroup_name='Pharmacy'
create or replace table `cartodb-on-gcp-backend-team.deckgl_summit.pharmacies_aoi` cluster by geom as 
select * except (geom),st_buffer(geom, 2000) as geom 
@alasarr
alasarr / h3_hex_to_int.sql
Last active June 10, 2022 05:35
Script to transform h3 tables to h3 int
----
-- BIGQUERY
---
-- Switzerland
create table carto-dev-data.public.derived_spatialfeatures_che_h3int_res8_v1_yearly_v2
cluster by h3
as
select cast(concat('0x', h3) as int64) as h3, * except (h3)
from carto-dev-data.public.derived_spatialfeatures_che_h3res8_v1_yearly_v2;
{
"version": 8,
"name": "Dark Matter",
"metadata": {
"maputnik:renderer": "mbgljs"
},
"sources": {
"carto": {
"type": "vector",
"url": "https://tiles.basemaps.cartocdn.com/vector/carto.streets/v1/tiles.json"
@alasarr
alasarr / h3_spatial_features_interpolation.sql
Last active June 8, 2022 11:13
Interpolation experiment to generate an h3 dataset resolution 10
-- Switzerland
create table carto-dev-data.public.derived_spatialfeatures_che_h3res10_v1_yearly_v2_interpolated cluster by h3
as
with q as (
select `carto-un`.carto.H3_TOCHILDREN(h3, 10) as h3_children,* except(h3)
from `carto-dev-data.public.derived_spatialfeatures_che_h3res8_v1_yearly_v2`
)
select h3, population/pow(7,2) as population, female/pow(7,2) as female, male/pow(7,2) as male
from q, unnest(q.h3_children) as h3;
@alasarr
alasarr / geoparquet-bigquery.ipynb
Created March 6, 2022 09:37
GeoParquet BigQuery
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@alasarr
alasarr / tolerance_per_zoom.md
Last active March 4, 2022 10:43 — forked from lukasmartinelli/tolerance_per_zoom.md
ST_Simplify tolerance per zoom level
zoom_level tolerance (m) tolerance (deg)
      0 |  78271.516953125 | 0.703124999902124
      1 | 39135.7584765625 | 0.351562499951062
      2 | 19567.8792382812 | 0.175781249975531
      3 | 9783.93961914062 | 0.0878906249877655
      4 | 4891.96980957031 | 0.0439453124938827
      5 | 2445.98490478516 | 0.0219726562469414
      6 | 1222.99245239258 | 0.0109863281234707

7 | 611.496226196289 | 0.00549316406173534

@alasarr
alasarr / tilejson.json
Last active October 19, 2020 18:23
tilejson
{
"tilejson":"2.2.0",
"tiles":["https://cartocdn-gusc-a.global.ssl.fastly.net/cartovl/api/v1/map/be2b5a9267b5c73a91ba17d11728d756:1560342716956/{z}/{x}/{y}.mvt?api_key=default_public"],
"minzoom": 3,
"maxzoom": 7,
"tilestats":{"layerCount":1,"layers":[{"layer":"429bbc773dcf729a70eaa2897637acd1","count":25648,"adapters":{"aggregation":false,"dates_as_numbers":false}}]}}