Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@mfdj
mfdj / why-alphanumeric.md
Last active October 5, 2022 16:27
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 any language) is about expressing ideas in an structured, intentional fashion. Obviously it needs to be correct for the computational device, and succeed as a software production, but we also want to make it comprehensible to our fellow humans.

To make code comprehensible I've observed the following stratgeies (I'm sure this list isn't exahustive, but it is tractable):

@sindresorhus
sindresorhus / esm-package.md
Last active April 23, 2024 05:25
Pure ESM package

Pure ESM package

The package that linked you here is now pure ESM. It cannot be require()'d from CommonJS.

This means you have the following choices:

  1. Use ESM yourself. (preferred)
    Use import foo from 'foo' instead of const foo = require('foo') to import the package. You also need to put "type": "module" in your package.json and more. Follow the below guide.
  2. If the package is used in an async context, you could use await import(…) from CommonJS instead of require(…).
  3. Stay on the existing version of the package until you can move to ESM.
@steveklabnik
steveklabnik / oil.md
Last active January 15, 2021 21:32
Why is the price of oil negative?

so, why is oil's price negative?

(note: I am a software developer who has an interest in finance. This is my understanding. I am not a professional.)

first, what does that even mean? so, the "price of oil" is the price of "WTI Crude", which is a specific kind of oil. There are multiple kinds of oil with multiple prices.

Why is it negative? to understand this, we also have to understand why WTI is the price of oil: that is, it's the kind of oil that underpins the New York Mercantile Exchange's oil futures contracts. The NYMEX is kind of like the stock market, but for commodities, aka stuff.

@rstacruz
rstacruz / README.md
Last active April 23, 2024 00:19
Setting up Jest with ESM

Setting up Jest with ESM

Here are some different ways on how to set up Jest to support ESM. This applies for Jest v25, Node v13, and Babel v7.

Method A: Native Node.js support

Node v14 and Jest v26 support ESM natively with the --experimental-vm-modules flag.

Install cross-env:

@TJC
TJC / Basic auth.md
Last active October 3, 2022 21:39
(Simplified) HTTP Basic auth vs MAC signed auth

Client:

username = "alice"
secretKey = "12345"
method = GET
url = "https://example.com/private"

Client sends what it essentially this HTTP request:
method = GET
URL = "https://example.com/private"
@appkr
appkr / howto_install_old_version_of_php.md
Last active September 25, 2021 06:50
How to intall php@7.1 with homebrew in MacOS

Workaround

Register the custom repostory as homebrew tap

~ $ TAP=appkr/homebrew-repo
~ $ brew tap $TAP

Install the binary from the custom repository AS USUAL

@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);
@colby
colby / sandman.sh
Created November 17, 2016 05:49
Put all of your Vagrant VMs to sleep.
#!/usr/bin/env sh
vagrant=$(which vagrant)
awk=$(which awk)
printf "Gathering a list of machines. "
machines=$(vagrant global-status --prune 2>/dev/null | $awk '/running/ {print $5}')
if [ ! -z "${machines[@]}" ]
then
@colby
colby / bump
Last active March 6, 2019 16:56
Bumps a git tag and metadata.rb version for a given Chef cookbook, follows SemVer standards.
#!/bin/bash
set -eo pipefail
semver_regex="^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(\-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?(\+[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$"
usage="\
Usage:
$0
$0 show
@mfdj
mfdj / javascript-undefined.html
Last active June 20, 2021 22:12
In ES5 undefined is protected at the global level but it's not quite bulletproof
<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"></head>
<!-- Normal script -->
<script>
// starting in ES5 window.undefined is read-only
undefined = 'NOT UNDEFINED'
console.log(undefined === window.undefined) // prove that we are scoped to window object (global object in node)
console.log(undefined !== 'NOT UNDEFINED')