This file contains 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 FUNCTION count_estimate(query text) RETURNS integer AS $$ | |
DECLARE | |
rec record; | |
rows integer; | |
BEGIN | |
FOR rec IN EXECUTE 'EXPLAIN ' || query LOOP | |
rows := substring(rec."QUERY PLAN" FROM ' rows=([[:digit:]]+)'); | |
EXIT WHEN rows IS NOT NULL; | |
END LOOP; | |
RETURN rows; |
This file contains 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 function lcfirst(word text) | |
returns text | |
language plpgsql | |
immutable | |
as $$ | |
begin | |
return lower(left(word, 1)) || right(word, -1); | |
end; | |
$$; |
This file contains 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
const ALGORITHM = { | |
name: 'HMAC', | |
hash: 'SHA-256' | |
} | |
const bufferToHex = (buffer) => ( | |
[...new Uint8Array(buffer)] | |
.map(b => b.toString(16).padStart(2, '0')) | |
.join('') | |
) |
This file contains 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
const b64EncodeUnicode = (str) => ( | |
window.btoa(window.encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, (_match, p1) => ( | |
String.fromCharCode(`0x${p1}`) | |
))) | |
) | |
const b64DecodeUnicode = (str) => ( | |
window.decodeURIComponent(window.atob(str).split('').map((c) => ( | |
`%${`00${c.charCodeAt(0).toString(16)}`.slice(-2)}` | |
)).join('')) |
This file contains 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
require 'benchmark/ips' | |
require 'ostruct' | |
# Enable and start GC before each job run. Disable GC afterwards. | |
class GCSuite | |
def warming(*) | |
run_gc | |
end |
This file contains 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
# unlogged tables used to speedup tests, but its are not crash proof | |
config.to_prepare do | |
ActiveSupport.on_load(:active_record) do | |
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.create_unlogged_tables = true | |
end | |
end |
This file contains 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
// you need to use https://github.com/digitalbazaar/forge | |
const encryptData = (key, data) => { | |
const mdKey = forge.md.sha256.create() | |
mdKey.update(key) | |
const iv = forge.random.getBytesSync(12) | |
const cipher = forge.cipher.createCipher('AES-GCM', mdKey.digest()) | |
cipher.start({ |
This file contains 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
# frozen_string_literal: true | |
require 'socket' | |
require 'resolv' | |
class DNSServer | |
attr_reader :port, :ttl | |
def initialize(port: 5300, ttl: 60, records: {}) |
This file contains 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
# frozen_string_literal: true | |
require 'socket' | |
require 'bindata' | |
class DnsHeader < BinData::Record | |
endian :big | |
uint16 :transaction_id | |
bit1 :flag_QR |
This file contains 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
import React from 'react' | |
import {Dispatcher} from 'flux' | |
import {EventEmitter} from 'events' | |
import keyMirror from 'fbjs/lib/keyMirror' | |
import './app.sass' | |
const actions = keyMirror({ | |
PLUS_ACTION: null, | |
MINUS_ACTION: null |
NewerOlder