Skip to content

Instantly share code, notes, and snippets.

@ChJJin
ChJJin / doItAgain.js
Last active August 8, 2016 12:13
wrap a function that would do it again easily.
function wrapper(cb){
var args, that;
function doItAgain(){
cb.apply(that, args);
}
function execute(){
that = this;
args = [].slice.call(arguments, 0);
@ChJJin
ChJJin / Surfingkeys.setting.js
Last active April 1, 2022 17:29
Surfingkeys setting
// scroll setting
unmaps('u, e');
mapkey('u', '#2Scroll a page up', 'Normal.scroll("pageUp")', {repeatIgnore: true});
unmaps('E, R');
mapkey('J', '#3Go one tab left', 'RUNTIME("previousTab")');
mapkey('K', '#3Go one tab right', 'RUNTIME("nextTab")');
unmaps('B, F, S, D, H, L');
mapkey('H', '#4Go back in history', 'history.go(-1)');
@ChJJin
ChJJin / json.stringify.js
Created August 2, 2017 10:42 — forked from composite/json.stringify.js
JSON stringify with escape unicode characters. http://stackoverflow.com/a/4901205/489575
function JSON_stringify(s, emit_unicode)
{
var json = JSON.stringify(s);
return emit_unicode ? json : json.replace(/[\u007f-\uffff]/g,
function(c) {
return '\\u'+('0000'+c.charCodeAt(0).toString(16)).slice(-4);
}
);
}
function formatDuration(dur) {
const timeRange = [60, 60, 24, 1000];
const units = ['秒', '分钟', '小时', '天'];
let i = 0;
let total = dur;
function getUnitStr(pad) {
const larger = (total / timeRange[i]) >= 1;
const base = total % timeRange[i];
if (base === 0) return '';