Skip to content

Instantly share code, notes, and snippets.

@haishanh
haishanh / keybase.md
Last active April 27, 2022 09:14
keybase.md

Keybase proof

I hereby claim:

  • I am haishanh on github.
  • I am haishanh (https://keybase.io/haishanh) on keybase.
  • I have a public key ASCVAbSwFIkUm68AJW4o64FypapsMcNM3k1jIAoG7viuRwo

To claim this, I am signing this object:

@haishanh
haishanh / machine.js
Created January 17, 2021 04:30
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@haishanh
haishanh / script-template.sh
Created December 29, 2020 04:48 — forked from m-radzikowski/script-template.sh
Minimal safe Bash script template - see the article with full description: https://betterdev.blog/minimal-safe-bash-script-template/
#!/usr/bin/env bash
set -Eeuo pipefail
trap cleanup SIGINT SIGTERM ERR EXIT
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd -P)
usage() {
cat <<EOF
Usage: $(basename "${BASH_SOURCE[0]}") [-h] [-v] [-f] -p param_value arg1 [arg2...]
const fetchUser = userId =>
fetch(`url/to/user/${userId}`).then(response => response.json());
const userMachine = Machine({
id: 'user',
initial: 'idle',
context: {
userId: 42,
user: undefined,
error: undefined
Machine({
id: 'SWAPI',
initial: 'idle',
context: {
user: null
},
states: {
idle: {
on: {
FETCH: 'loading'
@haishanh
haishanh / machine.js
Last active May 2, 2020 10:50
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@haishanh
haishanh / configureStore.js
Created March 14, 2020 04:07
redux-with-hooks
import { createStore, applyMiddleware, compose } from 'redux';
import thunkMiddleware from 'redux-thunk';
import rootReducer from '../ducks';
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
function configureStore() {
const store = createStore(
rootReducer,
composeEnhancers(applyMiddleware(thunkMiddleware))
@haishanh
haishanh / use-bunyan-logger-factory.js
Last active February 12, 2020 09:55
use bunyan-logger-factory
"use strict";
/**
* on Mac you can use system builtin app Console to view syslog
* but logProto has to be 'sys'
* Note, Console only shows logs with level >= warn by default
*
*
* fatal 60
* error 50
import React from "react";
import { Link } from "react-router-dom";
export function createResource(getPromise) {
let cache = {};
let inflight = {};
let errors = {};
function load(key) {
inflight[key] = getPromise(key)
@haishanh
haishanh / class.js
Created February 21, 2018 12:16 — forked from gxcsoccer/class.js
各种类构造和继承性能比较
'use strict';
const Benchmark = require('benchmark');
const benchmarks = require('beautify-benchmark');
const suite = new Benchmark.Suite();
const util = require('util');
const assert = require('assert');
class A {