Skip to content

Instantly share code, notes, and snippets.

View justsml's full-sized avatar
🔥
#BLM

Dan Levy justsml

🔥
#BLM
View GitHub Profile
@justsml
justsml / fetch-api-examples.md
Last active February 24, 2024 18:05
JavaScript Fetch API Examples
View fetch-api-examples.md
@justsml
justsml / macos-setup.md
Last active January 7, 2024 14:06
MacOS setup
View macos-setup.md

MacOS - Software Developer Environment Setup

Dan's collection of MacOS setup and configuration scripts, updated for 2022 🚀!

Table of Contents

Software & Apps

View verifyUser.ts
export type User = ReturnType<typeof verifyUser>;
// ^ Type defined for 'free'
// + Pro: Less wasted effort aligning types AND validation.
// + Pro: More 'honest', not obscured by layers, `any` or `as`
// - Con: Easy to accidentally change a public interface.
// (Prefer explicit definitions at your library/module boundaries.)
export function verifyUser(data: { [key: string]: unknown; }) {
if (!data || typeof data !== 'object')
throw new Error(`User must be a valid object.`);
@justsml
justsml / INSTALL.md
Last active August 8, 2023 17:31
Add Page Up and Page Down Keyboard Bindings to Sublime Text 3 (and 2)
View INSTALL.md

Add PageUp PageDown (Keyboard Shortcut Scrolling) to Sublime Text 3 (and 2)

  • Save ScrollLinesFixedCommand.py to ~/Library/Application Support/Sublime Text 3/Packages/User/ folder
  • Copy the suggested usage from sublime-keymap.json into your ~/Library/Application Support/Sublime Text 3/Packages/User/Default (OSX).sublime-keymap

Hey Sublime, why the hell this isn't an available keybinding by default? Seriously, I'm tired of looking up how to do this every so often. For most of my work I've switched to Visual Studio Code, the Open Source IDE from Microsoft (still sounds wierd)... But it's genuinely amazing.

View ovh-mount-nfs-ftp-backup-server.sh
#!/bin/bash
set -e
# REQUIRED ACTION: Configure your backup server vars - see OVH Server Manager's "Backups" tab.
# BACKUP_HOST_PREFIX: use the prefix domain for the listed "Name" value on the "Backups" tab.
# Example: With a 'Name' value `ftpback-bhs1-3.ip-111-222-333.net` you would need to set `BACKUP_HOST_PREFIX=ftpback-bhs1-3`
# Add something likethese to your ~/.bashrc - /etc/profile
#export OVH_SERVER_ID="ns5xxxxx.ip-x-x-x.net"
#export BACKUP_HOST_PREFIX="ftpback-bhs1-x"
@justsml
justsml / aws-client-options.js
Last active April 20, 2023 01:22
Using LocalStack with AWS SDK v3 - determine options for AWS client constructors.
View aws-client-options.js
const DEFAULT_LOCALSTACK_EDGE_PORT = 4566;
/**
* Get options for use in AWS client constructors.
*
* Configure the `AWS_ENDPOINT` environment variable to set an endpoint.
*
* ### Example
*
* To run tests w/ LocalStack: `AWS_ENDPOINT=http://127.0.0.1:4566 jest`
View location-redirect.js
const checkForRedirect = (response) => {
// Check for temporary redirect (307), or permanent (308)
if (response.status === 307 || response.status === 308) {
const location = response.headers.get('location')
if (!location) {
return Promise.reject(new Error('Invalid HTTP Redirect! No Location header.'));
}
// You can change the behavior here to any custom logic:
// e.g. open a "confirm" modal, log the redirect url, etc.
return fetch(location)
View fetch-retry-with-curry.js
/**
* A **Smarter** retry wrapper with currying!
*/
function retryCurry(fn, retriesLeft = 5) {
const retryFn = (...args) => fn(...args)
.catch(err => retriesLeft > 0
? retryFn(fn, retriesLeft - 1)
: Promise.reject(err)
})
return retryFn
View basic-example.js
fetch('https://api.github.com/orgs/nodejs')
.then(response => response.json())
.then(data => {
console.log(data) // result from `response.json()` above
})
.catch(error => console.error(error))
View progressHelper-usage.js
// OPTION #1: no temp streamProcessor var
fetch(...)
.then(progressHelper(console.log))
// ⚠️ OR️ ️⚠️
// OPTION #2: define a `streamProcessor` to hold our console logger
const streamProcessor = progressHelper(console.log)
fetch(...)
.then(streamProcessor)