Skip to content

Instantly share code, notes, and snippets.

Avatar
😑

Chiyu Zhong CatTail

😑
View GitHub Profile
@CatTail
CatTail / charlist.ex
Created September 30, 2018 02:01
string to charlist
View charlist.ex
to_charlist "hello world"
@CatTail
CatTail / read-kinesis.py
Created August 4, 2018 07:34
Simple CLI script read kinesis record and log to console
View read-kinesis.py
#! /usr/bin/env python
import sys
import boto3
import json
from datetime import datetime
import time
if len(sys.argv) != 3:
print "Usage: read-kinesis.py <region name> <stream name>"
exit(1)
@CatTail
CatTail / migrate-redis.py
Last active March 20, 2018 11:34 — forked from thomasst/migrate-redis.py
Migrate Redis data on Amazon ElastiCache
View migrate-redis.py
"""
Copies all keys from the source Redis host to the destination Redis host.
Useful to migrate Redis instances where commands like SLAVEOF and MIGRATE are
restricted (e.g. on Amazon ElastiCache).
The script scans through the keyspace of the given database number and uses
a pipeline of DUMP and RESTORE commands to migrate the keys.
Requires Redis 2.8.0 or higher.
@CatTail
CatTail / proto.js
Last active November 27, 2017 02:55
Javascript prototype in a nutshell
View proto.js
var assert = require('assert')
var util = require('util')
function test (inherits) {
function Fruit () {
}
Fruit.prototype.round = false
Fruit.prototype.sweet = true
Fruit.prototype.eat = function () {}
@CatTail
CatTail / close.html
Last active May 10, 2017 06:39
close the fucking window
View close.html
<!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
View to-json-array.sh
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
View dedupe.sh
ls | xargs -I{} bash -c 'mv {} $(md5 -q {})'
@CatTail
CatTail / client.html
Created February 9, 2017 10:17
Simple Req/Rep pattern for socket.io (which is Pub/Sub in nature)
View client.html
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/1.7.2/socket.io.js"></script>
<script>
var socket = io('http://localhost:8088');
var route = createRouter((reply) => {
socket.on('rep', reply)
})
socket.emit('req', route('hello world', (data) => {
console.log(data)
}))
@CatTail
CatTail / migrate-plugin.sh
Last active January 9, 2017 06:08
Add all exsiting vim bundle to gitmodules
View migrate-plugin.sh
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
View gen-jsonschema
#! /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 -