Skip to content

Instantly share code, notes, and snippets.

zx texzhichen

Block or report user

Report or block texzhichen

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
  • 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
View common-tasks.js
// Reverse a string, e.g., '321' -> '123'
// 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;
View clock-state-react-example.jsx
class Clock extends React.Component {
constructor(props) {
this.state = {date: new Date()};
componentDidMount() {
this.timerID = setInterval(
() => this.tick(),
View exp.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
texzhichen / KFY_shuffle_vs_naive_shuffle.matlab
Last active Aug 29, 2015
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
View KFY_shuffle_vs_naive_shuffle.matlab
%% 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);
You can’t perform that action at this time.