Skip to content

Instantly share code, notes, and snippets.

View CatTail's full-sized avatar
😑

Chiyu Zhong CatTail

😑
View GitHub Profile
@CatTail
CatTail / wrap.js
Last active June 13, 2017 02:49
async/await wrapper for express middleware
// 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]);
};
}
@CatTail
CatTail / close.html
Last active May 10, 2017 06:39
close the fucking window
<!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 () {
@CatTail
CatTail / to-json-array.sh
Last active April 13, 2017 07:21
convert lines output to json array
ls | jq -R -s -c 'split("\n")'
@CatTail
CatTail / dedupe.sh
Created April 13, 2017 05:58
Dedupe large number of images in a directory
ls | xargs -I{} bash -c 'mv {} $(md5 -q {})'
@CatTail
CatTail / codename.js
Created June 10, 2016 02:20
Barcode name popular in StarCraft
'use strict'
const MAP = {
'A': '.-',
'B': '-...',
'C': '-.-.',
'D': '-..',
'E': '.',
'F': '..-.',
'G': '--.',
@CatTail
CatTail / migrate-plugin.sh
Last active January 9, 2017 06:08
Add all exsiting vim bundle to gitmodules
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
@CatTail
CatTail / gen-jsonschema
Last active December 7, 2016 09:48
Generate json schema definition (yaml format) from example snippt
#! /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 -
@CatTail
CatTail / all-route.js
Created December 6, 2016 09:22
Get all registered routes in Express
app._router.stack // registered routes
.filter(r => r.route) // take out all the middleware
.map(r => r.route.path) // get all the paths
@CatTail
CatTail / json-pretty
Created December 5, 2016 05:51
Pretty print stdin json data, even it contains comment or other misc javascript syntax
#! /usr/bin/env node
const chunks = []
process.stdin.setEncoding('utf8')
process.stdin.on('readable', () => {
const chunk = process.stdin.read()
if (chunk) {
chunks.push(chunk)
@CatTail
CatTail / gist:4167036
Created November 29, 2012 05:43
Javascript array concatenation
// 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