Skip to content

Instantly share code, notes, and snippets.

View kiinlam's full-sized avatar
:octocat:
hard working

kiinlam kiinlam

:octocat:
hard working
View GitHub Profile
@kiinlam
kiinlam / pipeline-in-es6.js
Last active June 10, 2019 11:05
es6实现pipeline效果
function pipe(data, ...args) {
return args.reduce((r, f) => f(r), data);
}
//test
function f1(a) {
a.pop();
return a;
}
function f2(a) {
@kiinlam
kiinlam / nginx-set-https-on-windows.txt
Last active March 19, 2024 02:31
Windows下用Nginx配置https服务器
1、安装openssl:http://slproweb.com/products/Win32OpenSSL.html。
2、设置环境变量
a)新建变量:OPENSSL_HOME => C:\OpenSSL-Win64\bin;
b)Path变量添加:%OPENSSL_HOME%。
3、创建私钥
C:\nginx\ssl> openssl genrsa -des3 -out [name].key 1024
[name]为文件名,任意
输入密码,完成
(function (url) {
var script = document.createElement("script");
script.src = url;
var n = document.getElementsByTagName("script")[0];
n.parentNode.insertBefore(script, n);
})(url);
@kiinlam
kiinlam / document.documentElement-and-document.body.js
Created March 29, 2018 08:37
document.documentElement和document.body的区别
// scrollHeight 内容完整高度
scrollHeight = document.compatMode === "CSS1Compat" ? document.documentElement.scrollHeight : document.body.scrollHeight;
// or
scrollHeight = Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
// scrollTop 滚动高度
scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
// clientHeight 可视高度
clientHeight = document.compatMode === "CSS1Compat" ? document.documentElement.clientHeight : document.body.clientHeight;
@kiinlam
kiinlam / tco.js
Created November 22, 2017 07:08
尾递归优化tco
function tco(f) {
var value;
var active = false;
var accumulated = [];
return function accumulator() {
accumulated.push(arguments);
if (!active) {
active = true;
while (accumulated.length) {
@kiinlam
kiinlam / thousandfy.js
Created November 17, 2017 08:02
数值增加千分位分隔,保留小数部分
function thousandfy(value) {
let re = /\d{1,3}(?=(\d{3})+$)/g;
return String(value).replace(/^(\d+)((\.\d+)?)$/, (s, s1, s2) => s1.replace(re, "$&,") + s2)
}
thousandfy('24426295.93') // => 24,426,295.93
@kiinlam
kiinlam / RemainingTime.js
Last active February 10, 2017 08:27
倒计时 Remaining time
function remainingTime (rt) {
var hour = (rt | 0)/(3600*1000) | 0,
minute = ((rt | 0)%(3600*1000))/(60*1000) | 0,
second = ((rt | 0)%(3600*1000)%(60*1000))/1000 | 0;
if (rt <= 0) {
return;
} else {
setTimeout(function(){
remainingTime(rt - 1000);
@kiinlam
kiinlam / isElementInViewport.js
Created January 4, 2017 08:25
Check an Element In Viewport
function isElementInViewport (el) {
//special bonus for those using jQuery
if (typeof jQuery === "function" && el instanceof jQuery) {
el = el[0];
}
var rect = el.getBoundingClientRect();
return (
@kiinlam
kiinlam / cookies.js
Created January 4, 2017 03:19
cookies.js 一个完整支持unicode的cookie读取/写入器
/*\
|*|
|*| :: cookies.js ::
|*|
|*| A complete cookies reader/writer framework with full unicode support.
|*|
|*| https://developer.mozilla.org/en-US/docs/DOM/document.cookie
|*|
|*| This framework is released under the GNU Public License, version 3 or later.
|*| http://www.gnu.org/licenses/gpl-3.0-standalone.html
@kiinlam
kiinlam / mapConvert.js
Created November 24, 2016 09:32
mapToObj, mapToObjArray, objToMap
function mapToObj (map) {
let obj = Object.create(null)
for (let [k,v] of map) {
obj[k] = v
}
return obj
}
function mapToObjArray (map) {
let objArray = []