Skip to content


Getting Postgres up on Docker

This took me a while to figure out from scratch. The most important thing is to know that docker pull postgres retrieves an image from the main Docker registry.

After you retrieve the image, you run a container with parameters, which are used in its entrypoint file, to set up a database. But you still have to know to mount a volume from the “host” (the physical machine) and to expose ports.

docker run -p 5432:5432 --rm --name postgres_container -d -v /var/www/postgres_data:/var/lib/postgresql/data -e POSTGRES_DB=yourdb -e POSTGRES_USER=youruser -e POSTGRES_PASSWORD=yourpassword postgres

Note here that postgres (the last argument to run) is the name of the image which is what you get when you run the pull from Docker.

Google Spreadsheet: The Gateway Drug of Programming

You might not know it, but if you have used Google Spreadsheet (or its much more powerful equivalent, Microsoft Office Excel), you have already programmed. And if you like using these products a lot, then you know you are hooked! It’s a sure way to find out if you are a nerd in hiding – if a pivot table makes you excited, you know you will come jonesing back for more.

Read More →

Javascript Regex Cheatsheet

I always forget how to do this:

r = /^[^0-9]+/;
regex = new RegExp('^[^0-9]+', 'g');
/* The 'g' can be used in replace later. */
string = '1a';

me = 'b2';

/* these return false and null, respectively */


/* this returns true and an Array of matches respectively */



Then how about capture groups – you can’t iterate over them in one go, that’s the problem, you have to do it via exec() which you run multiple times on the same str variable, weirdly enough. The return value is an array with always just two elements: the entire match and the capture group match.

let str = '<h1>Hello, world!</h1> <h1>Hello1, world!</h1> <h1>Hello3, world!</h1>';
let reg = /<h1>(.*?)<\/h1>/g;
let match;
while (match = reg.exec(str)) {


Voila – you get first the 2 elements, “<h1>Hello, world!</h1>” and “Hello, world!” and then the two elements, “<h1>Hello1, world!</h1>” and “Hello1, world!” and so on


This is a method on String, not in Regex. Bah.

'abc12ab1'.replace1)new RegExp('\d', 'g', 'N');

This should give you ‘abcNNabN’

References   [ + ]

1. new RegExp('\d', 'g'