Skip to content

Instantly share code, notes, and snippets.

View thesmart's full-sized avatar

John Smart thesmart

View GitHub Profile
@thesmart
thesmart / postgresql_errors.js
Last active May 30, 2024 17:14
A helpful decoding of PostgreSQL error codes to plain text error messages. @see https://www.postgresql.org/docs/14/errcodes-appendix.html
const errorCodes = {
'00000': 'Success: successful_completion',
'01000': 'Warning: warning',
'0100C': 'Warning: dynamic_result_sets_returned',
'01008': 'Warning: implicit_zero_bit_padding',
'01003': 'Warning: null_value_eliminated_in_set_function',
'01007': 'Warning: privilege_not_granted',
'01006': 'Warning: privilege_not_revoked',
'01004': 'Warning: string_data_right_truncation',
'01P01': 'Warning: deprecated_feature',
function extract() {
let EMAIL_REGEX = /[^@^\s]+@([^\s]+)/;
let resultsEl = document.getElementById("results");
let data = resultsEl.innerHTML.split('<b>');
data.shift(); data.shift();
let entries = data.map(function(t) {
let fields = t.split('<br>');
fields = fields.map(function(t) {
return t.replaceAll(/<[^>]+>/g, '')
hQIMA7RHUuesCgrCARAAo7Xl5uxdVqdVKQTowlq2Imbb30tCDIlmKmQjN1JuBuEj
NiDrBPSQinkboLL+kk2OaJ1GzEQbebUqSudtKbxScLWg8W2LL4MuXWXnc6IQ6wVv
//DZwZv1d3COD+0/L9H7h3ug376xgJtb7WlWT0Bm6b2Rg+VnjP/Ka2K5J49QHocP
t8D7IS4JJOg79hftAqUnHQbi+ma/MuJmYYJ2oSWgMxmnw/b41YJrt6XVJ9i3r33t
zcJOEuRer6dz7vuVNrjNfiQO6DrGZVwWzPyAFwNYMnfARJdDyEK5jTEqM/iv5frO
+YDhZsMFLUCefLWs+RRlbWu1fj9hNqOoKAedMavIcLW24+Hq/gAwAfUReq5YSUsF
hmQBMZNbo51dvMWm7Qdg1e954NEyEkF0Tw0/24gkUajhCbshFhXAKd+XynNih7GV
y2V5kof4C0JZh0FhYa3CsGgfeIGi4Wv5F3J/NPmeNJLRwNy+Tsu4Bw7eM/EetXCt
THArF8Pe0wG7j3o/gkS1EZ1iVx4v8TN/kG2PsqiL76CazdZcp0aBKtk3UrEhnn1R
ZSoLB22QksVV9qSVkBtJAfWs2/jCBvs9x9HE6NHoE75kuJkb1bkodt0pdpkoL77B
@thesmart
thesmart / mock-oak-test.ts
Created March 7, 2021 22:53
This is an example showing how Deno's Oak can be tested without network connections
import type {
Server,
ServerRequest,
ServerResponse,
} from "https://deno.land/x/oak@v6.5.0/types.d.ts";
import {
Application,
ListenOptions,
} from "https://deno.land/x/oak@v6.5.0/mod.ts";
@thesmart
thesmart / hid_generate.sql
Created May 5, 2020 17:25
Generates ordered, base36 alpha-numeric ids similar to Slack's ID scheme. Suitable for use as primary key.
-- This function generates ordered, base36 alpha-numeric ids similar to Slack's ID scheme.
--
-- I wanted a primary key scheme that had the following features:
-- 1) Lexical order, so that `ORDER BY` works as expected.
-- 2) Prevents sampling an auto-incrementing primary key to determine growth over time.
-- 3) Shorter and more human-friendly than BIGINT and UUID keys.
-- 4) Has a prefix such that table can be inferred from any record's primary or foreign key.
--
-- It is suitable for use as primary key, provided a few assumptions are true:
-- 1) You do not attempt to genereate more than 10M hids per second (system-time).
text.gsub!('`', '')
# these are unicode equivalents
text.gsub!('*', '﹡')
text.gsub!('_', '_')
text.gsub!('-', '‒')
text.gsub!('~', '~')
text.gsub!('%', '%')
text.gsub!('^', '^')
text.gsub!('|', '|')
text.gsub!(':', '꞉')
const declineCodes = {
approve_with_id: "The payment cannot be authorized. The payment should be attempted again. If it still cannot be processed, the customer needs to contact their card issuer.",
call_issuer: "The card has been declined for an unknown reason. The customer needs to contact their card issuer for more information.",
card_not_supported: "The card does not support this type of purchase. The customer needs to contact their card issuer to make sure their card can be used to make this type of purchase.",
card_velocity_exceeded: "The customer has exceeded the balance or credit limit available on their card. The customer should contact their card issuer for more information.",
currency_not_supported: "The card does not support the specified currency. The customer needs to check with the issuer whether the card can be used for the type of currency specified.",
do_not_honor: "The card has been declined for an unknown reason. The customer needs to contact their card issuer for more informati
@thesmart
thesmart / dump_http_multipart.js
Created August 16, 2018 17:37
Dump an http multipart body
import * as when from 'when';
import * as winston from 'winston';
import settings from '../cli';
import * as fs from 'fs';
import * as util from 'util';
/**
* Records a multipart upload for later playback in testing.
* @constructor
*/
utcOffset = ->
date = new Date()
jan = new Date(date.getFullYear(), 0, 1);
jul = new Date(date.getFullYear(), 6, 1);
utcOffset = -Math.floor(Math.max(jan.getTimezoneOffset(), jul.getTimezoneOffset()) * 60)
@thesmart
thesmart / readdirSyncRecursive
Created November 27, 2012 04:28
readdirSyncRecursive - Recurse through a directory and populate an array with all the file paths beneath
/**
* Recurse through a directory and populate an array with all the file paths beneath
* @param {string} path The path to start searching
* @param {array} allFiles Modified to contain all the file paths
*/
function readdirSyncRecursive(path, allFiles) {
var stats = fs.statSync(path);
if (stats.isFile()) {
// base case
allFiles.push(path);