Skip to content

Instantly share code, notes, and snippets.

CRIMX crimx

View GitHub Profile
@crimx
crimx / reactive.js
Last active Apr 5, 2018
Thoughts on reactive implementation
View reactive.js
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 Feb 28, 2018 — forked from jacobbubu/countries.json
Chinese country names and their ISO code
View countries.json
[
{
"ISO2": "AD",
"ISO3": "AND",
"DIGITS": "20",
"ISO-3166-2": "ISO 3166-2:AD",
"English": " Andorra",
"China": "安道尔",
"Taiwan": "安道爾",
"Hongkong": "安道爾",
View promise-more.js
/**
* 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 Mar 18, 2017
应急使用,合并两个中英 srt 字幕为上中下英双语,使用字幕组的 ass 样式。两个字幕在不同的 layer 所以允许保留各自的时间,不需要人工调整。先 npm install subtitles-parser
View Drag&Drop.cmd
node %~dp0\index.js %*
@crimx
crimx / mofun.js
Created May 6, 2016
mofun avatar
View mofun.js
$("#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 Apr 7, 2016
Make any function singleton
View singletonify.js
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 Feb 2, 2016
把所有微博设为“自己可见”。
View weibo-hide.js
// 把所有微博设为“自己可见”。基于档案娘助手修改,提高稳定减少卡死。
$(function() {
var mids = [];
var pageRecord = [];
var oldSearch = window.location.search;
var page = getPage();
// 获得当前页码
function getPage() {
return parseSearch().page;
@crimx
crimx / count-letters.js
Created Dec 3, 2015
计算字符串中出现最多的字符和次数
View count-letters.js
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 Aug 29, 2015
Bottom-up DP for longest common substring (not subsequence). http://jsperf.com/crimx-lcstr/2
View lcstr.js
/**
* 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 Aug 29, 2015
请编写一个 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
View parseQueryString.js
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;
}
You can’t perform that action at this time.