Skip to content

Instantly share code, notes, and snippets.

View vbilopav's full-sized avatar
🏠
Working from home

Vedran Bilopavlović vbilopav

🏠
Working from home
View GitHub Profile
CREATE EXTENSION pg_stat_statements SCHEMA public;
# postgresql.conf
shared_preload_libraries = 'pg_stat_statements' # (change requires restart)
pg_stat_statements.max = 10000
pg_stat_statements.track = all
select
g.code
from (
select generate_series as code from generate_series(1000, 9999)
) g
left outer join tbl t on g.code = t.id
where
t.id is null
order by
random() limit 1;
select
keys.key, data->>keys.key as value
from (
select distinct jsonb_object_keys(data) as key from table
) keys cross join table
where data->>keys.key is not null
group by keys.key, data->>keys.key
select "value" from "values" where id = @id;
do $$
begin
drop function if exists select_company_and_sectors(int);
drop function if exists update_company(int, json);
drop function if exists update_sectors(json);
drop table if exists employees;
drop table if exists sectors;
drop table if exists companies;
define(["sys/html"], html => {
const
test = (object, extensions) => {
extensions.forEach(e => {
if (object.prototype[e] !== undefined) {
throw new Error(`Error: Name collision - object ${object} already have defined "${e}" !`);
}
});
};
@vbilopav
vbilopav / pubsub.js
Last active February 19, 2019 14:26
/*
*** Publish/Subscribe global events functions - implementation of pubsub pattern for loose coupled components ***
Usage:
* Publish global application event:
publish("unique event name / category / subcategory", arg1, arg2, arg3);
or
select
t.table_name,
c.column_name,
c.data_type ||
case when c.character_maximum_length is not null
then '(' || cast(c.character_maximum_length as varchar) || ')'
else case when c.numeric_precision is not null
then '(' || cast(c.numeric_precision as varchar) || ',' || cast(c.numeric_precision_radix as varchar) || ')'
|| case when coalesce(c.numeric_scale, 0) = 0 then '' else ',' || cast(c.numeric_scale as varchar) || ')' end
define('text',["module"],function(e){"use strict";var l,o,a,s,u,r=["Msxml2.XMLHTTP","Microsoft.XMLHTTP","Msxml2.XMLHTTP.4.0"],t=/^\s*<\?xml(\s)+version=[\'\"](\d)*.(\d)*[\'\"](\s)*\?>/im,i=/<body[^>]*>\s*([\s\S]+)\s*<\/body>/im,c="undefined"!=typeof location&&location.href,f=c&&location.protocol&&location.protocol.replace(/\:/,""),p=c&&location.hostname,d=c&&(location.port||void 0),m={},v=e.config&&e.config()||{};return l={version:"2.0.12",strip:function(e){if(e){var n=(e=e.replace(t,"")).match(i);n&&(e=n[1])}else e="";return e},jsEscape:function(e){return e.replace(/(['\\])/g,"\\$1").replace(/[\f]/g,"\\f").replace(/[\b]/g,"\\b").replace(/[\n]/g,"\\n").replace(/[\t]/g,"\\t").replace(/[\r]/g,"\\r").replace(/[\u2028]/g,"\\u2028").replace(/[\u2029]/g,"\\u2029")},createXhr:v.createXhr||function(){var e,n,t;if("undefined"!=typeof XMLHttpRequest)return new XMLHttpRequest;if("undefined"!=typeof ActiveXObject)for(n=0;n<3;n+=1){t=r[n];try{e=new ActiveXObject(t)}catch(e){}if(e){r=[t];break}}return e},parseName:function