Skip to content

Instantly share code, notes, and snippets.

@zapthedingbat
zapthedingbat / tf-idf.js
Created October 19, 2018 14:25
Simple TF-IDF
function getTermKey(term) {
return term
.normalize('NFD')
.replace(/[\u0300-\u036f]/g, "")
.replace(/[^\w]/g, "")
.toLowerCase()
};
function getTermsIn(document) {
return document.split(/[\s_():.!?,;]+/)
@zapthedingbat
zapthedingbat / README.md
Created September 26, 2018 08:24
Example reproduction of wallabyjs missing the setTimeout[util.promisify.custom] property used by the native node util.promisify module.

Example reproduction of wallabyjs missing the setTimeout[util.promisify.custom] property

When running tests in wallaby the setTimeout[util.promisify.custom] property is missing, which causes util.promisify to fail.

Reproduction steps

Running this gist with the command line npm test will result in a passing test.

Array.from(s.split(/\W+/)
.map(a => a.toLowerCase())
.reduce((p, v) => p.set(v, (p.has(v)?p.get(v):0)+1), new Map())
.entries()
)
.sort((a,b) => b[1]-a[1])
.forEach(a => console.log(`${a[0]}:${a[1]}`));
@zapthedingbat
zapthedingbat / Highlight.html
Created May 12, 2017 17:42
Highlight effect on <em> tags
<html>
<head>
<style>
em:before,
em:after{
content: " ";
display: block;
top:0;
bottom: 0;
@zapthedingbat
zapthedingbat / bookmarklet.js
Created April 11, 2017 09:00
A bookmarklet source
console.log('bookmarklet');
@zapthedingbat
zapthedingbat / birthday.js
Created February 24, 2017 11:18
Calculating the probability that a member of a team shares their birthday with someone else in the same team.
//https://en.wikipedia.org/wiki/Birthday_problem#Calculating_the_probability
function p(n){
let a = 1;
for(let i = 0; i < n; i++){
a *= ((365 - i) / 365);
}
return 1 - a;
}
const chance = p(parseInt(process.argv.pop())) * 100;
console.log(`There is a ${chance}% chance of two people in the same team sharing the same birthday`);
const runs = 10;
function run(method, runIndex) {
console.time(`run ${runIndex}`);
return method().then(() => {
console.timeEnd(`run ${runIndex}`);
if (runIndex < runs){
return run(method, runIndex+1);
}
});
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace ZapTheDingbat.IO
{
public class CsvReader : IEnumerable<IReadOnlyList<string>>, IEnumerator<IReadOnlyList<string>>

Keybase proof

I hereby claim:

  • I am zapthedingbat on github.
  • I am zapthedingbat (https://keybase.io/zapthedingbat) on keybase.
  • I have a public key whose fingerprint is 560A 68F0 73EF 2F76 AE8C 014F 35C4 4D58 1084 3365

To claim this, I am signing this object:

@zapthedingbat
zapthedingbat / chromebackbug.html
Last active February 17, 2016 18:04
Chrome Unload Back Bug
<!DOCTYPE html>
<html>
<head>
<script>
window.addEventListener('unload', function(){
var origionalUrl = location.href;
var newUrl = origionalUrl.replace('#.*$', '') + '#nope';
console.log('cancel navigation', newUrl);
window.location.replace(newUrl);
window.location.replace(origionalUrl);