Skip to content

Instantly share code, notes, and snippets.

Avatar

david kaye dfkaye

View GitHub Profile
@dfkaye
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).constructor.name // "Number"
@dfkaye
dfkaye / private-test.md
Last active Oct 23, 2020
Testing Private Functions in JavaScript: 1) Don't, and 2) Use the Function() constructor
View private-test.md

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
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 = [
1111222333,
@dfkaye
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 https://codepen.io/lyle/pen/mdPGEKN -->
<!-- all inspired by trolling tweet by Hays Stanford, https://twitter.com/haysstanford/status/1306209477226569729 -->
<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(li.style.backgroundColor)});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
dfkaye / ferrets-nicknames-for-trump-and-regime.md
Last active Nov 3, 2020
Ferret's nicknames for Trump and his regime
View ferrets-nicknames-for-trump-and-regime.md

Nicknames for Trump and the regime

Dreamed up and repeated by Ferret on [showercapblog.com].

The Donald

  • President Dotard
  • Hairplug Himmler
  • Shart Garfunkel
  • the Turd Reich
View dai-zhen-tai-chen-quote.md

Bookmarking Allen Holub's tweet for future reference.

https://twitter.com/allenholub/status/1289389657080225792

"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
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 https://dfkaye.com/posts/2020/08/17/safer-math-operations-in-javascript-using-tdd/
* Test suite at https://dfkaye.com/demos/safe-math-test-suite/
*/
// 14 August 2020
// Returns the average of a list of functionally numeric values.
@dfkaye
dfkaye / value-onchange-previous-next-api.md
Last active Aug 7, 2020
This is a personal attack on Object-oriented thinking to the exclusion of all else.
View value-onchange-previous-next-api.md

Reminder

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.