Skip to content

Instantly share code, notes, and snippets.

Delete all docker images and containers

#!/bin/bash
# Delete all containers
docker rm $(docker ps -a -q)
# Delete all images
docker rmi $(docker images -q)
@viruschidai
viruschidai / flatten.js
Created August 28, 2017 01:36
Flatten js array without recursion
function flatten(arr) {
if (!arr || !arr.length) return [];
var nodes = arr.slice();
var results = [];
var node = nodes.pop();
while(node) {
if (Array.isArray(node)) {
nodes.push.apply(nodes, node);
} else {
exports.pack = (data, cb) ->
ret= []
innerRet = []
for index, d of data
if d then innerRet.push '1' else innerRet.push '0'
if innerRet.length is 32 or index is (data.length - 1)
ret.push innerRet
innerRet = []
binary = []
@viruschidai
viruschidai / gist:80dff0ba0244a805377b
Created June 7, 2014 11:38
When should you avoid adding comment to your code?
1. When it takes less time to read your code than to read your comment
2. When your code can be written in a more self-documented way
3. When your comment is simply repeat a method name or variable name
@viruschidai
viruschidai / gist:fff99ce7c9c47eb80efa
Last active August 29, 2015 14:01
When you should not use Dynamodb
You need transaction
You need db pagination
You need db aggregation functions
You want to store document big than 64kb
You need joins
You don't want to write tools to use dynamodb to fit your need
Your data has schema and you need to migrate data to use new schema occasionally
You want easily to add indexes whenever you want to a table
@viruschidai
viruschidai / gist:31e4d2208d8a44b80a36
Last active August 30, 2016 10:25
git pre-commit hook to check if '.skip' or '.only' is used in mocha tests
filelist=$(git diff --cached --name-only --diff-filter=ACMR)
testfiles=$(echo "${filelist[@]}" | grep -E 'test\/.*\.coffee$' | grep -v node_modules)
if [[ ${testfiles[@]} ]]
then
echo
echo 'Checking if there are skipped tests ...'
echo
echo ${testfiles[@]} | xargs cat | grep -E '\.only|\.skip' && echo 'Error: contains skipped tests' && exit 1 || exit 0
fi
@viruschidai
viruschidai / gist:9360639
Created March 5, 2014 03:31
Node.js custom error
# Base custom error class
exports.AbstractError = class AbstractError extends Error
constructor: (msg, constr) ->
Error.captureStackTrace this, constr or this
@message = msg or 'Error'
name: 'Abstract Error'
exports.InvalidDataError = class InvalidDataError extends AbstractError
@viruschidai
viruschidai / gist:6362441
Created August 28, 2013 05:31
replace text in all files found
find . -type f -print0 | xargs -0 sed -i 's/Application/whatever/g'
@viruschidai
viruschidai / my-git-config
Last active December 17, 2015 23:19
my git config
[user]
name = Bill Gao
email = viruschidai@gmail.com
[core]
excludesfile = /home/billg/.gitignore
editor = vim
[color]
ui = true
[giggle]
main-window-maximized = true