Skip to content

Instantly share code, notes, and snippets.


Shawn Wang iShawnWang

View GitHub Profile
dhaneshgosai / AppStoreUpdate.swift
Last active May 8, 2021
This Gist Class for Checking App Store version with local version.
View AppStoreUpdate.swift
// AppStoreUpdate.swift
// Created by CodeChanger on 03/11/19.
// Copyright © 2019 CodeChanger. All rights reserved.
import UIKit
enum CustomError: Error {
iShawnWang / useRouter.ts
Last active Jul 27, 2019
react-router backward hooks, support react-router 4.x | 5.x
View useRouter.ts
import { __RouterContext as RouterContext, RouteComponentProps } from 'react-router'
import { useContext, useMemo, useCallback } from 'react'
import qs from 'qs'
import { Location } from 'history'
interface ParsedQuery {
[whatever: string]: any
export const useRouter = <T>(): RouteComponentProps<T> =>
View json_parser.js
// This is a coding exercise of implementing a parser. Some minor parsing capabilities are not implemented.
// The algorithm are mainly from Douglas Crockford's ''
function json_parse(str) {
var i = 0
var ch = str[i]
// core function that recursively called to move forward scanning pointers and accept tokens
function next(c) {
if (c) {
webfrogs /
Created Mar 30, 2017
Output swift function information whose compile time is large than 100ms
xcodebuild -workspace XXX.xcworkspace -scheme XXX clean build OTHER_SWIFT_FLAGS="-Xfrontend -debug-time-function-bodies" | grep '^\d\{3,\}[.]\{1\}'
QinMing / .zshrc
Last active Apr 22, 2021
.zshrc (lazy loading shell functions)
View .zshrc
# Copyright (c) 2016-2018 Ming Qin (覃明) <>
# Open source under MIT LICENSE.
lazy_load() {
# Act as a stub to another shell function/command. When first run, it will load the actual function/command then execute it.
# E.g. This made my zsh load 0.8 seconds faster by loading `nvm` when "nvm", "npm" or "node" is used for the first time
# $1: space separated list of alias to release after the first load
# $2: file to source
# $3: name of the command to run after it's loaded
# $4+: argv to be passed to $3
slavafomin /
Last active Apr 13, 2021
Custom ES6 errors in Node.js

Here's how you could create custom error classes in Node.js using latest ES6 / ES2015 syntax.

I've tried to make it as lean and unobtrusive as possible.

Defining our own base class for errors


# lazyload nvm
# all props goes to
# grabbed from reddit @
lazynvm() {
unset -f nvm node npm npx
export NVM_DIR=~/.nvm
[ -s "$NVM_DIR/" ] && . "$NVM_DIR/" # This loads nvm
if [ -f "$NVM_DIR/bash_completion" ]; then
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
remarkablemark / Dockerfile
Last active May 7, 2021
Install node and npm with nvm using Docker.
View Dockerfile
# set the base image to Debian
FROM debian:latest
# replace shell with bash so we can source files
RUN rm /bin/sh && ln -s /bin/bash /bin/sh
# update the repository sources list
# and install dependencies
RUN apt-get update \
View Enable crontab log MAC
1. `vim /etc/syslog.conf`
2. Add to end of file: `cron.* /var/log/cron.log`
sudo launchctl unload /System/Library/LaunchDaemons/
sudo launchctl load /System/Library/LaunchDaemons/