Skip to content

Instantly share code, notes, and snippets.

View YajJackson's full-sized avatar
🎯
Focusing

Jay Jackson YajJackson

🎯
Focusing
  • DroneDeploy
  • Noblesville IN
View GitHub Profile
@YajJackson
YajJackson / defer_nvm
Last active October 12, 2022 17:06
defer nvm
# Defer initialization of nvm until nvm, node or a node-dependent command is
# run. Ensure this block is only run once if .bashrc gets sourced multiple times
# by checking whether __init_nvm is a function.
if [ -s "$HOME/.nvm/nvm.sh" ] && [ ! "$(type __init_nvm)" = function ]; then
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/bash_completion" ] && . "$NVM_DIR/bash_completion"
declare -a __node_commands=('nvm' 'node' 'npm' 'yarn' 'gulp' 'grunt' 'webpack')
function __init_nvm() {
for i in "${__node_commands[@]}"; do unalias $i; done
. "$NVM_DIR"/nvm.sh
@YajJackson
YajJackson / useAsyncMemo.ts
Created February 2, 2021 04:49
React hook for asynchronous state
import { useEffect, useState } from 'react'
import type { DependencyList } from 'react'
export const useAsyncMemo = <T>(
factory: () => Promise<T>,
deps: DependencyList,
initialState: T
) => {
const [state, setState] = useState<T>(initialState)
@YajJackson
YajJackson / App.js
Last active November 11, 2019 21:06
React Context Demo
import React, { useState, useEffect, useContext, createContext } from 'react'
const UserContext = createContext()
const Login = ({ onLogin }) => {
const [name, setName] = useState('')
const [pass, setPass] = useState('')
return (
<form onSubmit={() => onLogin({ name, pass })}>
<input
#!/bin/sh
# Note file
note_file=~/_notes.md
# Create Note file if it does not exist
if [ ! -f "$note_file" ]; then
touch $note_file
fi