Skip to content

Instantly share code, notes, and snippets.

david kaye dfkaye

Block or report user

Report or block dfkaye

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@dfkaye
dfkaye / format-condition.js
Last active May 21, 2019
format cycle condition strings...
View format-condition.js
// 20 May 2019l
// blecch
var payout = ` transactionType == 'PAYOUT' && sourceAmount.currency == 'YYY' `;
var payin = ` currency == 'USD' && transactionType == 'PAYIN'&& processorName == 'FIRST_DATA' && payInNetwork != 'AMEX' `;
function formatCondition(condition) {
return condition
.split('&&')
@dfkaye
dfkaye / format-currency.js
Last active May 21, 2019
formatCurrency, formatting with exponent and currency
View format-currency.js
// 20 May 2016
// formatCurrency, i18n
/**
* @function formatCurrency accepts an object containing value, currency, and
* exponent fields, and returns a string containing an currency- and exponent-
* based value.
*
* @param {Number} value
* @param {Number} exponent
@dfkaye
dfkaye / react-app-orginal.jsx
Last active May 8, 2019
React app UI refactored - replace spans with anchors, use hrefs, use CSS borders not HRs, delegate to single click handler
View react-app-orginal.jsx
/*
.sidenav .link {
padding: 6px 8px 6px 16px;
text-decoration: none;
font-size: 1.25em;
color: #7B899D;
display: block;
-webkit-transition-duration: 0.25s; /* Safari *\/
transition-duration: 0.25s;
@dfkaye
dfkaye / css-loading-indicator.html
Last active Apr 27, 2019
Accessible CSS-driven "loading" indicator
View css-loading-indicator.html
<!DOCTYPE html>
<html lang="en">
<head>
<title>accessible loading spinner</title>
<!-- see http://pauljadam.com/demos/loading-indicator.html -->
<style nonce="4AEemGb0xJptoIGFP3Nd">
html {
font-size: 1em;
@dfkaye
dfkaye / fibonacci.js
Last active Apr 27, 2019
A return to the "cumulative incremental" fibonacci algorithm in JavaScript that doesn't blow up the callstack
View fibonacci.js
// 23 April 2019
// A return to the "cumulative incremental" fibonacci algorithm in JavaScript that
// doesn't blow up the callstack (see fib4() towards the end for the final version).
// Every "functional programming" fibonacci algorithm example in JavaScript that
// uses the "recursive decrement" strategy is wrong. Creating thunks, trampolines,
// and all the other baloney, just to get around the lack of tail call optimization,
// should tell you that you're not thinking about the *constraints* of the problem.
// If recursion can blow up the callstack, DON'T USE RECURSON. IT'S NOT SAFE.
// USE A DIFFERENT APPROACH.
@dfkaye
dfkaye / undupe.js
Last active Apr 11, 2019
undupe() removes duplicate entries or objects by shape from an array...
View undupe.js
// 7 April 2019
// removes duplicate entries or objects by shape from an array...
// 9 April 2019 - support recursive array dedupe.
// Correction: returns an array of unique entries in an array or an object,
// where the keys are whole numbers, and the key values of the entire path
// through an object structure are unique.
// Safe for arrays, objects, null, undefined, empty strings, and NaN.
@dfkaye
dfkaye / hashcode.js
Last active Apr 20, 2019
javascript implementation of java's string.hashcode() method
View hashcode.js
// 2 April 2019
// hashcode algo
// from http://werxltd.com/wp/2010/05/13/javascript-implementation-of-javas-string-hashcode-method/
// stolen from jjdubray
// see https://medium.com/@metapgmr/hex-a-no-framework-approach-to-building-modern-web-apps-e43f74190b9c
function hashCode(s) {
var h = 0
return !s || !s.length
@dfkaye
dfkaye / june-2019.md
Last active May 22, 2019
dev-links for June 2019
View june-2019.md

June 2019

@dfkaye
dfkaye / Number.toFixed.js
Last active Mar 30, 2019
Updated Number().toFixed() polyfill to add-then-remove the trailing '1' in every case.
View Number.toFixed.js
// 14 March 2019
// Updated Number().toFixed() polyfill to add-then-remove the trailing '1' in every case.
// see original at https://gist.github.com/dfkaye/e977af36e668aa134c0ce55bab5bb15f
// and at https://dfkaye.wordpress.com/2017/12/06/number-tofixed-rounding-errors-broken-but-fixable/
/*
// fixes blog post solution
;(1.005).toFixed(2) == "1.01" || (function(prototype) {
var toFixed = prototype.toFixed
@dfkaye
dfkaye / fraction.js
Last active May 9, 2019
Get the decimal fraction of a value, if coercible to a number; exponent notation supported.
View fraction.js
// 45678901234567890123456789012345678901234567890123456789012345678901234567890
// 14 March 2019 - first cut.
// 18 March 2019 - support expontent notation.
// 19 March 2019 - better comment style, better return style.
// 9 May 2019 - fix 'a.b' ('.b' to '0'), trailing 0's ('.490' to '.49').
// 9 May 2019 - fix Case 2 where e's value is less than the length of the
// remaining mantissa (i.e., use m.substring(e) ), and even
// better documentation.
/**
You can’t perform that action at this time.