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
| (function(){ | |
| // Input a number in either a text field or with a slider. | |
| // Usage: <input type="number" is="with-slider" min="20" max="100" name="..." value="..."> | |
| try { | |
| var proto = Object.create(HTMLInputElement.prototype); | |
| proto.createdCallback = function() { | |
| var self = this; | |
| this.type = "number"; | |
| this.addEventListener("change", this.setDecimalPlaces); | |
| this.slider = document.createElement('input'); |
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
| if git ls-files -mo --exclude-standard | grep -q . | |
| then | |
| echo ":-X Dirty git. Say sorry:" | |
| read sorry ; [[ "${sorry:-unrepentant}" == "sorry" ]] || exit 1 | |
| else echo ":-) Git clean" | |
| fi |
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
| # Get (all, including multiline) postgres log file entries for [26748- | |
| sed -n ':a;/\[26748-/{ h;:b;n;/^\s/{H;bb};x;p;:a }' /var/log/postgresql/postgresql-9.5-warehouse.log | less |
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
| -- Note: There is a similar project: https://github.com/tgres/tgres | |
| -- I haven't looked into it much. | |
| -- This is nice and readable: http://grisha.org/blog/2015/09/23/storing-time-series-in-postgresql-efficiently/ | |
| CREATE TABLE ts ( tsid SERIAL PRIMARY KEY, name text, current INTEGER, value DOUBLE PRECISION, data DOUBLE PRECISION[], UNIQUE(name)); | |
| -- Initialise a timeseries: | |
| CREATE OR REPLACE FUNCTION pllua_init(len INTEGER, next INTEGER, value DOUBLE PRECISION) RETURNS DOUBLE PRECISION[] AS $$ | |
| local ans = {}; local i; for i=1,len,1 do ans[i] = 0 end |
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
| ss -ltpn | sed -r '1d;s/^(\S+\s+){3}(\S+).*,(pid=)?([0-9]+),(fd=)?[0-9]+[)][).*]/\2 \4/g' | while read line ; do set $line ; echo $1 $(readlink -f /proc/$2/cwd) $(cat /proc/$2/cmdline) ; done | sort |
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
| -- Like the Postgres first_val() aggregator, exceppt that this returns the first non-null value. | |
| CREATE OR REPLACE FUNCTION first_non_null_fun(numeric, numeric) RETURNS numeric | |
| AS 'SELECT case when $1 is null then $2 else $1 end;' | |
| LANGUAGE SQL IMMUTABLE STRICT; | |
| CREATE AGGREGATE first_non_null ( numeric ) ( | |
| SFUNC = first_non_null_fun, | |
| STYPE = numeric | |
| ); |
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
| create or replace function daynum_now() returns integer as $$ | |
| begin | |
| RETURN FLOOR(EXTRACT(EPOCH FROM now())/(24*3600)); | |
| end | |
| $$ LANGUAGE 'plpgsql'; |
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
| -- Refresh materialized views recursively | |
| -- DEPENDS: | |
| -- List the tables that a view depends on. | |
| -- Thanks to Dave: http://stackoverflow.com/questions/4229468/getting-a-list-of-tables-that-a-view-table-depends-on-in-postgresql | |
| create or replace function inf_view_dependencies(v text) | |
| returns table (kind text, name text) as $$ | |
| SELECT cl_d.relkind::text as kind | |
| , cl_d.relname::text AS name | |
| FROM pg_rewrite AS r |
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 the tables that a view depends on. | |
| -- Usage: select * from inf_view_dependencies(SOME_VIEW); | |
| -- Thanks to Dave: http://stackoverflow.com/questions/4229468/getting-a-list-of-tables-that-a-view-table-depends-on-in-postgresql | |
| create function inf_view_dependencies(v text) | |
| returns table (kind text, name text) as $$ | |
| SELECT cl_d.relkind::text as kind | |
| , cl_d.relname::text AS name | |
| FROM pg_rewrite AS r | |
| JOIN pg_class AS cl_r ON r.ev_class=cl_r.oid | |
| JOIN pg_depend AS d ON r.oid=d.objid |
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
| iotop -b | head | gawk '{print $1}' | tee /dev/stderr | xargs --replace={} ionice -c3 -p{} |