This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Linear Congruential Generator | |
// Variant of a Lehman Generator | |
var lcg = (function() { | |
// Set to values from http://en.wikipedia.org/wiki/Numerical_Recipes | |
// m is basically chosen to be large (as it is the max period) | |
// and for its relationships to a and c | |
var m = 4294967296, | |
// a - 1 should be divisible by m's prime factors | |
a = 1664525, | |
// c and m should be co-prime |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function RippleEffect(element){ | |
this.element = element; | |
this.element.addEventListener('mousedown', this.run.bind(this), false); | |
} | |
RippleEffect.prototype = { | |
run: function(event){ | |
var ripplerContainer = this.element.querySelector('.ripple-container'); | |
var offsetInfo = this.element.getBoundingClientRect(); | |
var rippleContainer = document.createElement('div'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 控制一个函数延后执行 | |
* @param tick 休眠时间 | |
*/ | |
function sleep(tick: number){ | |
return (target: any, propertyKey: string, descriptor: PropertyDescriptor) => { | |
let method = descriptor.value; | |
descriptor.value = (...args: any[]) =>{ | |
setTimeout(()=>{ | |
method.apply(target, args) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 定义一个函数,里面带有一个方法 | |
* 在不修改该方法的条件下,获取到o中所有的属性名 | |
*/ | |
var foo = (function(){ | |
var o = { | |
a: 1, | |
b: 2, | |
/**更多属性**/ | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const request = require('request') | |
const cheerio = require('cheerio') | |
const url = 'https://medium.com/@leighalexander/the-underground-world-of-magical-resistance-on-the-internet-6c854e567347'; | |
const audioUrl = /https:\/\/cdn-audio.*m4a/g; | |
const reqOpt = { | |
url: url | |
} | |
request(reqOpt, (error, res, body) => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var ArticleParser = require('article-parser'); | |
var he = require('he'); | |
var url = 'http://mp.weixin.qq.com/s/JJbZkcBoSMW0zPzmepUr1A'; | |
ArticleParser.configure({ | |
htmlRules:{ | |
allowedTags: [ 'pre', 'p', 'img' ], | |
allowedAttributes: { | |
pre: ['style'], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 根据参数名获取参数值 | |
* @param {string} name 参数名 | |
* @param {string} [url] 地址 | |
*/ | |
function getParameterByName(name, url) { | |
if (!url) url = window.location.href; | |
name = name.replace(/[\[\]]/g, "\\$&"); | |
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"), | |
results = regex.exec(url); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* tool for store data in global | |
*/ | |
class GlobalStorage{ | |
/** | |
* init Global Storage | |
* @param {string} globalKey key for store | |
*/ | |
constructor(globalKey = "app") { | |
this.globalKey = globalKey; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const lastMonthData = [ | |
{ | |
id: 1, | |
name: "Alex", | |
salary: 15662 | |
}, | |
{ | |
id: 2, | |
name: "Tom", | |
salary: 18672 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class TestClass { | |
someMethod(): number; | |
someMethod(str: string): string; | |
someMethod(str?: string) { | |
if ( typeof str === 'string' ) { | |
return str + '123'; | |
} else { | |
return Math.random(); | |
} |
OlderNewer