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
/** | |
* Will normalize quotes in a given string. There are many variations of quotes | |
* in the unicode character set, this function attempts to convert any variation | |
* of quote to the standard Quotation Mark - U+0022 Standard Universal: " | |
* | |
* @param {string} str The string to normalize | |
* @return {string} Normalized string. | |
* @see https://unicode-table.com/en/sets/quotation-marks/ | |
*/ | |
helpers.stdQuote = (str) => { |
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
#!/usr/bin/mawk -f | |
# | |
# description | |
# | |
BEGIN { | |
} | |
{ |
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
#!/usr/bin/awk -f | |
# | |
# Reads a CSV file and prints a TSV file to standard output. | |
# | |
# Usage: | |
# ./csv-to-tsv.awk input.csv > output.tsv | |
# ./csv-to-tsv.awk -v SEP=";" input.csv > output.tsv | |
# ./csv-to-tsv.awk -v COLUMNS=10 input.csv > output.tsv | |
# |
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
#!/bin/sh | |
zcat "$1" | 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
#!/bin/local/gawk -f | |
# parse utf-16 escape sequences generated by WGET | |
# transform them all into HTML entities: `�` | |
function parse_unicode() { | |
while (match($0, /\\u[0-9a-f][0-9a-f][0-9a-f][0-9a-f]/)) { | |
hex = substr($0, RSTART+2, RLENGTH-2); | |
gsub( "\\\\u" hex, "\\&#x" hex ";", $0); | |
} |
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
# hexadecimal reference to decimal | |
echo "--ƒ--" \ | |
| awk '{ while (match($0, /&#x[0-9a-fA-F]+;/)) { n = "0x" substr($0, RSTART + 3, RLENGTH - 4 ); x = sprintf("&#%d;", strtonum(n)); $0 = substr($0, 1, RSTART - 1) x substr($0, RSTART + RLENGTH); }; print }' | |
--ƒ-- | |
# decimal reference to character | |
echo "--ƒ--" \ | |
| awk '{ while (match($0, /&#[0-9]+;/)) { n = substr($0, RSTART + 2, RLENGTH - 3 ); sub(/^0+/, "", n); x = sprintf("%c", strtonum(n)); $0 = substr($0, 1, RSTART - 1) x substr($0, RSTART + RLENGTH); }; print }' | |
--ƒ-- |
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 join_numbers( i, n, x) { | |
while (match($0, /[ ][0-9,.()-]+[ ][0-9,.()-]+[ ]?/)) { | |
i = RSTART; | |
n = RLENGTH; | |
x = substr($0, i, n); | |
gsub(" ", "", x); | |
$0 = substr($0, 0, i-1) " " x " " substr($0, i+n) | |
} | |
} |
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 uuid7_sql() RETURNS uuid AS $$ | |
SELECT (FORMAT('%s-%s-%0s-%s-%s', | |
lpad(to_hex(trunc(EXTRACT(EPOCH FROM statement_timestamp()) * 1000)::bigint >> 16), 8, '0'), | |
lpad(to_hex(trunc(EXTRACT(EPOCH FROM statement_timestamp()) * 1000)::bigint & 65535), 4, '0'), | |
lpad(to_hex((trunc(random() * 2^12) + 28672)::bigint), 4, '0'), -- 28672 = 0x7000 | |
lpad(to_hex((trunc(random() * 2^14) + 32768)::bigint), 4, '0'), -- 32768 = 0x8000 | |
lpad(to_hex(trunc(random() * 2^48)::bigint), 12, '0')))::uuid; | |
$$ LANGUAGE SQL; | |
select uuid7_sql() -- 019450fe-7b0f-7ccc-8564-ad3ccc8234e0 |
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
-- install the extension | |
CREATE EXTENSION pgcrypto; | |
CREATE OR REPLACE FUNCTION secure_random_bigint() RETURNS bigint AS $$ | |
DECLARE | |
v_bytes bytea; | |
v_value bigint := 0; | |
v_length integer := 8; | |
i integer := 0; | |
BEGIN |
NewerOlder