Skip to content

Instantly share code, notes, and snippets.

View MiracleBlue's full-sized avatar

Nicholas Kircher MiracleBlue

  • Founder & CEO, Zircat - @zircat-dev
  • Melbourne, Australia
View GitHub Profile
@MiracleBlue
MiracleBlue / time-format-test.js
Last active December 16, 2015 01:28
Simple fuzzing unit testing example with Ember CLI and Ember Mocha
/* jshint expr:true */
import { expect } from 'chai';
import {
describe,
it
} from 'mocha';
import {
convertTimeTo12
} from 'digital-court-results/helpers/time-format';
@d-akara
d-akara / JavaScriptSafeNavigation.md
Last active April 11, 2024 16:18
JavaScript Safe Navigation

Experimental Safe JavaScript Navigation

Implemented using ES6 Proxies and Symbols

The purpose of this function is to provide a way to avoid deep nested conditionals when traversing a hierarchy of objects. Some languages use an operator such as '?.' to perform this capability. This is sometimes called safe navigation or null conditional operators.

You can somewhat think of this as how a xpath select works. If any nodes along the path are not found, your result is simply not found without throwing an exception and without needing to check each individual node to see if it exists.

Suggestions for improvements welcome!

// So this is fking incredible. Its actually possible to
// do totally immutable state inside a generator.
// No mutations. No 'let's. No shame!
function* range(start, end, step = 1, current = start) {
yield current;
if (current < end) yield* range(start, end, step, current + step);
}
// In the name of the Turing, and of the Crockford, and of the holy Atwood, Amen.
console.log(...range(5, 15));
@robdodson
robdodson / index.html
Last active October 4, 2023 18:57
Shady DOM example
<!DOCTYPE html>
<html lang="en">
<head>
<title></title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<h2>Hello from outside the Shadow DOM!</h2>