Skip to content

Instantly share code, notes, and snippets.


david kaye dfkaye

View GitHub Profile
dfkaye / make-it-work.txt
Created Nov 5, 2020
It would be nice if null and undefined were autoboxed in JavaScript, using parentheses.
View make-it-work.txt
4 November 2020
Objects are objects, and so are functions. OK.
Null and Undefined however cannot be autoboxed, so to speak. If we had autobox on them, using parentheses, life would improve.
// whereas
Object(1).valueOf(); // 1
Object(1).toString(); // "1"
Object(1) // "Number"
dfkaye /
Last active Oct 23, 2020
Testing Private Functions in JavaScript: 1) Don't, and 2) Use the Function() constructor

Testing Private Functions in JavaScript

Just Don't

Do not test private functions. Test your public API.

If you must...

If private functions require testing, you can use one of three approaches I know.

dfkaye / numeric-separator-tests.js
Created Oct 11, 2020
JavaScript Numeric Separator test cases
View numeric-separator-tests.js
// 11 Oct 2020
// tl;dr
// Numeric separators are parsed on numbers, not on string arguments passed to the Number constructor.
// JSON.stringify({ value: NaN }) returns "{"value":null}".
/* Test it out */
var tests = [
dfkaye / github-inactive-days-bookmarklet.html
Created Sep 17, 2020
github inactive days bookmarklet
View github-inactive-days-bookmarklet.html
<h1>Github Inactive Days Bookmarklet</h1>
<!-- hat tip to -->
<!-- all inspired by trolling tweet by Hays Stanford, -->
<p> Drag this bookmark -> <a class="bookmarklet" href="javascript:c=[];m=Math;d=document;q='querySelectorAll';d[q]('.contrib-legend li').forEach(li=>{c.push(});d[q]('g rect').forEach(i=>{i.setAttribute('fill', '#ebedf0')});">&lt;100 Hours A Week&gt;</a> to your bookmarks bar.</p>
<p>Then visit your github profile and click that bookmark!</p>
dfkaye /
Last active Nov 3, 2020
Ferret's nicknames for Trump and his regime

Nicknames for Trump and the regime

Dreamed up and repeated by Ferret on [].

The Donald

  • President Dotard
  • Hairplug Himmler
  • Shart Garfunkel
  • the Turd Reich

Bookmarking Allen Holub's tweet for future reference.

"But since...those who study the Classics are unable to penetrate and synthesize them...mistaking accumulated error for truth, I fear my words may not be sufficient to arrest this decline." --Dai Zhen (aka Tai Chen).

dfkaye / safer-math-avg.js
Last active Sep 9, 2020
safe-math-avg.js ~ safer numeric average computation
View safer-math-avg.js
* Update 17 August 2020:
* Now part of safe math blog post at
* Test suite at
// 14 August 2020
// Returns the average of a list of functionally numeric values.
dfkaye /
Last active Aug 7, 2020
This is a personal attack on Object-oriented thinking to the exclusion of all else.


This is a personal attack on Object-oriented thinking to the exclusion of all else.

OOP makes every value an object that must subscribe to publishers and offer its own notification API.

Value(42).on('change', ([previous, next]) => { `OMG the value changed from ${previous} to ${next}` });

Wait, what's wrong with that? Why wouldn't I want that?

You can’t perform that action at this time.