Skip to content

Instantly share code, notes, and snippets.

Waiting for code to compile

T twhite96

Waiting for code to compile
View GitHub Profile
twhite96 / index.js
Created Sep 26, 2020 — forked from kyleshevlin/index.js
Boolean operators don't distribute
View index.js
// I see this mistake often (and have made it myself before)
// What's the bug with this function?
function isFavSeason(season) {
return season === 'spring' || 'summer' ? 'yes' : 'no'
// Let's try it and find out
console.log(isFavSeason('spring')) // yes
console.log(isFavSeason('summer')) // yes
twhite96 /
Created Sep 3, 2020 — forked from wosephjeber/
Find and kill ruby process using specified port
# Puma occasionally doesn't kill all ruby processes when
# I shut down my local web server. Here are the steps
# to find and kill the processes.
# Find pid of process running on specified port
lsof -i :3000
# Kill process
sudo kill -9 [pid]
View tweet-when-to-use-generators-iterators.js
// Builds array of everything ahead of time
function collectAllItems() {
return [calculateFirst(), calculateSecond(), ...]
// This loop will end as soon as `isMatch(item)` is truthy.
// If the very first item in the array is a match, then we
// wasted all this time building the array in the first place.
for (let item of collectAllItems()) {
if (isMatch(item)) {
twhite96 / cloudSettings
Last active Mar 30, 2020
Visual Studio Code Settings Sync Gist
View cloudSettings

I really liked @tjvantoll article Handling Failed HTTP Responses With fetch(). The one thing I found annoying with it, though, is that response.statusText always returns the generic error message associated with the error code. Most APIs, however, will generally return some kind of useful, more human friendly message in the body.

Here's a modification that will capture this message. The key is that rather than throwing an error, you just throw the response and then process it in the catch block to extract the message in the body:

  .then( response => {
    if (!response.ok) { throw response }
    return response.json()  //we only get here if there is no error
twhite96 / example.js
Created Jan 22, 2020 — forked from hwangbible/example.js
Scriptablify - lets you require('modules') in Scriptable app!
View example.js
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: gray; icon-glyph: magic;
// Defaults to the latest version and no automatic update; if the file exists, just use it
const moment = await require('moment');
// Use any SemVer options to specify a version you want
// Refer to the calculator here:
const lodash = await require('lodash@^3.9.1');
twhite96 /
Created Jul 31, 2019 — forked from jaredhowland/
Clear Mac OS X Font Caches
twhite96 / git_newrepo
Created Jun 27, 2019 — forked from c0ldlimit/git_newrepo
Git: Push a new or existing repo to Github
View git_newrepo
# Create a new repository on the command line
git init
git add
git commit -m "first commit"
git remote add origin
git push -u origin master
# Push an existing repository from the command line

Download Audio from YouTube

-i - ignore errors

-c - continue

-t - use video title as file name

--extract-audio - extract audio track

View require.js
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: green; icon-glyph: file-code;
const getModule = importModule("getModule");
const documentDirectory = FileManager.iCloud().documentsDirectory();
module.exports = async ({ moduleName, url, forceDownload = false }) => {
if (moduleExists(moduleName) && !forceDownload) {
return importModule(moduleName);