Skip to content

Instantly share code, notes, and snippets.

@LouisRitchie
LouisRitchie / on-migrations.md
Last active February 19, 2020 05:19
On data migrations, the immutability of migrations

Migrations

Migrations are immutable. We run them once, and then they're done for good. The idea that migrations are reversible

  • the "up" and "down" pattern that you find in, for example, Rails and Phoenix - is not something you should build a workflow on. Rolling back migrations should happen only when you made a mistake in a migration & need to revert the database and it's data to a previous schema version.
@LouisRitchie
LouisRitchie / postgres_db_url_template.sh
Last active January 7, 2020 19:00
Template for database url using postgres protocol
DATABASE_URL="postgres://myuser:mypass@localhost:port/somedatabase"
# alex ffmpeg suggestion
alias gif='tmppalette=/tmp/palette.png; tmpvid=/tmp/cap.mp4; rm -f ; ffmpeg -video_size 1920x1080 -framerate 25 -f x11grab -i :100.0+0,0 && ffmpeg -ss 5.0 -i -filter_complex [0:v] palettegen && ffmpeg -ss 5.0 -i -i -filter_complex [0:v][1:v] paletteuse output.gif'
# simple example featuring scaling and speedup by 1/0.4 = 5/2
ffmpeg -i input.mkv -filter:v scale=720:-1 -filter:v "setpts=0.4*PTS" output.gif
@LouisRitchie
LouisRitchie / gist:5b0e5fb9fb9d098dc0064ebe52590069
Created November 30, 2018 18:57
content editable in browser - create browser text area by typing into address bar
data:text/html, <html contenteditable>
" search and replace over all files in directory & subdirectories
find ./ -type f -exec sed -i -e 's/apple/orange/g' {} \;
@LouisRitchie
LouisRitchie / run_shell_from_javascript.js
Created June 15, 2018 02:14
Run shell from javascript. Want to call a bash script with many varied args? Put arg sets into JSON, `require('./my.json')`, form the command string and run it. Used with https://gist.github.com/LouisRitchie/9a90badb920bea29c65100a757b1c95d to get chapters from a book.
const { exec } = require('child_process')
const fs = require('fs')
const SCRIPT_FILENAME = 'split_chapter_into_filename.sh'
function executeChildProcess(command, shouldLog) {
const dir = exec(command, (err, stdout, stderr) => {
if (shouldLog) {
console.log(stdout)
}
@LouisRitchie
LouisRitchie / get_chapter_from_djvu.sh
Last active June 15, 2018 02:16
A script that takes a .djvu file and generates another .djvu using the given page range. You can run this many times with https://gist.github.com/LouisRitchie/a797882ce9b934b2f08a649bf7261776 to a bunch of chapters out of a djvu.
# USAGE: ./script.sh [input file] [start page] [end page] [output file]
# Using this script asynchronously would be extremely painful
# > you're a big guy
# for you
input_file=$1
output_file=$4
start_page=$2
end_page=$3
@LouisRitchie
LouisRitchie / server.go
Last active April 30, 2018 06:43
The modified server.go file that is required to use the Battlesnake 2019 Board https://github.com/LouisRitchie/battlesnake-2019-board
package api
import (
"context"
"encoding/json"
"io/ioutil"
"net/http"
"strconv"
"time"