Skip to content

Instantly share code, notes, and snippets.

View glenjamin's full-sized avatar

Glen Mailer glenjamin

View GitHub Profile
@glenjamin
glenjamin / docker-compose.yml
Last active November 5, 2025 15:35
Postgres slice value/scanning
services:
postgres:
image: "postgres:16.3"
environment:
POSTGRES_HOST_AUTH_METHOD: trust
PGUSER: postgres # make it so `exec psql` works
ports:
- "127.0.0.1:5432:5432"
@glenjamin
glenjamin / pool-transaction.js
Last active October 3, 2025 01:54
DB transaction from a connection pool in node-mysql
var mysql = require('mysql');
var pool = mysql.createPool('mysql://localhost');
inTransaction(pool, function(db, next) {
db.query("DELETE * FROM stuff", function(err) {
if (err) return next(err);
db.query("INSERT INTO stuff VALUES (1,2,3)", function(err) {
return next(err);
@glenjamin
glenjamin / bookmarklet.md
Last active February 26, 2025 09:23
Honeycomb E&S Environment toggle bookmarklet

Honeycomb env-switching bookmarklet

This will toggle between the staging and production environments by default. Adjust the naming if that isn't what yours are called.

Setup

Create a bookmark named "Honeycomb Environment Switcher"

Set the target URL as the following, which is the content from full.js with newlines and indents removed.

{
"absolute": true,
"item": [
{
"text": "",
"value": [null, "2024-12-25T00:00:00Z"]
}
]
}
@glenjamin
glenjamin / http_tls_test.md
Created January 21, 2022 15:29
Testing an HTTP client that makes encrypted requests to a server you don't control

Here's neat testing trick I've just come across.

I've got an HTTP client that makes requests to https://accounts.google.com.

So I create a fake HTTP server:

srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
/// ...
})
@glenjamin
glenjamin / react-raf-batching.js
Last active August 17, 2021 14:33
requestAnimationFrame batching
/*eslint-env browser*/
/**
* Cribbed from:
* github.com/facebook/react/blob/master/src/addons/ReactRAFBatchingStrategy.js
* github.com/petehunt/react-raf-batching/blob/master/ReactRAFBatching.js
*/
var ReactUpdates = require('react/lib/ReactUpdates');
var ReactRAFBatchingStrategy = {
@glenjamin
glenjamin / on-testing.md
Created August 7, 2021 20:07
Testing blogpost intro

How I do automated tests

There’s a lot of posts out there where people will tell you how to do something. How you must do something in a certain way. How you’re not a real developer unless you do things in this particular way. I hate that sort of post.

I strongly believe that there isn’t such a thing as a best practice. There are effective practices that work well in certain contexts, but might be less effective in other contexts - although I’m pretty confident that some practices aren’t effective in any context. I do, however, think there’s a lot of value to be found in taking a practice that’s successful in one context, and finding ways to adapt or generalise it into more contexts.

So with those caveats out of the way, here’s a post that tries to explain and justify how I personally write my automated tests. These approaches have been shaped over the years by my own experiences but also by the opinions of my colleagues and how well (or not) we’ve seen them work.

The techniques I’m writing about here

@glenjamin
glenjamin / records.js
Last active May 4, 2020 16:50
Flow types for immutable records.
/* @flow */
import * as I from "immutable";
/**
* Define an immutable record intended for holding reducer state
* @param spec - the keys and their default values
* @return a state record factory function
*/
export function defineRecord<T: Object>(
@glenjamin
glenjamin / .kitchen.yml
Created September 28, 2015 20:48
Systemd in a container! Useful for testing services controlled by chef
---
driver:
name: docker
provision_command:
- yum -y swap -- remove systemd-container systemd-container-libs -- install systemd
- systemctl enable sshd.service
- curl -L https://www.opscode.com/chef/install.sh | bash
require_chef_omnibus: false
run_command: /usr/sbin/init
privileged: true
@glenjamin
glenjamin / routing.js
Last active January 13, 2017 21:13
Which of these do you prefer for a component-wrapping API? please comment below!
// The hypothetical <Routing /> component would pass extra props to <App /> to say which route is active
// 1. Wrapped component accepts component class and passes on props plus extras
<Routing
rootComponent={App}
propForApp="abc"
propForApp2="def"
/>
// 2. Wrapped component takes children and uses cloneElement to pass extra props