Skip to content

Instantly share code, notes, and snippets.

View judas-christ's full-sized avatar

Daniel Hägglund judas-christ

View GitHub Profile
@judas-christ
judas-christ / retry.js
Created November 24, 2020 08:24
Retry with exponential backoff
/**
* Execute `work`, retrying up to `retries` times with exponential backoff starting at `delay` ms
* @param {() => Promise} work work to perform.
* @param {number} [retries=5] number of retries before failing.
* @param {number} [delay=250] initial retry delay in milliseconds, increased exponentially for every try.
*/
export async function retry(work, retries = 5, delay = 250) {
for (let tries = 0; tries < retries; tries++, delay *= 2) {
try {
return await work()
@judas-christ
judas-christ / fix-refresh-rate.sh
Last active November 6, 2023 15:15
How to change refresh rate on an external display on macOS
# install homebrew
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
# install cscreen
brew cask install cscreen
# list displays
cscreen -l
# find your external screen in the list and write the number (not the ID) down somewhere
# in the following instructions, use that number instead of <SCREEN>
@judas-christ
judas-christ / kill-gulp-and-jekyll
Last active February 15, 2017 08:54
Run gulp watch and jekyll serve in parallell, kill both with the stroke of a key. Or two.
#!/bin/bash
trap "kill $GULPPID && trap - SIGINT" SIGINT && gulp & GULPPID=$! & bundle exec jekyll serve
@judas-christ
judas-christ / swig-chained-functions-test
Last active August 29, 2015 14:16
Swig template bug with chained instance functions
var swig = require('swig');
var assert = require('assert');
swig.invalidateCache();
var failingTemplate = '{% for child in model.getRoot().getChildren() %}{{ child.getName() }}{% endfor %}';
var workingTemplate = '{% for child in model.getChildren() %}{{ child.getName() }}{% endfor %}';
var expected = 'child';
function Model(name, children) {