Skip to content

Instantly share code, notes, and snippets.

View bearzk's full-sized avatar

Kai Zhang bearzk

View GitHub Profile
@bearzk
bearzk / gist:3717458
Created September 13, 2012 20:38
Python sort using the nth element
>>> a = [(111,555),(333,222)]
>>> a.sort()
>>> a
[(111, 555), (333, 222)]
>>> a.sort(lambda x,y: cmp(x[1],y[1]))
>>> a
[(333, 222), (111, 555)]
@bearzk
bearzk / numbers_at_odd_and_even_position_in_a_list.py
Created October 5, 2012 01:38
python odd and even position element in list
a = range(0,10) #[1..11]
odd = a[::2] #[1,3,5,7,9]
even = a[1::2] #[2,4,6,8,10]

Keybase proof

I hereby claim:

  • I am bearzk on github.
  • I am bearzk (https://keybase.io/bearzk) on keybase.
  • I have a public key whose fingerprint is C338 E988 980D 500C B6B9 AE1D 5ED2 A3B8 95F6 00B2

To claim this, I am signing this object:

#!/bin/bash
ok=false
echo
for file in $(find . -name '*.rb'); do
if [ $ok ]; then
echo -ne "\033[2A"
echo -ne "\033[K"
fi
echo $file;
ruby -c $file;
@bearzk
bearzk / partial_function.js
Last active May 7, 2018 13:50
[partial function] #js #functional
const toString = Object.prototype.toString;
const isType = type => {
return function (obj) {
return toString.call(obj) == '[object ' + type + ']';
};
};
const isFunction = isType('Function');
@bearzk
bearzk / center.css
Created May 9, 2018 08:42
[center text] center text in css #flex
.center {
display: flex;
justify-content: center;
align-items: center;
}
@bearzk
bearzk / htpasswd.sh
Created May 15, 2018 09:14
Generate a htaccess password
htpasswd -nb name password
# name:$apr1$8sRtOm7K$QxQXk5Zo6HhOhujVhovgn0
@bearzk
bearzk / .editorconfig
Created May 29, 2018 21:07
[editorconfig]
# http://editorconfig.org
root = true
[*]
charset = utf-8
end_of_line = lf
indent_style = space
indent_size = 4
insert_final_newline = true
@bearzk
bearzk / health-endpoint-monitoring.md
Created December 25, 2018 16:01
[Health Endpoint Monitoring] #cloud #designpattern

Health Check

Why?

Check the system is working properly, if any errors or anomaly, we want that be detected early than late.

When?

  • check availability
  • check operation correctness
  • check middle-tier or shared service to detect and isolate a failure
@bearzk
bearzk / queue-based-load-leveling-pattern.md
Last active February 12, 2019 13:13
[Queue-Based Load Leveling pattern] #cloud #designpattern

Queue-Based Load Leveling pattern

Why and When?

Sometimes a part of our application just can not run that fast, it could be for example, avatar processing, email sending, and in these case we don't usually need a response/confirmation that the action is finished, we can push these tasks into queue and handle them asynchronously to take the load off the system.

How?

  • push slow tasks into queue