Skip to content

Instantly share code, notes, and snippets.

View kitt1987's full-sized avatar
👽
I love this crazy world🤟

Kitt Hsu kitt1987

👽
I love this crazy world🤟
  • Shenzhen,China
View GitHub Profile
@kitt1987
kitt1987 / yell.sh
Created December 11, 2019 09:00
Show notification after executing shell commands.
yell() {
cmd=""
if [ $# -gt 0 ]; then
cmd=$@
else
cmd=$(history| awk '{$1=""; print $0}' | grep -E '^\s*yell.+' | tail -1)
fi
eval $cmd
@kitt1987
kitt1987 / bash.rc
Last active September 24, 2019 07:50
Show docker container with respect to a host PID
function findc {
local pid=$1
local containerLabel=$(head -1 /proc/11212/cgroup | sed -E 's|.*pod([0-9a-z\-]*).*|\1|')
if [[ "${containerLabel}" == "" ]]; then
echo "no container found with regards to PID $pid"
exit 2
fi
local matchedID=$(docker ps -a | grep "${containerLabel}" | awk '{ print $1 }' 2>/dev/null)
while read -r id; do
function randomSeq(begin, end, number) {
var i = 0;
var range = end - begin;
var exchanged = {};
var seq = [];
while (i < number) {
const v = i + Math.floor(Math.random() * (range - i));
if (exchanged[v] !== undefined) {
seq.push(begin + exchanged[v]);
} else {
@kitt1987
kitt1987 / gist:7dfcd1ab87e31f667f7078db710bb766
Created June 3, 2016 06:24
Helper for calling and binding function as private method in javascript
class PrivateFuncHelper {
constructor() {
var self = this;
Object.defineProperties(this, {
'_': {
value: function(func) {
return func.apply(self, Array.prototype.slice.call(arguments, 1));
}
},
'_bind': {
@kitt1987
kitt1987 / cache_key.js
Last active November 2, 2015 04:04
An object works as key of No sql storage.
'use strict';
exports = module.exports = CacheKey;
function CacheKey(symbol) {
if (!symbol || typeof symbol !== 'string') throw new Error('The symbol of cache key must be string');
this.type = symbol;
this.keys = {};
this.single = {};
}
/*
* Copyright (C) 2006, 2008 Valery Kholodkov
* Client body reception code Copyright (c) 2002-2007 Igor Sysoev
* Temporary file name generation code Copyright (c) 2002-2007 Igor Sysoev
*/
#include <ngx_config.h>
#include <ngx_core.h>
#include <ngx_http.h>
#include <nginx.h>