Skip to content

Instantly share code, notes, and snippets.

View mfdj's full-sized avatar
calculating infinity

Mark Fox mfdj

calculating infinity
View GitHub Profile
@mfdj
mfdj / install-kaleidoscope-3.9.sh
Last active July 18, 2023 07:08
Homebrew cask for kaleidoscope 3.9,2176
brew reinstall --cask kaleidoscope.rb
@mfdj
mfdj / make-sure-to-reject-an-Error-object.js
Created July 19, 2021 22:21
jest await expect(testSubject()).rejects.toThrow expects the rejected value to be an Error object otherwise just use `rejects.toMatch`
// test subjects
const rejectsStringValue = () => Promise.reject('I rejected');
const rejectsErrorValue = () => Promise.reject(new Error('I rejected'));
// tests
describe('rejectsStringValue', () => {
it('will throw in try/catch', async () => {
@mfdj
mfdj / why-alphanumeric.md
Last active September 17, 2024 21:37
Alphabetize your set items and map keys

Alphabetize your set items and map keys

This document looks at certain data-structures and makes the case for alphanumeric ordering to optimize developer experience (DX).

Strategies for organizing code

Authoring code, like all language, is about expressing ideas intentionally and legibly. Obviously code needs to be correct for the computational device, and succeed as a software product, but we also want to make it comprehensible to human colleagues.

To make code comprehensible I can identify four distinct organizational strategies:

@mfdj
mfdj / esm-object-export-is-a-shared-reference.md
Last active June 7, 2021 21:28
ECMAScript modules (ESM): Yes, when you export an object the reference is shared across all usages
$ node index.mjs
🌞 module-a pre-export { name: 'module-a 🌞', obj: { a: '🇨🇦', b: 'bee', c: 'see' } }
👻 module-b pre-export { name: 'module-b 👻', obj: { a: '🇨🇦', b: '🐝', c: 'see' } }
{
  moduleA: { name: 'module-a 🌞', obj: { a: '🇨🇦', b: '🐝', c: '👀' } },
  moduleB: { name: 'module-b 👻', obj: { a: '🇨🇦', b: '🐝', c: '👀' } },
  moduleObjectExport: { a: '🇨🇦', b: '🐝', c: '👀' }
}
@mfdj
mfdj / a.mjs
Last active September 15, 2020 19:17
module level static data
const STATE = { counter: 0 };
export { STATE };
@mfdj
mfdj / capybara-webkit-install.sh
Created July 27, 2020 04:54
installing capybara-webkit on Catalina
# installing capybara-webkit on Catalina via Monitor wiki
brew update
cd $(brew --prefix)/Homebrew/Library/Taps/homebrew/homebrew-core
git show 9ba3d6ef8891e5c15dbdc9333f857b13711d4e97 > /dev/null || git fetch --unshallow
git checkout 9ba3d6ef8891e5c15dbdc9333f857b13711d4e97 Formula/[email protected]
type -a gsed || brew install gnu-sed
gsed -i 's/depends_on :macos => :mountain_lion//' Formula/[email protected]
brew install [email protected]
# now gem install capybara-webkit -v '1.15.1' will work
@mfdj
mfdj / ghost_dog.js
Last active January 17, 2020 21:02
mocking-required-code-in-jasmine
export const log = function() {
return "ghost-dog";
};
export const blob = function() {
return "blee-bloop";
};
/*
@mfdj
mfdj / logReadableStream.js
Last active June 19, 2021 04:57
General use body-logger to use with browser fetch - riffing on https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream/getReader
/*
fetch('http://example.com')
.then(res => res.ok ? logReadableStream(res.body) : Promise.reject(`Status: ${res.status}`))
.catch(console.log)
*/
let logReadableStream = function (stream) {
const reader = stream.getReader();
let bytesReceived = 0;
let result = new Uint8Array(0);
@mfdj
mfdj / macos-newrelic-php-extension-install-steps.sh
Last active August 30, 2017 19:25
Install New Relic PHP extension on macOS
# Grabbed archive from https://download.newrelic.com/php_agent/release/ and decompressed
gzip -dc newrelic-php*.tar.gz | tar xf -
cd newrelic-php*/
# manually edited newrelic-install to not use sudo because it's contrary to how Homebrew (and thus most of my system) behaves
# Homebrew'd PHP doesn't use PHP's typical extensions folder so I created it manually (note path is dependent on php version)
mkdir -p /usr/local/Cellar/php70/7.0.17_9/lib/php/extensions/no-debug-non-zts-20151012
# run install script with custom paths (since /usr/bin is not writeable because of macOS "system integrity protection")
@mfdj
mfdj / assert.php
Created August 13, 2017 22:03
prove how to safely validate precision
<?php
set_error_handler(function($severity, $message, $filename, $lineno) {
throw new \Error($message, $severity);
});
function strictAssert($expected, $actual) {
if ($actual !== $expected) {
echo PHP_EOL . '✋' . PHP_EOL;
var_dump($actual, $expected);