Skip to content

Instantly share code, notes, and snippets.

View evanhsu's full-sized avatar

Evan Hsu evanhsu

  • PlexTrac
  • Boise, ID
View GitHub Profile
@evanhsu
evanhsu / ChildProcess.test.ts
Created September 2, 2022 23:46
Mimicking a ChildProcess in a nodeJS unit test
/**
* This is the function that we'll be testing. It takes a ChildProcess as
* an input arg, collects all the messages from the 'stderr' stream, then
* throws an Error with all the error messages concatenated once the
* ChildProcess ends
*/
function collectChildProcessErrors(cp: ChildProcess) {
const errorMessages: string[] = [];
cp.on('stderr', (data: Buffer) => {
@evanhsu
evanhsu / config.ts
Last active May 13, 2021 14:52
A typescript config object that provides strong typing of environment variables for node.js projects
import { logger } from './util/logger';
// appHealth keeps track of the success/error state of each critical component
// during app startup (database connection, env vars are present, remote API credentials work, etc).
// This info then supports the kubernetes health-check mechanism by preventing the app from simply
// crashing when it isn't configured correctly and instead it boots up and reports that it's degraded
// from its /healthz API endpoint.
// If you want to trim some complexity, you can eliminate appHealth and just *throw* an error instead
// of storing an error in the appHealth object.
import { appHealth } from './util/appHealth';
@evanhsu
evanhsu / package.json
Created May 13, 2021 14:07
Load env variables into process.env for a create-react-app project
{
"name": "Create React App",
"version": "1.0.0",
"private": true,
"scripts": {
"withenv": "export $(cat ../.env | xargs) && yarn",
"start": "yarn withenv react-scripts start",
"startnoenv": "react-scripts start"
}
}
@evanhsu
evanhsu / dcyarn
Created November 14, 2020 19:03
Run yarn commands inside docker-compose
#!/bin/bash
root_path=$( cd "$(dirname $(dirname "${BASH_SOURCE[0]}"))" ; pwd -P )
# Check to see if the node_modules folder exists in the 'web' project
if [ ! -d "$root_path/web/node_modules" ]; then
echo "No '/web/node_modules' folder found. Running 'yarn' in the web project...";
# Just go ahead and run yarn automatically...
cd $root_path/web
nvm use && yarn
@evanhsu
evanhsu / keybindings.json
Last active November 9, 2020 04:46
VSCode Custom Keybindings + Vim (put these in ~/Library/Application Support/Code/User)
// Place your key bindings in this file to override the defaultsauto[]
[
{
"key": "cmd+e",
"command": "-actions.findWithSelection"
},
{
"key": "cmd+e",
"command": "workbench.action.openNextRecentlyUsedEditor"
},
@evanhsu
evanhsu / keybase.md
Created August 26, 2020 01:46
Keybase Verification

Keybase proof

I hereby claim:

  • I am evanhsu on github.
  • I am suredoes (https://keybase.io/suredoes) on keybase.
  • I have a public key ASC1ZEln3lo3SjMk8RPZLVqfxrahsMZ-nkqdBWVHH_XmBQo

To claim this, I am signing this object:

@evanhsu
evanhsu / promiseWithTimeout.js
Last active April 10, 2018 17:17
Create a js promise with a timeout
/**
* Creates a promise that rejects after the specified amount of time.
* This can be used with the Promise.race() method to set a timeout on a different Promise:
*
* Promise.race([
* fetchDataSlowly(),
* timeoutThenReject(5000)
* ]);
*
* @param durationMillis Number of milliseconds to wait before resolving with a rejection.
@evanhsu
evanhsu / arrange-workspaces.sh
Created January 22, 2018 16:24
Change workspace layout in Ubuntu Unity
# Run in your terminal
dconf write /org/compiz/profiles/unity/plugins/core/vsize 1 # Arrange workspaces into a single row
dconf write /org/compiz/profiles/unity/plugins/core/hsize 3 # Arrange workspaces into 3 columns
@evanhsu
evanhsu / keymap.cson
Created July 25, 2016 23:10
Atom Keymap
# vim-mode-plus keymaps (package required)
#---#
# Vim - map 'jk' to 'esc'
'atom-text-editor':
'k': 'exit-insert-mode-if-preceeded-by-j'
# surround: ys
# -------------------------
'S': 'vim-mode-plus:surround-smart-word'