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 / 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>
create table budget_category
(
id bigserial,
name text not null,
constraint pk_budget_category primary key (id)
);
create table financial_source
(
id bigserial,
@steve-taylor
steve-taylor / doSynchronousLoop.js
Last active December 4, 2022 00:51
Synchronous for loop in JavaScript to ensure that the n+1th item isn't processed until the callback of the nth item's processor has been called.
/**
* Process an array of data synchronously.
*
* @param data An array of data.
* @param processData A function that processes an item of data.
* Signature: function(item, i, callback), where {@code item} is the i'th item,
* {@code i} is the loop index value and {@code calback} is the
* parameterless function to call on completion of processing an item.
*/
function doSynchronousLoop(data, processData, done) {
@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 / react-bacon.js
Last active October 27, 2021 11:03
Connect a React component to Bacon.js streams and buses
import React from 'react';
import Bacon from 'baconjs';
/**
* Create a factory of higher order components that render the specified inner
* component using the specified mapping of property names to the streams that
* feed them values and the specified mapping of callback property names to
* the buses onto which the callbacks' first parameter is pushed when called.
*
* This is similar in concept to react-redux's connect() function, but for
@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 / 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 / .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