Skip to content

Instantly share code, notes, and snippets.

View justsml's full-sized avatar
🔥
#BLM

Dan Levy justsml

🔥
#BLM
View GitHub Profile

Iterables, AsyncIterables, Observables, Oh My!

I know there is a lot of confusion around Observables, Iterables, AsyncIterables and AsyncObservables. Let's try to break this down and the reasons for each.

Pull versus Push Collections

When it comes to collections, you have two ways of thinking about collections, push versus pull. With pull, the consumer is in control of when you get the items, but with push, you get the values when the producer is ready.

Pull Based Collections

@justsml
justsml / setupOSX.sh
Last active March 21, 2024 09:28 — forked from tylerwalts/setupOSX.sh
This is a bash script to setup Mac OS X defaults on a new mac.
#!/bin/bash
#
# Set up OSX preferences
#
# Updated By: Dan Levy @justsml
#
# Inspired by: https://github.com/mathiasbynens/dotfiles/blob/master/.osx
###########################################
# CONFIG
@justsml
justsml / fetch-api-examples.md
Last active February 24, 2024 18:05
JavaScript Fetch API Examples
@justsml
justsml / macos-setup.md
Last active January 7, 2024 14:06
MacOS setup

MacOS - Software Developer Environment Setup

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

Table of Contents

Software & Apps

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)

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.

#!/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.
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`
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)
/**
* 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