Skip to content

Instantly share code, notes, and snippets.

View xinlc's full-sized avatar
🌴
On vacation

Richard Xin xinlc

🌴
On vacation
View GitHub Profile
@xinlc
xinlc / quicklz-js.js
Created May 6, 2020 02:35
QuickLZ port to Javascript
/*QuickLZ Port to Javascript*/
var QLZ = QLZ ||
{
REVISION : '1'
};
(function(){
// Streaming mode not supported
@xinlc
xinlc / LevenshteinDistance.js
Last active May 3, 2020 11:11
similarity算法,编辑距离
function compare(x, y) {
var z = 0;
var s = x.length + y.length;;
x.sort();
y.sort();
var a = x.shift();
var b = y.shift();
while(a !== undefined && b !== undefined) {
@xinlc
xinlc / Md5Utils1.java
Created April 23, 2020 07:52
Md5Utils
import org.apache.commons.codec.binary.Hex;
import java.security.MessageDigest;
import java.util.Random;
public class Md5Utils {
/**
* 加盐MD5加密
* <p>
@xinlc
xinlc / capture_articles.py
Created February 14, 2020 01:17 — forked from 2019ncovmemory/capture_articles.py
Create screenshots of articles; work for WeChat articles with lazy loading.
'''
Usage: python archive_articles.py test.csv
Input: test.csv
name url
1 url1
2 url2
.....
output:
1.png
2.png
@xinlc
xinlc / CallOnceInInterval.js
Created August 1, 2019 03:51
JS 防止快速重复点击
let isCalled = false, timer;
/**
* @param functionTobeCalled 被包装的方法
* @param interval 时间间隔,可省略,默认600毫秒
*/
export default callOnceInInterval = (functionTobeCalled, interval = 600) => {
if (!isCalled) {
isCalled = true;
clearTimeout(timer);
@xinlc
xinlc / Base64ImageUtil.java
Last active July 31, 2019 05:22
java 处理图片 Base64
package test;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
import javax.imageio.ImageIO;
import javax.xml.bind.DatatypeConverter;
import java.awt.image.BufferedImage;
import java.io.*;
import java.util.UUID;
@xinlc
xinlc / PubSub.js
Last active June 20, 2019 05:16
发布-订阅模式
// 发布订阅模式中统一由调度中心进行处理,订阅者和发布者互不干扰。这样一方面实现了解耦,还有就是可以实现更细粒度的一些控制。
// 比如发布者发布了很多消息,但是不想所有的订阅者都接收到,就可以在调度中心做一些处理,类似于权限控制之类的。还可以做一些节流操作。
// 在发布订阅模式中,组件是松散耦合的,正好和观察者模式相反。
// 发布-订阅模式大多数时候是异步的(使用消息队列)。
class PubSub {
constructor() {
this.subscribers = {}
}
subscribe(type, fn) {
@xinlc
xinlc / Observer.js
Last active June 20, 2019 05:03
观察者模式
// 在观察者模式中,观察者是知道Subject的,Subject一直保持对观察者进行记录。
// 观察者模式大多数时候是同步的,比如当事件触发,Subject就会去调用观察者的方法。
// 观察者
class Observer {
constructor() {
}
update(val) {
console.log(val);
@xinlc
xinlc / ClassUtil.java
Created April 19, 2019 03:58
取得某个接口下所有实现这个接口的类
import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import java.net.JarURLConnection;
import java.net.URL;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
@xinlc
xinlc / topview.js
Created January 28, 2019 07:43 — forked from mactive/topview.js
rn-topview
/**
* mactive@gmail.com
* 2017-05-08
*/
'use strict';
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,