Skip to content

Instantly share code, notes, and snippets.

View steve-taylor's full-sized avatar

Steve Taylor steve-taylor

  • Sydney, Australia
View GitHub Profile
@steve-taylor
steve-taylor / pg_dump-to-cockroachdb.md
Last active April 8, 2022 15:15
Migrating a PostgreSQL database to CockroachDB Serverless

When restoring a PostgreSQL database from a dump, the process is to simply feed PostgreSQL the dump file, whose SQL statements it executes.

CockroachDB seems to take a different approach in order to restore the database more efficiently. Unfortunately, it lacks support for the types of things that often occur in a PostgreSQL dump, such as sequences and computed indexes. Fortunately, these things can usually be removed from the database dump before importing, then executed as DDL after importing.

Also, it's not easy for a new CockroachDB user to follow the import process as documented, so I wanted to make it easy.

  1. Move all DDL statements related to SEQUENCEs, INDEXes and VIEWs into a separate SQL file. You'll need this later.
  2. Ensure client_min_messages is set to debug5 in the PostgreSQL dump file.
  3. Add your billing address and credit card details to CockroachDB if you haven't already. (Cockroach will prevent imports from external sources until you do.)
  4. Start a local HTTP server so your
@steve-taylor
steve-taylor / fetchBacon.js
Created March 6, 2022 23:48
Bacon.js fetch wrapper with AbortController support
import {fromBinder} from 'baconjs'
/**
* Create a Bacon.js EventStream that fetches a resource specified by the fetch
* parameters.
*
* If the EventStream loses all subscriptions while the underlying request is pending,
* the request will be aborted using <code>AbortController</code>. NOTE: If
* <code>init.signal</code> is provided, it will be ignored in favour of an internally
* provided signal.
@steve-taylor
steve-taylor / theme-colors.html
Last active November 2, 2020 22:59
Theme color chooser
<!doctype html>
<html>
<head>
<style>
html, body {
font-family: -apple-system, BlinkMacSystemFont, 'Helvetica Neue', Roboto, 'Segoe UI', sans-serif;
}
.color-grid {
display: grid;
@steve-taylor
steve-taylor / generate-mnemonic.js
Created November 4, 2018 11:54
Given a list of words, generate a list of random words that start with the same letter as the original words.
#!/usr/bin/env node
const fs = require('fs');
const util = require('util');
const readline = require('readline');
const crypto = require('crypto');
const readFile = util.promisify(fs.readFile);
const rl = readline.createInterface({
@steve-taylor
steve-taylor / rancheros-swap.yml
Created March 25, 2018 11:31
RancherOS cloud-config.yml options
# RancherOS cloud-config.yml options I find useful.
# Enable 4GB swap
runcmd:
- sudo dd if=/dev/zero of=/swapfile bs=4K count=1M
- sudo chmod 600 /swapfile
- sudo mkswap /swapfile
- sudo swapon /swapfile
mounts:
- [ /swapfile, none, swap, sw, 0, 0 ]
@steve-taylor
steve-taylor / .bash_profile
Last active March 19, 2018 08:00
Private Docker registry with Let's Encrypt
#!/usr/bin/env bash
export REGISTRY_DOMAIN=docker.example.com
export DOMAIN_ADMIN_EMAIL=admin@example.com
export REGISTRY_USER=docker
@steve-taylor
steve-taylor / lua-editor.html
Last active January 8, 2024 03:25
Simple Lua text editor using Hightlight.js
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Lua editor with Syntax highlighting</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.26.0/babel.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.2.0/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.2.0/umd/react-dom.production.min.js"></script>
@steve-taylor
steve-taylor / sequence-generator.js
Created January 31, 2018 23:33
Create an Iterable over a sequence of numbers
function *sequence(...args) {
const start = args.length < 2 ? 0 : args[0];
const end = args[args.length < 2 ? 0 : 1] || 0;
const step = args.length < 3 ? 1 : args[2];
for (let i = start; i < end; i += step) {
yield i;
}
}
@steve-taylor
steve-taylor / parseBif.js
Created January 31, 2018 23:23
BIF file parser
function *parseBif(buffer) {
const data = new DataView(buffer);
// Ensure this is a BIF v0.
if (data.getUint32(0, true) !== 0x46494289 || data.getUint32(4, true) !== 0x0a1a0a0d || data.getUint32(8, true) !== 0) {
return;
}
const separation = data.getUint32(16, true) || 1000;
const start = 64;
@steve-taylor
steve-taylor / publish.sh
Created September 24, 2017 11:46
Version bump and publish Maven+Git project
#!/bin/bash
#
# Version bump and publish this Git+Maven repo.
#
# Usage: ./publish.sh {major|minor|patch}
#
# For example, to bump the version from 1.5.9 to 1.6.0:
#
# ./publish.sh minor