This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// wrap async function to use as express middleware or route | |
// let wrap = fn => (...args) => fn(...args).catch(args[2]) | |
function wrapRoute(fn) { | |
return function () { | |
return fn.apply(undefined, arguments) | |
.catch(arguments[arguments.length - 1]); | |
}; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title></title> | |
<script src="https://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script> | |
</head> | |
<body> | |
<script> | |
setTimeout(function () { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ls | jq -R -s -c 'split("\n")' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ls | xargs -I{} bash -c 'mv {} $(md5 -q {})' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
const MAP = { | |
'A': '.-', | |
'B': '-...', | |
'C': '-.-.', | |
'D': '-..', | |
'E': '.', | |
'F': '..-.', | |
'G': '--.', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
plugins=$(find . -type d -d 1 | tail -n +3) | |
for plugin in $plugins; do | |
echo plugin: $plugin | |
cd $plugin | |
repo=$(git remote -v | head -n 1 | cut -f 2 | cut -f 1 -d ' ') | |
echo repo: $repo | |
cd .. | |
git submodule add $repo | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
# npm install -g yamljs json-schema-generator | |
# json-pretty came from [here](https://gist.github.com/CatTail/fc172a7fe6f300528665e279592c6500) | |
cat "${1:-/dev/stdin}" | json-pretty | json-schema-generator | tail -n +2 | json2yaml -d 10 - |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app._router.stack // registered routes | |
.filter(r => r.route) // take out all the middleware | |
.map(r => r.route.path) // get all the paths |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env node | |
const chunks = [] | |
process.stdin.setEncoding('utf8') | |
process.stdin.on('readable', () => { | |
const chunk = process.stdin.read() | |
if (chunk) { | |
chunks.push(chunk) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Following concat function concatenate javascript arrays | |
// It consider three more factor then normal Array.prototype.concat: | |
// 1. eliminate common element | |
// 2. escape null and undefined | |
// 3. deal with element being an array | |
var arr1 = ['a']; | |
var arr2 = ['b', 'c']; | |
var arr3 = ['c', ['d'], 'e', undefined, null]; | |
// return object classname |