Skip to content

Instantly share code, notes, and snippets.

View crimx's full-sized avatar

CRIMX crimx

View GitHub Profile
@crimx
crimx / reactive.js
Last active April 5, 2018 07:57
Thoughts on reactive implementation
function compose (...funcs) {
if (funcs.length <= 0) {
return x => x
}
if (funcs.length === 1) {
return funcs[0]
}
const innerFunc = funcs[funcs.length - 1]
const restFunc = funcs.slice(0, -1)
@crimx
crimx / countries.json
Last active February 28, 2018 18:12 — forked from jacobbubu/countries.json
Chinese country names and their ISO code
[
{
"ISO2": "AD",
"ISO3": "AND",
"DIGITS": "20",
"ISO-3166-2": "ISO 3166-2:AD",
"English": " Andorra",
"China": "安道尔",
"Taiwan": "安道爾",
"Hongkong": "安道爾",
@crimx
crimx / promise-more.js
Created July 28, 2017 05:05
Promise helper
/**
* Like Promise.all but is always successful.
* @param {Array|Object} iterable
* @returns {Promise} A promise with an array of all the resolved/rejected results. null for rejection.
*/
export const reflect = function reflect (iterable) {
if (!Array.isArray(iterable)) {
iterable = Array.from(iterable)
}
@crimx
crimx / Drag&Drop.cmd
Last active March 18, 2017 11:50
应急使用,合并两个中英 srt 字幕为上中下英双语,使用字幕组的 ass 样式。两个字幕在不同的 layer 所以允许保留各自的时间,不需要人工调整。先 npm install subtitles-parser
node %~dp0\index.js %*
@crimx
crimx / mofun.js
Created May 6, 2016 22:15
mofun avatar
$("#user_photo_upload").upload("/index.php?act=upload&mdl=upload&is_temp=1", function(ret) {
var ret_url = ret.url.replace('/', '\/');
if (ret.status === 'ok') {
$.ajax({
type: 'POST',
url: "/index.php?act=ajax&mdl=user_photo&func=user_photo_save",
data: {
"photo": {
"240x240_f": ret.filename,
"240x240_url": ret_url,
@crimx
crimx / singletonify.js
Created April 7, 2016 02:18
Make any function singleton
function singletonify(_Class) {
if (typeof singletonify.prototype._singletonifyInstances === 'undefined') {
singletonify.prototype._singletonifyInstances = [];
}
var _instances = singletonify.prototype._singletonifyInstances;
var _index = _instances.push(void(0)) - 1;
function genSingleton() {
if (typeof _instances[_index] !== 'undefined') {
return _instances[_index];
} else {
@crimx
crimx / weibo-hide.js
Created February 2, 2016 14:23
把所有微博设为“自己可见”。
// 把所有微博设为“自己可见”。基于档案娘助手修改,提高稳定减少卡死。
$(function() {
var mids = [];
var pageRecord = [];
var oldSearch = window.location.search;
var page = getPage();
// 获得当前页码
function getPage() {
return parseSearch().page;
@crimx
crimx / count-letters.js
Created December 3, 2015 09:05
计算字符串中出现最多的字符和次数
function count(s) {
var r = s.split('')
.sort()
.join('')
.match(/(\w)\1*/g)
.sort(function(a,b) {
return a.length < b.length
});
return {
letter: r[0],
@crimx
crimx / lcstr.js
Last active August 29, 2015 14:06
Bottom-up DP for longest common substring (not subsequence). http://jsperf.com/crimx-lcstr/2
/**
* Bottom-up DP for longest common substring (not subsequence).
* Time: O(m*n)
* Space: O(min(m,n))
* @author Jesse Wong (@straybugs)
*/
function lcstr(sstr, lstr) {
'use strict';
@crimx
crimx / parseQueryString.js
Last active August 29, 2015 14:05
请编写一个 JavaScript 函数 parseQueryString,它的用途是把 URL 参数解析为一个对象,如:var url = "http://www.taobao.com/index.php?key0=0&key1=1&key2=2"; var obj = parseQueryString(url); alert(obj.key0); // 输出0
function parseQueryString(str){
var pairs = str.replace(/^.*\?/, '').split('&'),
res = {};
for (var i = pairs.length - 1; i > 0; i -= 1) {
var p = pairs[i].split('=');
res[p[0]] = p[1];
}
return res;
}