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 / convert_radix.js
Last active September 7, 2020 02:51
[js进制转换]
// toString(radix)
// 任意数值转为指定进制
0x6600.toString(2) // "110011000000000"
// parseInt(value, radix)
// 将value作为指定进制radix来解析,得到10进制结果
parseInt("110011000000000",2) // 26112
// 任意进制相互转换
// 先转10进制,再换成目标进制
@kiinlam
kiinlam / delay.js
Created September 9, 2019 06:28
delay some time
const delay = timeout => new Promise(resolve => setTimeout(resolve, timeout));
@kiinlam
kiinlam / DJBHash.java
Last active July 9, 2019 01:34
哈希函数,Daniel J.Bernstein 教授发明的,是目前公布的最有效的哈希函数
public long DJBHash(String str)
{
long hash = 5381;
for(int i = 0; i < str.length(); i++)
{
hash = ((hash << 5) + hash) + str.charAt(i);
}
return hash;
}
@kiinlam
kiinlam / hash.js
Last active February 24, 2021 07:52
time 33 哈希函数
/**
A string hashing function based on Daniel J. Bernstein's popular 'times 33' hash algorithm.
@param {string} text - String to hash
@return {number} Resulting number.
*/
function hash(text) {
'use strict';
var hash = 5381,
index = text.length;
@kiinlam
kiinlam / documentCopy.js
Created July 2, 2019 02:44
document.execCommand("copy")
n.copy = function(e, n, o) {
var c = d('<span class="my-gallery-src-copy-hidden">' + e + "</span>")
, s = d("body");
s.append(c);
var a = document.createRange();
a.selectNode(c.get(0));
var i = window.getSelection();
i.removeAllRanges(),
i.addRange(a);
var t = document.execCommand("copy");
@kiinlam
kiinlam / utf16EncodeDecode.js
Created May 17, 2019 01:56
Javascript \x 反斜杠x 16进制 编解码
// js 里 \x 开头的通常是16进制编码的数据,下面代码实现编解码:
// 解码
//eg.
//decode('\x5f\x63\x68\x61\x6e\x67\x65\x49\x74\x65\x6d\x43\x72\x6f\x73\x73\x4c\x61\x79\x65\x72')
//"_changeItemCrossLayer"
function decode(str){
return str.replace(/\\x(\w{2})/g,function(_,$1){ return String.fromCharCode(parseInt($1,16)) });
}
@kiinlam
kiinlam / registry.npm.taobao.md
Last active April 30, 2019 07:56
淘宝NPM源的设置
function combine(arr, num) {
var r = [];
(function f(t, a, n) {
if (n == 0) return r.push(t);
for (var i = 0, l = a.length; i <= l - n; i++) {
f(t.concat(a[i]), a.slice(i + 1), n - 1);
}
})([], arr, num);
return r;
}
// 适用于处理二维数组: ([['a','b'],['c'],['d']],2) --> [[["a","b"],["c"]],[["a","b"],["d"]],[["c"],["d"]]]
function dp_combine(a, m) {
var t = [[]], r = [];
for (var i = 0, n = a.length; i < n; ++i) {
for (var j = 0, l = t.length; j < l; ++j) {
(t[j].length < m - 1 ? t : r).push(t[j].concat([a[i]]));
}
}
return r;
}
@kiinlam
kiinlam / curry-in-es6.js
Created March 12, 2019 11:27
es6柯里化
//es5
function add(a, b) {
return a + b;
}
var curriedAdd = _.curry(add);
var add2 = curriedAdd(2);
add2(1);// 3
//es6