Skip to content

Instantly share code, notes, and snippets.

@ppxu
ppxu / README
Created June 8, 2018 07:31 — forked from joelambert/README
Drop in replacements for setTimeout()/setInterval() that makes use of requestAnimationFrame() where possible for better performance
Drop in replace functions for setTimeout() & setInterval() that
make use of requestAnimationFrame() for performance where available
http://www.joelambert.co.uk
Copyright 2011, Joe Lambert.
Free to use under the MIT license.
http://www.opensource.org/licenses/mit-license.php

Keybase proof

I hereby claim:

  • I am ppxu on github.
  • I am ppxu (https://keybase.io/ppxu) on keybase.
  • I have a public key whose fingerprint is 8339 D149 B131 E005 D5F7 7073 4912 CBB4 A000 E897

To claim this, I am signing this object:

// Fisher–Yates_shuffle
// https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle
function shuffle(arr) {
    let i = arr.length;
    while (i) {
        let j = Math.floor(Math.random() * i--);
        [arr[j], arr[i]] = [arr[i], arr[j]];
    }
}
function _LazyMan (name) {
this.tasks = [];
var self = this;
var fn = (function (n) {
var name = n;
return function () {
console.log('Hi! This is ' + name + '!');
self.next();
};
})(name);
server {
listen 80;
server_name localhost;
# 处理静态资源文件:
location ^~ /static/ {
root /path/to/ws-with-koa;
}
# 处理WebSocket连接:
// 校验密码强度
// 密码的强度必须是包含大小写字母和数字的组合,不能使用特殊字符,长度在8-10之间。
/^(?=.*\\d)(?=.*[a-z])(?=.*[A-Z]).{8,10}$/
// 校验中文
// 字符串仅能是中文。
/^[\\u4e00-\\u9fa5]{0,}$/
// 由数字、26个英文字母或下划线组成的字符串
/^\\w+$/
function shellInsert (arr, dk) {
var i, j, l, tmp;
for (i = dk, l = arr.length; i < l; i++) {
if (arr[i] < arr[i - dk]) {
tmp = arr[i];
for (j = i - dk; j >= 0 && tmp < arr[j]; j -= dk) {
arr[j + dk] = arr[j];
arr[j] = tmp;
}
}
function selectSort (arr) {
var i, j, l, min, index;
for (i = 0, l = arr.length; i < l; i++) {
min = arr[i];
index = i;
for (j = i + 1; j < l; j++) {
if (arr[j] < min) {
min = arr[j];
index = j;
}
function insertSort (arr) {
var i, j, l, tmp;
for (i = 1, l = arr.length; i < l; i++) {
tmp = arr[i];
j = i;
while (arr[j - 1] > tmp && j) {
arr[j] = arr[j-1];
j--;
}
arr[j] = tmp;
function bubbleSort (arr) {
var i, j, l, tmp;
for (i = 0, l = arr.length - 1; i < l; i++) {
for (j = l; j > i; j--) {
if (arr[j] < arr[j - 1]) {
tmp = arr[j];
arr[j] = arr[j - 1];
arr[j - 1] = tmp;
}
}