I hereby claim:
- I am chux0519 on github.
- I am chux0519 (https://keybase.io/chux0519) on keybase.
- I have a public key ASBmv5sc3jH3XoEPCaV_gT02QP_HMprXAgdpHvPkLx8s2Qo
To claim this, I am signing this object:
| // 最大公约数 | |
| const gcd = (a, b) => a === 0 ? b : gcd(b % a, a) | |
| // 最小公倍数 | |
| const lcm = arr => arr.reduce((a, b) => a * b / gcd(a, b), 1) | |
| const overallTotal = 9 / 10 | |
| const overallAvg = overallTotal / 3 | |
| for (let x = 2; ; ++x) { |
I hereby claim:
To claim this, I am signing this object:
| #!/bin/bash | |
| DATA_PATH=$1 | |
| DATE=$(date +%F) | |
| BACKUP=rancher-data-backup-$DATE.tar.gz | |
| CONTAINER_NAME=$(docker ps | grep rancher | awk '{print $NF}') | |
| printf "found running rancher container $CONTAINER_NAME\n" |
| PAGE_SZ = 2 | |
| class Page(object): | |
| def __init__(self): | |
| self.m = {} | |
| self.d = 0 | |
| def full(self): | |
| return len(self.m) >= PAGE_SZ |
| sed -n '/protocol:op_query/p' mongod.log | sed 's/\([0-9|_|T]*\+0000\) .*command \(.*\..*\) command:.*planSummary: \([A-Z|_]*\) .*protocol:op_query \([0-9]*ms\)$/\1 \2 \3 \4/g' |
| #!/bin/bash | |
| # Install Shadowsocks on CentOS 7 | |
| echo "Installing Shadowsocks..." | |
| random-string() | |
| { | |
| cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w ${1:-32} | head -n 1 | |
| } |
| const AWS = require('aws-sdk') | |
| function buildS3Service (options) { | |
| const { | |
| s3Key, | |
| s3Secret | |
| } = options | |
| const s3Client = new AWS.S3({ | |
| accessKeyId: s3Key, | |
| secretAccessKey: s3Secret |
| // 简单递归求和写法 | |
| const sumRec = x => { if (x === 0) return 0; else return x + sumRec(x - 1) } | |
| // CPS变换,转递归为尾递归 | |
| // nodejs 依赖于v8,当前版本的实现已经不支持尾递归优化,因此下面的写法虽然是尾递归,但是仍会爆栈 | |
| const sumCPS = (x, kont) => { | |
| if (x === 0) return kont(0) | |
| else return sumCPS(x - 1, res => kont(res + x)) | |
| } |
| const superstatic = require('superstatic').server | |
| const path = require('path') | |
| const fsProvider = require('superstatic/lib/providers/fs') | |
| // Remove etag, cancel the browser's cache, avoid update issues | |
| function noCacheProvider (options) { | |
| const handler = fsProvider(options) | |
| return (req, pathname) => handler(req, pathname).then(res => { | |
| if (res) { // res can be null | |
| res.modified = false |
| const {TaskExecutionLimiter, buildTaskExecutionLimiter, buildWithLimit} = require('task-execution-limiter') | |
| const console = require('consoleit') | |
| const case1 = () => { | |
| console.log('=> case 1: Usage of `TaskExecutionLimiter.schedule`') | |
| // Using TaskExecutionLimiter class | |
| // schedule method | |
| const limiter = new TaskExecutionLimiter({ | |
| interval: 1000, // rate limit: one task per second | |
| limit: 1, |