Skip to content

Instantly share code, notes, and snippets.

View MarHoff's full-sized avatar

Martin Hoffmann MarHoff

View GitHub Profile
@MarHoff
MarHoff / histogram.sql
Created May 19, 2016 07:07 — forked from wolever/histogram.sql
Functions to create and draw histograms with PostgreSQL.
-- Functions to create and draw histograms with PostgreSQL.
-- psql> select * from show_histogram((select histogram(length(email), 0, 32, 6) FROM auth_user limit 100));
-- bucket | range | count | bar | cumbar | cumsum | cumpct
-- --------+-------------------------------------+-------+--------------------------------+--------------------------------+--------+------------------------
-- 0 | [0,5.33333333333333) | 1 | | | 1 | 0.00273224043715846995
-- 1 | [5.33333333333333,10.6666666666667) | 5 | = | | 6 | 0.01639344262295081967
-- 2 | [10.6666666666667,16) | 149 | ============================== | ============= | 155 | 0.42349726775956284153
-- 3 | [16,21.3333333333333) | 145 | =========
@MarHoff
MarHoff / erreurs_pole_france2016.sql
Last active April 20, 2016 13:56
Poles de rattachements hors départements dans la table france2016.txt au 14-04-2016
SELECT actual, cheflieu, cdc, rang, reg, dep, com, ar, ct, modif, pole,
tncc, artmaj, ncc, artmin, nccenr, articlct, nccct
FROM insee_cog.france2016 WHERE subst(dep,1,2) <> substr(pole,1,2);
actual | cheflieu | cdc | rang | reg | dep | com | ar | ct | modif | pole | tncc | artmaj | ncc | artmin | nccenr | articlct | nccct
--------+----------+-----+------+-----+-----+-----+----+----+-------+-------+------+--------+------------------+--------+------------------+----------+-------
2 | | | | 32 | 02 | 285 | | | 1 | 59545 | 1 | | ESCAUFOURT | | Escaufourt | |
3 | | | | 24 | 28 | 131 | | | 1 | 91016 | 0 | | DOMMERVILLE | | Dommerville | |
2 | | | | 27 | 39 | 012 | | | 1 | 25527 | 1 | | ANTORPE | | Antorpe | |
2 | | | | 44 | 51 | 4
@MarHoff
MarHoff / clock.sql
Last active August 29, 2015 14:07 — forked from vpicavet/clock.sql
-- Open These views with QGIS
-- You can label the ticks view with this expression : "CASE WHEN m % 5 = 0 THEN h END" to get hour numbers
-- Set categorized styles on typ and unit to set different styles for dials, and for the hands
-- Please tweet your best clock designs with #PostGISClock hashtag
create or replace view ticks as
select
m as id
, case when m % 5 = 0 then 'h' else 'm' end as typ
, m / 5 as h