Skip to content

Instantly share code, notes, and snippets.

View espadrine's full-sized avatar

Thaddée Tyl espadrine

View GitHub Profile
@espadrine
espadrine / sync-stdin.js
Created September 12, 2014 11:32
How to read stdin synchronously in nodejs.
var fs = require('fs');
// Returns a buffer of the exact size of the input.
// When endByte is read, stop reading from stdin.
function getStdin(endByte) {
var BUFSIZE = 256;
var buf = new Buffer(BUFSIZE);
var totalBuf = new Buffer(BUFSIZE);
var totalBytesRead = 0;
var bytesRead = 0;
@espadrine
espadrine / README.md
Created February 12, 2021 18:52
Birthday paradox on Slack username colors.

You might know the birthday problem: “it only takes 23 people so that two have the same birthday”.

But do you know the Slack username color problem?

Slack gives random colors to each user in compact view. But there’s only 51 colors to choose from, so as soon as you are 9 in a channel, odds are that two share the same color.

BEGIN MESSAGE.
Tx74RVCgXiswTvD yeKGImuFXka2Y2x JKalxOHiQXtBEl7 qPCoctF82Th5Gpi
0lnxdLk5s0Tjzuk v4cuJ7BDnCjTCKq 6Xr2MZHgg6UyBLH zqZDdsfvbTLAC6D
CifYELzwhOiJaIA 8uXBbOLbUUhC4MD ox0043eX0QUhQbG zamauzRNZReGGDG
7hg8Hz4u226E7Ic bW4xOd900EAZRvN Mjs7629HFxl.
END MESSAGE.
@espadrine
espadrine / OutputBigCrush
Last active April 19, 2020 13:03
Harmonoise PRNG
./harmonoise-big-crush
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Starting BigCrush
Version: TestU01 1.2.3
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
***********************************************************
Test smarsa_SerialOver calling smultin_MultinomialOver
@espadrine
espadrine / perl6.js
Created June 19, 2015 11:30
Perl6 CodeMirror syntax highlighting mode
// Parts from Ace; see <https://raw.githubusercontent.com/ajaxorg/ace/master/LICENSE>
CodeMirror.defineMode("perl6", function(cmCfg, modeCfg) {
// Fake define() function.
var moduleHolder = Object.create(null);
// Given a module path as a string, create the canonical version
// (no leading ./, no ending .js).
var canonicalPath = function(path) {
return path.replace(/\.\//, '').replace(/\.js$/, '');
@espadrine
espadrine / rr.sh
Created January 1, 2019 12:30
Trying to use rr for debugging https://github.com/espadrine/tree-array
$ rr record cargo test
rr: Saving execution to trace directory `/home/tyl/.local/share/rr/cargo-4'.
Finished dev [unoptimized + debuginfo] target(s) in 0.01s
Running target/debug/deps/bench_insert-8cb017bd9e593f1f
running 5 tests
test tests::bench_insert_list ... ok
test tests::bench_insert_vec ... ok
test tests::test_insert_list ... ok
test tests::test_insert_tree_array ... FAILED
@espadrine
espadrine / new.js
Last active March 20, 2016 12:05
Potential new ScoutCamp API
// Server demo. `node app [PORT [https]]`
// © 2011-2016 Thaddée Tyl, Jan Keromnes. LGPL.
let port = +process.argv[2] || +process.env.PORT || 1234
let camp = require('./lib/camp.js')
let sc = camp.start({port: port, secure: process.argv[3] === 'https'})
console.log('http://[::1]:' + port)
// Templating demo: /template.html?title=Hello&info=[Redacted].
sc.path('template.html')
@espadrine
espadrine / tokenizer.js
Last active February 23, 2016 01:51
Raw tokenizer taken from Esprima.
/*
Copyright (C) 2013 Ariya Hidayat <ariya.hidayat@gmail.com>
Copyright (C) 2013 Thaddee Tyl <thaddee.tyl@gmail.com>
Copyright (C) 2013 Mathias Bynens <mathias@qiwi.be>
Copyright (C) 2012 Ariya Hidayat <ariya.hidayat@gmail.com>
Copyright (C) 2012 Mathias Bynens <mathias@qiwi.be>
Copyright (C) 2012 Joost-Wim Boekesteijn <joost-wim@boekesteijn.nl>
Copyright (C) 2012 Kris Kowal <kris.kowal@cixar.com>
Copyright (C) 2012 Yusuke Suzuki <utatane.tea@gmail.com>
Copyright (C) 2012 Arpad Borsos <arpad.borsos@googlemail.com>
[![stability 0 - deprecated](http://b.adge.me/:stability-0_--_deprecated-red.svg)
](http://nodejs.org/api/documentation.html#documentation_stability_index)

stability 0 - deprecated

@espadrine
espadrine / color-cheat-golf.js
Last active January 3, 2016 19:29 — forked from jankeromnes/color-cheat-golf.js
Cheat on <http://www.colormunki.com/game/huetest_kiosk>. How to get the best score, how to get the worst score.
for(i=0;++i<5;)for(j=2;++j<22;)eval('a=patch_'+i+'_'+j).parentNode.appendChild(a)