Skip to content

Instantly share code, notes, and snippets.

  • install percol
  • .bashrc: bind -x '"\C-R": READLINE_LINE=$(history | tac | cut -c 8- | percol --query "${READLINE_LINE}") READLINE_POINT='
  • .bashrc: export HISTCONTROL=ignoreboth:erasedups
// Reverse a string, e.g., '321' -> '123'
s.split('').reverse().join('')
// Give a random number within a range [a,b)
Math.random() * (b - a) + a;
// XOR swap
x = x^y;
y = x^y;
x = x^y;
class Clock extends React.Component {
constructor(props) {
super(props);
this.state = {date: new Date()};
}
componentDidMount() {
this.timerID = setInterval(
() => this.tick(),
1000
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@texzhichen
texzhichen / KFY_shuffle_vs_naive_shuffle.matlab
Last active August 29, 2015 14:00
Compare the KFY shuffle with naive shuffle by a=[1,2,3]. There are 6 combinations. The experiment result shows that KFY shuffle is unbiased and the number of distinct combination closes to round(max_iter/6). But naive shuffle is biased. Refer to http://blog.codinghorror.com/the-danger-of-naivete/
%% KFY shuffle
n = 3;
max_iter = 1e5;
count = zeros(17,1);
for iter = 1:max_iter
a = 1:n;
for i = n:-1:2
j = randi(i,1,1);
t = a(i);
a(i) = a(j);