Skip to content

Instantly share code, notes, and snippets.

@zapthedingbat
zapthedingbat / bookmarklet.js
Created April 11, 2017 09:00
A bookmarklet source
console.log('bookmarklet');
@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;
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 / 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.

@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 / number-bytes.js
Created May 14, 2019 19:30
converting between numbers and bytes in javascript
function bitLength(number) {
return Math.floor(Math.log2(number)) + 1;
}
function byteLength(number) {
return Math.ceil(bitLength(number) / 8);
}
function toBytes(number) {
if (!Number.isSafeInteger(number)) {
@zapthedingbat
zapthedingbat / watercolors.js
Created November 13, 2019 14:24
Generate watercolor style blobs: Inspired by tyler hobbs's generative watercolors- https://tylerxhobbs.com/
(function(doc) {
const TWO_PI = Math.PI * 2;
const HALF_PI = Math.PI / 2;
const RADIUS_SCALE = 0.05;
const RADIUS_SD = 15;
const POLYGON_SIDES = 5;
const POSITION_SD = 0.04;
const BASE_DEFORMATIONS = 3;
const LAYER_DEFORMATIONS = 3;
const LAYERS = 40;
console.log(process.argv.slice(2).map(b=>[...b].reduce((a,b)=>2*a+("."==b?1:2),0)).map(a=>"-etianmsurwdkgohvf-l-pjbxcyzq--54-3---2--+----16=/-----7---8-90"[a]).join(''))
@zapthedingbat
zapthedingbat / poll-xid.js
Created June 25, 2020 07:41
Poll for the Conde Nast XID and pass it into permutive
(function () {
var interval = setInterval(function () {
var [, xid] = (document.cookie.match(/CN_xi_d=([^;]+)/) || []);
xid = xid || window._4d && window._4d.user && window._4d.user.xid;
if (xid) {
permutive.identify([
{
id: xid,
tag: 'xid'
}
@zapthedingbat
zapthedingbat / vendor-ids.js
Last active November 27, 2020 12:30
Compression and decompression for Google's appallingly inefficient additional consent string
/*
|| Compression and decompression using a combination of
|| Variable-length Quantity(VLQ) and Delta encoding to encode the "Additional
|| Consent" (AC) string required by Google’s Additional Consent Mode technical
|| specification https://support.google.com/admanager/answer/9681920?hl=en
||
|| vendorIds.compress(input)
|| input - A string of "." delimited list if ids in ascending order.
||
|| vendorIds.decompress(input)