Skip to content

Instantly share code, notes, and snippets.

View XiongLiding's full-sized avatar

XiongLiding XiongLiding

View GitHub Profile
@XiongLiding
XiongLiding / valineCommentToCSV.js
Last active December 11, 2020 03:47
将valine导出的评论转换成CSV格式,方便导入自建数据库(如 waline 的 wl_comment 表)
/**
* trans
* 将valine导出的评论转换成CSV格式
* @param {String} input - 从 valine 导出的 JSON 文本
* @return {String} CSV 文本
*/
const trans = input => {
let output = [];
const field = [
"nick",
@XiongLiding
XiongLiding / nestGroupBy.js
Created June 16, 2020 12:23
通过递归实现任意级别的分组功能,第一个参数是作为分组依据的函数的数组,第二个参数是初始的数据数组
const { map, groupBy } = require("rambda");
const nestGroupBy = ([fn, ...fns], list) => {
if (!fn) {
return list;
}
const g = groupBy(fn, list);
return map(v => {
return nestGroupBy(fns, v);
}, g);
@XiongLiding
XiongLiding / samplingRate.coffee
Created April 23, 2014 04:04
use samplingRate to limit the frequency of event trigger
# Define samplingRate
samplingRate = (interval) ->
mark = 0
->
now = Date.now()
return false if now - mark < interval
mark = now
# How to use
sampling = samplingRate 1000
@XiongLiding
XiongLiding / readme.markdown
Last active December 21, 2015 12:18
从调用函数 timeTrigger 开始,在 time 指定的时间内,每隔一段时间 interval ,执行一次回调函数 trigger ,并且每次执行时,都带有当前进度。 可用于实现动画等效果。

使用示例:

timeTrigger(5000, 1000, function (percent) {
    console.log(percent);   
});

回调函数中的 percent 用来返回当前执行的进度,数值在 0 - 1 之间,执行结果如下:

0

0.2002