Skip to content

Instantly share code, notes, and snippets.

View devi's full-sized avatar
⛰️
Off-Grid

Devi Mandiri devi

⛰️
Off-Grid
View GitHub Profile
CREATE FUNCTION jb_merge(jsonb, jsonb)
RETURNS jsonb
IMMUTABLE
LANGUAGE SQL
AS $$
WITH xxx AS
(SELECT * FROM jsonb_each_text($1)
UNION ALL
SELECT * FROM jsonb_each_text($2))
SELECT json_object_agg(key, value)::jsonb FROM xxx;
CREATE OR REPLACE FUNCTION public.json_append(data json, insert_data json)
RETURNS json
IMMUTABLE
LANGUAGE sql
AS $$
SELECT ('{'||string_agg(to_json(key)||':'||value, ',')||'}')::json
FROM (
SELECT * FROM json_each(data)
UNION ALL
SELECT * FROM json_each(insert_data)
@devi
devi / multi shape
Last active June 12, 2018 15:46 — forked from eqhmcow/multi shape
#!/bin/bash
# As the "bufferbloat" folks have recently re-discovered and/or more widely
# publicized, congestion avoidance algorithms (such as those found in TCP) do
# a great job of allowing network endpoints to negotiate transfer rates that
# maximize a link's bandwidth usage without unduly penalizing any particular
# stream. This allows bulk transfer streams to use the maximum available
# bandwidth without affecting the latency of non-bulk (e.g. interactive)
# streams.
@devi
devi / keccak-compat.js
Last active August 29, 2015 14:03
keccak-compat.js
// keccak
//
// Implementation derived from https://github.com/floodyberry/scrypt-jane
//
// Ported by Devi Mandiri. Public domain
//
var u64 = function (h, l) {
h = h|0; l = l|0;
this.hi = h >>> 0;
this.lo = l >>> 0;
@devi
devi / keccak.js
Last active August 29, 2015 14:03
keccak.js
// keccak
//
// Implementation derived from https://github.com/floodyberry/scrypt-jane
//
// Ported by Devi Mandiri. Public domain
//
var u64 = function (h, l) {
h = h|0; l = l|0;
this.hi = h >>> 0;
this.lo = l >>> 0;
@devi
devi / blake2b.js
Created July 2, 2014 08:49
blake2b.js
(function(exports) {
'use strict';
// Blake2b
// Ported by Devi Mandiri. Public domain.
var u64 = function (h, l) {
h = h|0; l = l|0;
this.hi = h >>> 0;
@devi
devi / sha512.js
Last active August 29, 2015 14:02
sha512.js
/* sha512 */
// Written in 2014 by Devi Mandiri. Public domain.
//
// Implementation derived from TweetNaCl version 20140427.
// See for details: http://tweetnacl.cr.yp.to/
//
var u64 = function (h, l) {
h = h|0; l = l|0;
this.hi = h >>> 0;
@devi
devi / poly1305.js
Last active August 29, 2015 14:02
poly1305.js
/* poly1305 */
// Written in 2014 by Devi Mandiri. Public domain.
//
// Implementation derived from poly1305-donna-16.h
// See for details: https://github.com/floodyberry/poly1305-donna
var Poly1305BlockSize = 16;
var Poly1305Ctx = function() {
@devi
devi / chacha20.js
Last active July 6, 2016 22:06
chacha20.js
/* chacha20 - 256 bits */
// Written in 2014 by Devi Mandiri. Public domain.
//
// Implementation derived from chacha-ref.c version 20080118
// See for details: http://cr.yp.to/chacha/chacha-20080128.pdf
var Chacha20KeySize = 32;
var Chacha20NonceSize = 8;
@devi
devi / u64.js
Last active August 29, 2015 14:02
helper for dealing with uint64
// helper for dealing with uint64
var u64 = function (h, l) {
h = h|0; l = l|0;
this.hi = h >>> 0;
this.lo = l >>> 0;
}
function new64(num) {
var hi = 0, lo = num >>> 0;
if ((+(Math.abs(num))) >= 1) {