Skip to content

Instantly share code, notes, and snippets.

View voxpelli's full-sized avatar

Pelle Wessman voxpelli

View GitHub Profile
@voxpelli
voxpelli / parse_fb_ua.js
Last active June 11, 2019 20:33
Experiment in parsing the extra data that Facebook sends in its User Agent string
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 June 26, 2018 15:02
Download Gravatars for all authors of a git repo and save in folder. Useful when combined with Gource. Node.js CLI script.
#!/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 August 2, 2017 09:30
Part of custom Bunyan setup with Logstash output, as used by HD-Sydsvenskan
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)

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
@voxpelli
voxpelli / main.js
Last active April 19, 2022 12:43
A recursive Promise.all() that works on objects
const zipObject = function (keys, values) {
const result = {};
keys.forEach((key, i) => {
result[key] = values[i];
});
return result;
};
@voxpelli
voxpelli / keybase.md
Created September 2, 2016 08:12
keybase.md

Keybase proof

I hereby claim:

  • I am voxpelli on github.
  • I am voxpelli (https://keybase.io/voxpelli) on keybase.
  • I have a public key whose fingerprint is 65D3 06C1 79C7 5F64 0B4F 84C2 A62A 96DF E7A1 4F5A

To claim this, I am signing this object:

const stream = {
level: 'warn',
type: 'raw',
stream: { write: (obj) => {
console.log(
[
bunyan.nameFromLevel[obj.level],
obj.msg,
obj.err ? bunyan.stdSerializers.err(obj.err).stack : false
]
@voxpelli
voxpelli / log-chai-error-with-diff.js
Created July 11, 2016 10:12
This small snippet leverages Mocha's reporter to do proper diffs of Chai assertion errors so that one can log them oneself as well
const mochaList = require('mocha').reporters.Base.list;
const mochaErrorLog = function (err, title) {
mochaList([{
err,
fullTitle: () => title || 'Untitled'
}]);
};
@voxpelli
voxpelli / gist:e08600ee1bd1ca254a46ff437e672200
Created May 6, 2016 11:23
git alias to notify on git push fail (works on OS X)
git config --global alias.pushh '!git push $@ || terminal-notifier -message "Push failed" -title "git"'
var validateInstalledDependencies = function () {
var readJson = require('read-package-json');
var readInstalled = require('read-installed');
var semver = require('semver');
var packagePromise = new Promise(function (resolve, reject) {
readJson('package.json', function (err, data) {
if (err) { return reject(err); }
resolve(data);
});