Skip to content

Instantly share code, notes, and snippets.

@tswaters
tswaters / ddl.sql
Created August 31, 2022 21:33
crud operations using json_to_recordset
CREATE TABLE _table (
pk SERIAL PRIMARY KEY,
field1 TEXT,
field2 TEXT,
date_deleted TIMESTAMPTZ
);
@tswaters
tswaters / index.html
Created December 4, 2021 03:27
HOW TO: center text
<!DOCTYPE html>
<html>
<head>
<title>How to center text</title>
<meta charset="utf-8" />
</head>
<body>
<table style="width: 100%; height: 100%; position:absolute;">
<tr>
<td valign="middle" align="center">
@tswaters
tswaters / game-of-life.mjs
Created December 13, 2020 00:05
Terminal game of life
import readline from 'readline'
const w = process.stdout.columns
const h = process.stdout.rows
const init = () => Array.from({ length: w * h }).map(() => Math.round(Math.random()))
let state = init()
const deindex = (i) => [i % w, Math.floor(i / w)]
@tswaters
tswaters / postgres-policy.sql
Last active February 7, 2020 05:08
postgres policy
SET SESSION app.id TO DEFAULT;
SET ROLE postgres;
SET search_path = 'public';
DROP TABLE IF EXISTS expenses CASCADE;
DROP TABLE IF EXISTS projects CASCADE;
DROP TABLE IF EXISTS users CASCADE;
CREATE TABLE users (
user_name text PRIMARY KEY NOT NULL,
### Keybase proof
I hereby claim:
* I am tswaters on github.
* I am tswaters (https://keybase.io/tswaters) on keybase.
* I have a public key ASAm_89GCHVXoI95zX9hNRCPpZH-qf9RlS2mR4qQBBHWOgo
To claim this, I am signing this object:
@tswaters
tswaters / bench.js
Last active September 13, 2019 05:49
seneca-web-adapter-express bench
'use strict'
const { runMain, show } = require('bench')
const express = require('express');
const Seneca = require('seneca');
const SenecaWeb = require('seneca-web');
const adapter = require('..');
const Request = require('request')
'use strict'
// error-prone work function
const _work = (name, failure_rate) => (thing) =>
new Promise((resolve, reject) => {
setTimeout(() => {
if (Math.random() < failure_rate) {
console.log(`${name} failed - ${JSON.stringify(thing)}`)
reject(new Error(`${name} hit above ${failure_rate}`))
} else {
@tswaters
tswaters / .dockerignore
Last active October 10, 2022 22:57
node dockerfile
.git
node_modules
dist
public
@tswaters
tswaters / canvas.html
Created September 29, 2018 03:31
Cards on canvas
<!doctype html>
<html>
<head>
<meta charet="utf-8"/>
<style>
canvas {
image-rendering: crisp-edges;
margin: 5px;
}
canvas.horizontal {
@tswaters
tswaters / random.js
Created September 23, 2018 20:06
random number using node crypto
'use strict'
const assert = require('assert')
const crypto = require('crypto')
module.exports = (min, max) => {
// borrowed from http://stackoverflow.com/a/33627342
// figure out range and how many bytes required