Skip to content

Instantly share code, notes, and snippets.

@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:

@sindresorhus
sindresorhus / esm-package.md
Last active September 18, 2024 22:09
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 August 27, 2024 12:54
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);
@bittner
bittner / keyboard-keys.md
Created February 28, 2019 22:50
Keyboard keys markup in MarkDown

Ctrl + Alt + Space

@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