Skip to content

Instantly share code, notes, and snippets.

@brito
brito / slider.sql
Created May 23, 2020 02:14
Simple ASCII slider visualization of two quantities and their relative ratio
/*
Simple ASCII slider visualization of two quantities and their relative ratio
eg */ select * from _slider(3,5); /*
*/
create function _slider(_left int, _right int, _glyphs text[] = '{-,|,-}')
returns text as $$
select
repeat(_glyphs[1], _left)
|| _glyphs[2] ||
@brito
brito / histogram.sql
Created May 23, 2020 02:14
Column histogram
/*
Column histogram
eg */ select * from _meta (
'{app_public}',
'{data_report_session,data_raw_session,data_report}'),
_histogram(_schema,_relname,_column,_type);/*
*/
create function _histogram(_schema name,_relname name,_column name,_type text)
returns setof json as $function$ begin
return query execute format(case
@brito
brito / iqt.sql
Created May 23, 2020 02:13
Column interquartile range and box-and-whisker plot
/*
Column interquartile range and box-and-whisker plot
eg */ select * from _meta (
'{app_public}',
'{data_report_session,data_raw_session,data_report}'),
_iqt(_schema,_relname,_column,_type);/*
*/
create function _iqt(_schema name, _relname name, _column name, _type text)
returns table (_quartiles json, _whiskers text) as $function$
select xmltable.* from (select query_to_xml(format(case
@brito
brito / tally.sql
Created May 23, 2020 02:13
Top 10 count distinct values in a column
/*
Top 10 count distinct values in a column
eg */ select * from _meta (
'{app_public}',
'{data_report_session,data_raw_session,data_report}'),
_tally(_schema,_relname,_column);/*
*/
create function _tally(_schema name,_relname name,_column name)
returns table (_tally json) as $function_tally$
select xmltable.* from (select query_to_xml(format($$
@brito
brito / meta.sql
Created May 23, 2020 02:12
List column names and types for relations in schemas
/*
List column names and types for _relations in _schemas
eg */ select * from _meta (
'{app_public}',
'{data_report_session,data_raw_session,data_report}');/*
*/
create function _meta (_schemas text[], _relations text[])
returns table (_schema name, _relname name, _kind text, _column name, _type name) as $$
@brito
brito / lcs.js
Last active December 9, 2019 23:13
Hacky longest common subsequence
// longest common subsequence
// without additions nor deletions
var list = `five
one_two_three
two_three_four
three_four_five
one_two
foo_bar
bar_baz`
@brito
brito / dabblet.css
Last active April 4, 2019 23:26
Seasonal palette
/* Seasonal palette*/
body {
background: linear-gradient(to right,
hsl(217, 78%, 58%) 0,
hsl(59, 84%, 78%) 22%, /* spring equinox */
hsl(40, 91%, 61%) 49%, /* summer solstice */
hsl(18, 66%, 45%) 73%, /* autumn equinox */
hsl(217, 78%, 58%) 99%); /* winter solstice */
display:flex; height:100vw;
margin:0;
// eg (buy_load|free_bee|no_signal)
topicWords = '('+ ['buy load', 'free bee', 'no signal'].join('|') +')';
// eg (but|however|already)
complexWords = '('+ ['but', 'however', 'already'].join('|') +')';
maxWordsBetween = 2;
// eg 'in there '
maybeWordsBetween = '('+ `(\\W+\\w+){0,${maxWordsBetween}}` + ')';
@brito
brito / timewave.js
Last active December 14, 2018 21:28
for browser console funsies
/** in an era of public availability of source code, is explicit credit still necessary? */
//codegolf.stackexchange.com/a/79490/69502
continuous_fraction = f = (n,d) => n%d ? [r=(n/d)|0,...f(d,n-r*d)] : [n/d]
fill = (ch,n) => Array(n).fill(ch).join('')
bars = n => console.debug(fill('|', Math.abs(n)), n, fill(' ', Math.pow(Math.random(),-2)|0))
interval =
//stackoverflow.com/a/18123985/811330
function removeDiacritics (str) {
return [
{'base':'A', 'letters':/[\u0041\u24B6\uFF21\u00C0\u00C1\u00C2\u1EA6\u1EA4\u1EAA\u1EA8\u00C3\u0100\u0102\u1EB0\u1EAE\u1EB4\u1EB2\u0226\u01E0\u00C4\u01DE\u1EA2\u00C5\u01FA\u01CD\u0200\u0202\u1EA0\u1EAC\u1EB6\u1E00\u0104\u023A\u2C6F]/g},
{'base':'AA','letters':/[\uA732]/g},
{'base':'AE','letters':/[\u00C6\u01FC\u01E2]/g},
{'base':'AO','letters':/[\uA734]/g},
{'base':'AU','letters':/[\uA736]/g},
{'base':'AV','letters':/[\uA738\uA73A]/g},
{'base':'AY','letters':/[\uA73C]/g},