Skip to content

Instantly share code, notes, and snippets.

View ricardobeat's full-sized avatar

Ricardo Tomasi ricardobeat

View GitHub Profile
@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 / 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 / coordenadas_estados_BR.js
Created November 12, 2010 20:46
Coordenadas dos estados do brasil (centralizado, não capitais)
{
AC: [ -8.77, -70.55]
, AL: [ -9.71, -35.73]
, AM: [ -3.07, -61.66]
, AP: [ 1.41, -51.77]
, BA: [-12.96, -38.51]
, CE: [ -3.71, -38.54]
, DF: [-15.83, -47.86]
, ES: [-19.19, -40.34]
, GO: [-16.64, -49.31]
@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 / git-find
Created July 14, 2014 16:00
File search using git ls-files with relative path output.
git ls-files | grep $1 | sed s%`git rev-parse --show-prefix`%%
@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 / intro.md
Created July 12, 2013 02:04
Powerline-style bash prompt
@ricardobeat
ricardobeat / dragDropData.js
Created January 10, 2013 17:52
Pass any kind of object via .dataTransfer (drag & drop API)
/*
Easy way to "transfer" any native objects with the Drag & Drop API
@ricardobeat
$('.draggable').on('dragstart', function(e){
App.dragData.set(e, {
type: 'blablabla'
, items: [1,2,3]
})
@ricardobeat
ricardobeat / bandwidth.sh
Created July 17, 2013 20:01
Throttle localhost bandwidth
# First add a rule for all local traffic to port 80 to go into pipe 1
# 100 is the rule number which will be used for referencing the rule later
sudo ipfw add 100 pipe 1 ip from 127.0.0.1 to 127.0.0.1 dst-port http
# To display the rule use
# sudo ipfw show 100
# configure the settings of the pipe as you please
# 50kbit/s bandwidth
sudo ipfw pipe 1 config bw 50Kbit