Skip to content

Instantly share code, notes, and snippets.

Avatar

Pelle Wessman voxpelli

View GitHub Profile
@voxpelli
voxpelli / all.txt
Created Oct 26, 2021
Takes a Blue Oak Council Copyleft JSON file and outputs it in a format that can be copy and pasted into the GitHub organization insights query https://blueoakcouncil.org/copyleft.json
View all.txt
license:CDDL-1.0
license:CDDL-1.1
license:CPL-1.0
license:EPL-1.0
license:EPL-2.0
license:ErlPL-1.1
license:IPL-1.0
license:LGPL-2.0-only
license:LGPL-2.0-or-later
license:LGPL-2.1-only
@voxpelli
voxpelli / starship.toml
Created Oct 13, 2021
my starship config
View starship.toml
format = """
$username\
$hostname\
$shlvl\
$directory\
$git_branch\
$git_commit\
$git_state\
$git_status\
$aws\
View html-safe-json-2.js
// My own take
const JSON_ESCAPE = {
'&': '\\u0026',
'>': '\\u003e',
'<': '\\u003c',
'\u2028': '\\u2028',
'\u2029': '\\u2029'
};
@voxpelli
voxpelli / .zshrc
Created Aug 13, 2021
My history setup in zsh
View .zshrc
# **** History setup ****
setopt EXTENDED_HISTORY
# share history across multiple zsh sessions
setopt SHARE_HISTORY
# append to history
setopt APPEND_HISTORY
# adds commands as they are typed, not at shell exit
setopt INC_APPEND_HISTORY
# expire duplicates first
@voxpelli
voxpelli / template-tag-factory.js
Created Jan 22, 2020
A small little helper for creating a template tag where one can modify the static strings, the values and/or the final output in some way. Eg. trim some whitespaces?
View template-tag-factory.js
/**
* @template T
* @param {T} value
* @returns {T}
*/
const passthrough = value => value;
/**
* @param {object} [options]
* @param {(value: string) => string} [options.staticCallback]
View resolve-value.js
// Used in real world eg. here: https://github.com/voxpelli/node-format-microformat/blob/5381268dbcdb1aef6a5757758710e4b9f75cbea3/index.js#L72-L78
// Works
/** @typedef {null|undefined|boolean|string|number|Array} NonObject */
/**
* @template T
* @typedef {T|Promise<T>} MaybePromised
@voxpelli
voxpelli / parse_fb_ua.js
Last active Jun 11, 2019
Experiment in parsing the extra data that Facebook sends in its User Agent string
View parse_fb_ua.js
const fbUserAgentPattern = /\]|(?:[\;\[](?=FB|$]))/;
const parseFbUserAgentOptions = (input) => input.split(fbUserAgentPattern)
.filter(text => text.startsWith('FB'))
.reduce(text => {
const [ name, value ] = text.split('/');
return { name, value };
}, result);
const prettifyFbUserAgentOptions = (fbUserAgentOptions) => fbUserAgentOptions.map(({name, value}) => name + ': ' + value).join('\n');
@voxpelli
voxpelli / gource-gravatar.js
Created Jun 26, 2018
Download Gravatars for all authors of a git repo and save in folder. Useful when combined with Gource. Node.js CLI script.
View gource-gravatar.js
#!/usr/bin/env node
'use strict';
// Inspired by https://github.com/acaudwell/Gource/wiki/Gravatar-Example
const { execSync } = require('child_process');
const crypto = require('crypto');
const https = require('https');
const fs = require('fs');
@voxpelli
voxpelli / bunyan-setup.js
Created Aug 2, 2017
Part of custom Bunyan setup with Logstash output, as used by HD-Sydsvenskan
View bunyan-setup.js
const bunyan = require('bunyan');
const bunyanExpressSerializer = require('bunyan-express-serializer');
const LogstashStream = require('./logstash-stream');
const streams = [
{
level: 'trace',
type: 'raw',
stream: new LogstashStream(outStream)
View README.md

Test case for duplicate downloads of Link Preloads

  1. Download package.json and single-preload.js and put into same folder
  2. Run npm install
  3. Run node single-preload.js
  4. Visit http://127.0.0.1:4000/ using Safari Technology Preview 24 with the Link Preload experimental feature activated
  5. Check the Network tab of the web development tools. See two style.css that's loaded