Skip to content

Instantly share code, notes, and snippets.

View raineorshine's full-sized avatar

Raine Revere raineorshine

  • New York, NY
View GitHub Profile
@raineorshine
raineorshine / promiseOnDemand.ts
Last active June 26, 2023 22:59
A promise that can be resolved on demand.
import Emitter from 'emitter20'
/** Returns a [promise, resolve] pair. The promise is resolved when resolve(value) is called. */
const promiseOnDemand = <T>(): [Promise<T>, (value: T) => void] => {
const emitter = new Emitter()
const promise = new Promise<T>((resolve, reject) => {
emitter.on('resolve', resolve)
})
/** Triggers the emitter to resolve the promise. */
@raineorshine
raineorshine / keybindings.json
Created June 20, 2023 21:42
Four handy VS Code keyboard shortcuts
[
{
"key": "alt+cmd+d",
"command": "editor.action.revealDefinition",
"when": "editorHasDefinitionProvider && editorTextFocus && !isInEmbeddedEditor"
},
{
"key": "cmd+r",
"command": "editor.action.rename",
"when": "editorHasRenameProvider && editorTextFocus && !editorReadonly"
@raineorshine
raineorshine / Vanilla IndexedDB Recipes
Last active June 12, 2023 14:02
Vanilla IndexedDB Recipes... because IndexedDB was designed by Java developers 🙄🙄🙄
i ♡ indexeddb
@raineorshine
raineorshine / readLines.ts
Created March 22, 2023 14:31
Stream a file by chunk size and return whole lines. Based on: https://stackoverflow.com/a/39505307/480608
/** Stream a file by chunk size and return whole lines. */
// See: https://stackoverflow.com/a/39505307/480608
function readLines(
file: Blob,
{
chunkSizeBytes,
data,
complete,
}: { chunkSizeBytes?: number; data?: (lines: string) => void; complete?: (err: DOMException | null) => void },
) {
@raineorshine
raineorshine / java-exception-handling-best-practices.md
Last active March 13, 2023 02:54
5 Great Resources for Exception Handling Best Practices in Java

General Tip

"The trick is to catch exceptions at the proper layer, where your program can either meaningfully recover from the exception and continue without causing further errors, or provide the user with specific information, including instructions on how to recover from the error. When it is not practical for a method to do either of these, simply let the exception go so it can be caught later on and handled at the appropriate level."

Resources

Advantages of Exceptions
Excellent example of separating error-handling code from program logic

Three Rules for Effective Exception Handling
Longer explanation and case study of exception use, including the basic principles of "throw early" and "catch late". Clear and thorough.

@raineorshine
raineorshine / tsconfig.json
Created February 21, 2023 21:01
Minimum typescript configuration needed to use ESM modules and top-level await
{
"includes": ["*.ts"],
"compilerOptions": {
// es modules
"module": "es2022",
"moduleResolution": "node",
// top-level await
"target": "es2022"
}
}
@raineorshine
raineorshine / animals.txt
Last active January 23, 2023 17:09 — forked from Bradleykingz/animals.txt
List of 446 animals
Aardvark
Aardwolf
African Buffalo
African Elephant
African Leopard
Albatross
Alligator
Alpaca
Amphibian
Anaconda
@raineorshine
raineorshine / sendRawTransaction.js
Last active December 3, 2022 18:02
Sends a raw transaction with web3 v1.2.2, ethereumjs-tx v2.1.1, and Infura
const Web3 = require('web3')
const Tx = require('ethereumjs-tx').Transaction
// connect to Infura node
const web3 = new Web3(new Web3.providers.HttpProvider('https://mainnet.infura.io/INFURA_KEY'))
// the address that will send the test transaction
const addressFrom = '0x1889EF49cDBaad420EB4D6f04066CA4093088Bbd'
const privateKey = new Buffer('PRIVATE_KEY', 'hex')
@raineorshine
raineorshine / responsive.css
Last active November 19, 2022 06:08
Cheat Sheet: Responsive Design
@media all and (max-width: 1024px) {...}
@media all and (min-width: 800px) and (max-width: 1024px) {...}
@media not screen and (color) {...}
@media only screen and (orientation: portrait) {...}
@media all and (max-width: 420px) {
section, aside {
float: none;
width: auto;
}
@raineorshine
raineorshine / git-essentials.sh
Created April 1, 2014 22:53
Git Cheat Sheet: Just the Essentials (13 Commands). See https://gist.github.com/5128563 for more.
# Status Commands - These are always safe to execute and don't change the repo.
git status # Print the status of the current repo
git log # Print a list of the most recent commits
git diff # Show all differences between unstaged changes
# and the last commit.
git remote -v # Show all remotes with name and url.
# Repo Commands - These modify the state of the repo in some way but do not modify files
git init # Initialize a new repo in the current folder
git add MYFILE # Add a file with changes to the staging area to be committed.