Skip to content

Instantly share code, notes, and snippets.

aasdasd

@javisantana
javisantana / index.html
Created October 22, 2014 04:37
highlight polygon on click with leaflet and cartodb.js
<!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 / license.txt
Last active August 30, 2023 07:07
NMEA parser in java which does not suck
this software is under the terms of MIT license: http://opensource.org/licenses/MIT
@javisantana
javisantana / quota.sql
Created October 11, 2011 09:42
soft quota limit on postgres
-- You need to create plpython languaje in the database
-- createlang -U postgres plpythonu DATABASE_NAME
-- this small trigger prevents an user exceeds a database size. Once the user exceeds the quota
-- the database size is checked every time an update or insert are performed until the user deletes some data
-- If the server is restarted the quota is checked the fist time user executes some update or insert
CREATE OR REPLACE FUNCTION check_quota() RETURNS trigger AS
$$
c = SD.get('quota_counter', 0)
if c%1000 == 0:
import urllib,sys,csv;
print reduce(lambda p, new: (p[0] + (new - p[0])/p[1], p[1] + 1), map(float, (x['tip_amount'] for x in csv.DictReader(urllib.urlopen(sys.argv[1])))), (0, 1))
@javisantana
javisantana / python_code_test_carto.md
Last active November 17, 2021 07:27 — forked from jorgesancha/python_code_test_carto.md
Python code test - CARTO

Build the following and make it run as fast as you possibly can using Python 3 (vanilla). The faster it runs, the more you will impress us!

Your code should:

All of that in the most efficient way you can come up with.

@javisantana
javisantana / gps.java
Created March 20, 2011 18:39
real/fake gps
package hardware;
import java.util.ArrayList;
import android.app.Activity;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.location.LocationProvider;

When you a clickhouse cluster and you run queries on all the replicas it's not easy to get all the queries ran. I use system.query_log all the time to check timings, errors and so on.

So what I do is create a global query_log:

:) create view query_log_all on cluster my_cluster as select * from remote('10.0.0.1,10.0.0.2', 'system.query_log')

So I can inspect queries in all the replicas with a single query:

Sometimes you have to move data from one table to a different one. You usually use

insert into target select * from source

This works but have several problems:

  1. materialized columns are not properly copied
  2. it's slow