Skip to content

Instantly share code, notes, and snippets.

View ricardobeat's full-sized avatar

Ricardo Tomasi ricardobeat

View GitHub Profile
@ricardobeat
ricardobeat / shape-extract.mjs
Last active July 3, 2024 13:07
Extract SVG shapes from a draw.io mxlibrary file
import fs from 'node:fs'
import path from 'node:path'
let opts = {}
process.argv.forEach(function (val, index, array) {
if (val.startsWith('--')) {
opts[val.slice(2)] = process.argv[index+1]
}
});
@ricardobeat
ricardobeat / sequential-test.js
Created March 8, 2024 09:35
Sequential test based on Evan Miller's
function sequentialTest(control, treatment, sample) {
if (treatment - control >= 2.25 * Math.sqrt(sample)) {
return 'treatment wins'
} else if (control - treatment >= 2.25 * Math.sqrt(sample)) {
return 'control wins'
} else if (treatment + control >= sample) {
return 'stop test. no winner'
}
return 'continue testing'
@ricardobeat
ricardobeat / assignment-FNV-multi-variant.js
Last active April 8, 2024 12:14
Experiment assignment for Cloudfront
const BUCKETS = 120 // multiple of 3 for correct split on 3-variant experiments
const seed = '8fc40cab' // random seed, change to reallocate users
function hashFNV(s, h = 0x811c9dc5) {
for (let i = 0; i < s.length; i++) {
h ^= s.charCodeAt(i);
h += (h << 1) + (h << 4) + (h << 7) + (h << 8) + (h << 24);
}
return h >>> 0;
}
@ricardobeat
ricardobeat / lodash-group-by-unrolled.js
Created December 19, 2023 21:53
lodash 'simple group by'
// https://github.com/lodash/lodash/blob/4.17.15/lodash.js#L9393C5-L9399C8
var groupBy = createAggregator(function(result, value, key) {
if (hasOwnProperty.call(result, key)) {
result[key].push(value);
} else {
baseAssignValue(result, key, [value]);
}
});
// https://github.com/lodash/lodash/blob/4.17.15/lodash.js#L4818C5-L4825C6
@ricardobeat
ricardobeat / Brewfile
Last active October 25, 2022 14:32
Mac CI runner
brew 'coreutils'
brew 'tmux'
brew 'jq'
brew 'htop'
brew 'wget'
brew 'tree'
brew 'aria2'
brew 'xcbeautify'
brew 'git'
@ricardobeat
ricardobeat / index.html
Created September 10, 2018 09:21
Inline event attributes benchmark
<!doctype html>
<body></body>
<script>
const events = [
'click',
'input',
'change',
'mouseenter',
'mouseleave',
@ricardobeat
ricardobeat / task.js
Last active November 4, 2020 18:02
Taks sample
const { task, read, write } = require('taks')
const _postcss = require('postcss')
const _rollup = require('rollup')
const _uglify = require('uglify-es')
const postcss = task.plugin(async function (input, output, options) {
let opts = Object.assign({ from: undefined, plugins: [] }, options)
let src = await read(input)
let { css } = await _postcss(opts.plugins).process(src, opts)
return write(output, css)
@ricardobeat
ricardobeat / task.js
Last active November 4, 2020 10:27
minimal task runner
#!/usr/bin/env node
const _tasks = {}
function task (name, fn) {
_tasks[name] = fn
}
task.run = async function (name, wait) {
if (!name) return console.warn(`Usage: node task [name]`)
if (!_tasks[name]) return console.warn(`No task named ${name}`)
@ricardobeat
ricardobeat / search.sh
Created April 10, 2017 14:47
Git: digging for lost code - unlabeled stashes etc
git fsck --no-reflogs | awk '/dangling commit/ {print $3}'| while read hash; do
echo "$hash"
git show $hash | grep -H -C4 svg
done