Skip to content

Instantly share code, notes, and snippets.

View yanzhihong23's full-sized avatar
🏠
Working from home

Hom yanzhihong23

🏠
Working from home
View GitHub Profile
@yanzhihong23
yanzhihong23 / LRUCache-class.js
Last active September 24, 2020 08:25
LRUCache
class LRUCache {
constructor(size) {
this.size = size;
this.cache = new Map();
}
put(key, value) {
const { cache, size } = this;
if(cache.has(key)) {
cache.delete(key);
@yanzhihong23
yanzhihong23 / cookie.js
Created July 26, 2019 04:01
Get cookie object
@yanzhihong23
yanzhihong23 / curry.js
Created December 26, 2018 05:14
curry multi add
function curry(fn) {
var res;
function curried() {
args = [].slice.call(arguments);
if (!res && args.length == fn.length) {
res = fn.apply(this, args);
return curried;
} else if (!res && args.length > fn.length) {
res = fn.apply(this, args);
@yanzhihong23
yanzhihong23 / demo.js
Last active December 23, 2018 08:29
Promise.all handle exceptions
function fetchData(x) {
return new Promise((resolve, reject) => {
// mock
if (x == 3 || x == 4 || x == 5) {
reject('error');
} else {
resolve(x);
}
});
}
function to64bitFloat(number) {
var i, result = "";
var dv = new DataView(new ArrayBuffer(8));
dv.setFloat64(0, number, false);
for (i = 0; i < 8; i++) {
var bits = dv.getUint8(i).toString(2);
if (bits.length < 8) {
bits = new Array(8 - bits.length).fill('0').join("") + bits;
@yanzhihong23
yanzhihong23 / shell.md
Created June 26, 2017 03:15
centos update server time
yum install ntp
chkconfig ntpd on
ntpdate pool.ntp.org
service ntpd start
@yanzhihong23
yanzhihong23 / scroll-iframe-ios.css
Last active June 10, 2017 08:03
Scroll IFRAMEs on iOS
.scroll-wrapper {
-webkit-overflow-scrolling: touch !important;
overflow-y: scroll !important;
position: fixed;
right: 0;
bottom: 0;
left: 0;
top: 0;
}
@yanzhihong23
yanzhihong23 / shell.md
Last active June 1, 2017 06:19
Fix nvm ls-remote N/A
export NVM_NODEJS_ORG_MIRROR=http://nodejs.org/dist
@yanzhihong23
yanzhihong23 / avenger-nginx.conf
Created May 19, 2017 11:15
nginx config for angular app deploy in subpath
server {
server_name gist.github.com
root /usr/share/gist;
index index.html
location / {
try_files $uri $uri/ =404;
}
location /avenger/ {
@yanzhihong23
yanzhihong23 / pm2-guard.js
Created April 28, 2017 10:24
pm2 cpu guard
'use strict';
const later = require('later');
const logger = require('./logger')('guard');
const pm2 = require('pm2');
const schedule = later.parse.recur().every(10).second();
// set local timezone
later.date.localTime();