This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Tally v 1.0 */ | |
function tally (range, limit = 10){ | |
let total = range.length, | |
values = {} | |
for (let [k, v] of range) { | |
k = ('' + k).replace(/\n[\s\S]*/, '…') | |
values[k] = values[k] ? values[k] + 1 : 1 | |
} | |
return Object.entries(values) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Transform a string using multiple regex | |
@customfunction | |
*/ | |
function replaces(operators,operands) { | |
return operators[0].map ? | |
operators.reduce((a,b) => replaces(b,a), operands) | |
: operands.replace(new RegExp(operators[0]), operators[1]) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* __ _ _ _ __ | |
__ _ / _| |_ ___ __ _ _ __ __ _ ___| |_ ___ ___| |__ __ _ ___ _ __ ___ /_/ ___ | |
/ _` | |_| __/ _ \ / _` | '_ \ / _` / __| __/ _ \ / __| '_ \ / _` / __| '_ ` _ \ / _ \/ __| | |
| (_| | _| || (_) | (_| | | | | (_| \__ \ || (_) | (__| | | | (_| \__ \ | | | | | (_) \__ \ | |
\__,_|_| \__\___/ \__,_|_| |_|\__,_|___/\__\___/ \___|_| |_|\__,_|___/_| |_| |_|\___/|___/ | |
αυτοαναστοχασμός ergo legit */ | |
select | |
_column, _type, | |
_nulls, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Simple ASCII bar visualization of a single quantity | |
eg */ select * from _bar(53); /* | |
*/ | |
create function _bar(_quantity int, _glyph text = '■') | |
returns text as $$ | |
select repeat(_glyph,_quantity/3) || ' ' || _quantity | |
$$ language sql immutable; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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] || |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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($$ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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 $$ | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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` |