Skip to content

Instantly share code, notes, and snippets.

View alrocar's full-sized avatar

alrocar alrocar

View GitHub Profile
@alrocar
alrocar / high quality gif
Last active May 26, 2018 15:13
high-quality-gif
# first create a palette of the portion of the video with more colors
ffmpeg -y -ss 20 -t 3 -i input.mp4 -vf fps=50,scale=640:-1:flags=lanczos,palettegen palette.png
# then use the palette to obtain high quality colors
ffmpeg -i input.mp4 -i palette.png -filter_complex "fps=50,scale=640:-1:flags=lanczos[x];[x][1:v]paletteuse" output.gif
# -ss -> start from second
# -t -> duration
CREATE OR REPLACE FUNCTION adjacency_list(table_name regclass, user_name text) RETURNS void AS $$
BEGIN
EXECUTE format('DROP TABLE IF EXISTS %s_adjacency_list;
CREATE TABLE %s_adjacency_list AS
SELECT DISTINCT a.cartodb_id,
array_agg(b.cartodb_id) over (PARTITION BY a.cartodb_id) AS adjacent,
count(b.*) over (PARTITION BY a.cartodb_id) AS valence,
0 AS color
FROM %s a,
%s b
@alrocar
alrocar / carto-python-bigquery
Created April 18, 2018 05:11
This is a sample snippet to ingest data from BigQuery into CARTO by using both Python SDKs
A snippet to make a query to BigQuery and import the result in CARTO using both Python client libraries:
```
#!/usr/bin/env python
import argparse
import time
import uuid
from tempfile import NamedTemporaryFile
<!DOCTYPE html>
<html>
<head>
<title>Reacciones al #AccordDeParis</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%;
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" href="http://libs.cartocdn.com/cartodb.js/v3/3.15/themes/css/cartodb.css" />
<!-- <link rel="stylesheet" href="https://cartodb-libs.global.ssl.fastly.net/cartodb.js/v3/3.15/themes/css/cartodb.css" /> -->
<style type="text/css">
html,
@alrocar
alrocar / GIF-Screencast-OSX.md
Created June 29, 2017 13:09 — forked from dergachev/GIF-Screencast-OSX.md
OS X Screencast to animated GIF

OS X Screencast to animated GIF

This gist shows how to create a GIF screencast using only free OS X tools: QuickTime, ffmpeg, and gifsicle.

Screencapture GIF

Instructions

To capture the video (filesize: 19MB), using the free "QuickTime Player" application:

@alrocar
alrocar / join-points
Created April 30, 2017 19:14
Join points with PostGIS
SELECT cartodb_id, ele, time, ST_MAKELINE(the_geom,the_geom2) as the_geom FROM (
SELECT cartodb_id, row_number() OVER w AS ele, time, the_geom, lead(the_geom) OVER w AS the_geom2
FROM TRACK_POINTS WINDOW w AS (PARTITION BY track_fid ORDER BY cartodb_id) ) as q
WHERE the_geom2 IS NOT NULL
@alrocar
alrocar / segment-line
Last active April 30, 2017 19:16
Segment a line with PostGIS
insert into SEGMENTED_DATASET SELECT cartodb_id+n, ST_LineSubstring(the_geom, 100.00*n/length,
CASE
WHEN 100.00*(n+1) < length THEN 100.00*(n+1)/length
ELSE 1
END) As the_geom
FROM
(SELECT TRACK_GPS.cartodb_id,
ST_LineMerge(TRACK_GPS.the_geom) AS the_geom,
ST_Length(TRACK_GPS.the_geom::geography) As length
FROM TRACK_GPS
@alrocar
alrocar / README.md
Last active April 20, 2017 10:55
carto-python change privacy of dataset

In order to execute the code snippet below, use the 1.0.0 branch of carto-python. You can follow these steps:

  • git clone https://github.com/CartoDB/carto-python
  • cd carto-python/
  • git checkout 1.0.0
  • virtualenv env
  • source env/bin/activate
  • pip install -r requirements.txt
  • pip install .
  • python change_privacy.py # REMEMBER TO EDIT THE FILE TO INCLUDE YOUR USER CREDENTIALS AND DATASET_NAME
@alrocar
alrocar / LICENSE
Last active April 18, 2017 07:56
carto-tracks-example
Copyright 2017 Alberto Romeu Carrasco
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,