Skip to content

Instantly share code, notes, and snippets.

View mrxf's full-sized avatar
🚀
努力工作中

张树源 mrxf

🚀
努力工作中
View GitHub Profile
@mrxf
mrxf / prng.js
Created April 10, 2016 16:14 — forked from Protonk/prng.js
Various PRNGs, implemented in javascript.
// 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
@mrxf
mrxf / ripple.js
Created April 25, 2017 10:11
material ripple effect
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');
@mrxf
mrxf / @sleep.ts
Last active June 12, 2017 09:33
@decorator 装饰器
/**
* 控制一个函数延后执行
* @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)
/**
* 定义一个函数,里面带有一个方法
* 在不修改该方法的条件下,获取到o中所有的属性名
*/
var foo = (function(){
var o = {
a: 1,
b: 2,
/**更多属性**/
};
@mrxf
mrxf / get-medium-media.js
Created July 28, 2017 02:24
获取medium中的音频media
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) => {
@mrxf
mrxf / parser-article.js
Created July 28, 2017 02:32
使用article parser提取网页内容
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'],
@mrxf
mrxf / get-param-by-name.js
Created January 29, 2018 06:37
url操作
/**
* 根据参数名获取参数值
* @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);
@mrxf
mrxf / global-storage.js
Created January 29, 2018 08:36
store your date in global
/**
* tool for store data in global
*/
class GlobalStorage{
/**
* init Global Storage
* @param {string} globalKey key for store
*/
constructor(globalKey = "app") {
this.globalKey = globalKey;
@mrxf
mrxf / compare.js
Created January 30, 2018 03:14
compare two differ between two Array
const lastMonthData = [
{
id: 1,
name: "Alex",
salary: 15662
},
{
id: 2,
name: "Tom",
salary: 18672
@mrxf
mrxf / ts-overload.ts
Created March 26, 2020 08:13
typescript函数重载
export class TestClass {
someMethod(): number;
someMethod(str: string): string;
someMethod(str?: string) {
if ( typeof str === 'string' ) {
return str + '123';
} else {
return Math.random();
}