Skip to content

Instantly share code, notes, and snippets.

Actively recommending people not to use WordPress!

Michael Bøcker-Larsen mblarsen

Actively recommending people not to use WordPress!
View GitHub Profile

Pure ESM package

The package linked to from here is now pure ESM. It cannot be require()'d from CommonJS.

This means you have the following choices:

  1. Use ESM yourself. (preferred)
    Use import foo from 'foo' instead of const foo = require('foo') to import the package. You also need to put "type": "module" in your package.json and more. Follow the below guide.
  2. If the package is used in an async context, you could use await import(…) from CommonJS instead of require(…).
  3. Stay on the existing version of the package until you can move to ESM.
ClickerMonkey / types.ts
Last active Nov 11, 2021
Typescript Helper Types
View types.ts
// when T is any|unknown, Y is returned, otherwise N
type IsAnyUnknown<T, Y, N> = unknown extends T ? Y : N;
// when T is never, Y is returned, otherwise N
type IsNever<T, Y = true, N = false> = [T] extends [never] ? Y : N;
// when T is a tuple, Y is returned, otherwise N
// valid tuples = [string], [string, boolean],
// invalid tuples = [], string[], (string | number)[]
tigt / git-branch-to-favicon.js
Created Mar 18, 2020
Creates an SVG string that can be used as a favicon across different Git branches. Actually getting this into the browser is sadly project-specific.
View git-branch-to-favicon.js
const { execSync } = require('child_process')
const { createHash } = require('crypto')
const invertColor = require('invert-color')
const branchName = execSync('git rev-parse --abbrev-ref HEAD')
const hash = createHash('sha256')
const color = '#' + hash.digest().toString('hex').substring(0, 6)
const invertedColor = invertColor(color, true)
tcrowe / src-middleware-authenticated.js
Created Sep 13, 2019
express, sapper, polka authentication idea
View src-middleware-authenticated.js
+ assuming you're using cookie-session or similar session
import authenticated from "./middleware/authenticated.js"
rauschmerscen / laravel laravel-echo laravel-echo-server private channel authentication problems
Last active Nov 3, 2021
Common Problems faced while setting up private channels with laravel-echo & laravel-echo-server.
View laravel laravel-echo laravel-echo-server private channel authentication problems
I'll start with the basics and proceed to addressing the common problems
faced while setting up private channels with laravel-echo & laravel-echo-server.
If you are getting these errors while setup; 401, 403, 419 etc, as I did in my experience.
this gist will help you fix these errors.
Although this gist addresses common problems of laravel-echo-server setup, some problems are similar with Pusher setup.
So it might also be useful if you're having problems with setting up Pusher with Echo.
I'll try to cover eveything and try to use appropriate highlighting to single out each common problem.
OliverJAsh /
Last active Dec 3, 2021
Flexbox gutters

Flexbox gutters


  • We use flexbox for our layout.
  • We want to add horizontal and vertical gutters inbetween these items.
  • Items wrap according to contents (flex-wrap: wrap), therefore we can't decide when/where to apply gutters using breakpoints.


Billz95 / .php_cs.dist
Last active Nov 16, 2021
A Customised fixer for PHP-CS-Fixer to use `prettier`'s php plugin to pre-process the code before getting analysed by other fixers. This would enable `php-cs-fixer` to take advantage of `prettier`'s ability of managing long line.
View .php_cs.dist
require_once __DIR__.'/relative/path/to/PrettierPHPFixer/File';
return PhpCsFixer\Config::create()
(new PrettierPHPFixer()),
'Prettier/php' => true,
View minimal-analytics-snippet.js
(function (context, trackingId, options) {
const history = context.history;
const doc = document;
const nav = navigator || {};
const storage = localStorage;
const encode = encodeURIComponent;
const pushState = history.pushState;
const typeException = 'exception';
const generateId = () => Math.random().toString(36);
const getId = () => {
rogpeppe /
Last active Aug 29, 2021
go get binary@version
# This command installs binaries at specified versions
# into $GOBIN, $GOPATH/bin or $HOME/bin.
# It assumes Go 1.11.
if [ $# = 0 ]; then
usage: vgoget cmdpackage[@version]... >&2
exit 2
d=`mktemp -d`
cd "$d"
View netrw_explorer_toggle.vim
" netrw
let g:netrw_banner = 0 " hide banner
let g:netrw_altv=1 " open splits to the right
let g:netrw_liststyle=3 " tree view
let g:netrw_list_hide=netrw_gitignore#Hide()
function! s:open_netrw()
" Grab the current file name
let file_name = expand("%:t")
" Open a 20-column left-side netrw explorer in the directory for the current