Skip to content

Instantly share code, notes, and snippets.

View alfredwesterveld's full-sized avatar

Alfred Westerveld alfredwesterveld

View GitHub Profile
@alfredwesterveld
alfredwesterveld / .env.example
Last active April 30, 2023 07:24
slow down browser
URL=https://xkcd.com/
@alfredwesterveld
alfredwesterveld / .env.example
Last active April 29, 2023 20:21
report vitals on soft refresh (experimental)
URL=https://xkcd.com/
@alfredwesterveld
alfredwesterveld / Makefile
Created March 9, 2021 18:13
makefile chrome-aws-lambda
.PHONY: clean
clean:
rm -f $(lastword $(MAKECMDGOALS))
.fonts.zip:
zip -9 --filesync --move --recurse-paths .fonts.zip .fonts/
%.zip:
mkdir -p nodejs/node_modules/chrome-aws-lambda/
const Jimp = require("jimp")
const {ssim} = require('ssim.js')
Jimp.read("./ref.gif", function (err, image) {
if (err) {
console.log(err)
} else {
const buf = image.getBuffer();
const out = ssim(buf, buf);
console.log(out);
}
#!/bin/bash
# https://stackoverflow.com/questions/965053/extract-filename-and-extension-in-bash
filename=$(basename -- "$1") # $1 is full name
extension="${filename##*.}"
filename="${filename%.*}"
# trace to gif via https://github.com/pmdartus/snapline
echo "Converting $1 to $filename.gif ..."
snapline $1 -f 30 -o "$filename.gif"
@alfredwesterveld
alfredwesterveld / chain.js
Created November 20, 2019 14:22
test chaining sharp
const sharp = require('sharp');
sharp('./3MB.png').resize(400, 400).jpeg({
quality: 1,
force: true
}).webp({
lossless: false,
quality: 50,
force: true
}).toFile('./chain.webp');
@alfredwesterveld
alfredwesterveld / index.js
Last active July 9, 2018 14:08
generate svg filesize
// 6MB => 6291456
const fs = require('fs');
fs.copyFileSync('svg.svg', 'long.svg');
fs.appendFileSync('long.svg', `<!--${'-'.repeat(6 * 1024 * 1024 - 96)}-->`);
@alfredwesterveld
alfredwesterveld / index.js
Created May 4, 2017 16:48
requirebin sketch
const browser = require('detect-browser');
if (browser) {
console.log(browser.name);
console.log(browser.version);
}
@alfredwesterveld
alfredwesterveld / index.js
Created April 28, 2017 11:52
requirebin sketch
var PNG = require('pngjs').PNG
, pixelmatch = require('pixelmatch')
, fabric = require('fabric').fabric
var c1 = new fabric.Canvas('c1')
, getData = document.getElementById('get-data')
, data = document.getElementById('data');
c1.add(new fabric.IText('hi', {
left: 20,
@alfredwesterveld
alfredwesterveld / index.js
Last active April 28, 2017 11:46
requirebin sketch
var PNG = require('pngjs').PNG
, pixelmatch = require('pixelmatch')
, fabric = require('fabric').fabric;
var c1 = new fabric.Canvas('c1')
, c2 = new fabric.Canvas('c2');
var ctx1 = c1.getContext()
, ctx2 = c2.getContext()
, ctx3 = document.getElementById('c3').getContext('2d');