Skip to content

Instantly share code, notes, and snippets.

View blackmiaool's full-sized avatar
🏠
Working from home

blackmiaool blackmiaool

🏠
Working from home
View GitHub Profile
@blackmiaool
blackmiaool / A and C.js
Last active June 11, 2017 05:37
leetcode tools
const A=(function (){
const cache={};
return function(num,base){
const key=num+'-'+base;
if(cache[key]){
return cache[key];
}
let ret=1;
for(var i=0;i<num;i++){
ret*=base-i;
@blackmiaool
blackmiaool / ipcRenderer.js
Last active May 7, 2017 06:02
make electron ipc support callback
let cbUid = 0;
const cbMap = {};
ipcRenderer.send = function(event, ...args) {
const last = args[args.length - 1];
if (typeof last === "function") { //callback
cbMap[cbUid] = last;
args[args.length - 1] = "callback-" + cbUid;
cbUid++;
}
return preSend.call(ipcRenderer, event, ...args);
@blackmiaool
blackmiaool / index.js
Last active January 26, 2020 12:12
preload image
function preloadImage(src) {
const $dom = $("<img />", {
src
});
if ($dom[0].naturalWidth) {
return Promise.resolve($dom);
}
$dom.css({
opacity: 0.01,
@blackmiaool
blackmiaool / index.js
Last active March 29, 2017 08:42
import2require (copy to console to execute)
var test = `
import a from b;
import {a,b} from c;
import a,b,{c,d},{e,f} from c;
import a,{
b,
c,} from d;
alert("hi!");
`;
function getDataGradually(data, childKey, gap, count, updateCb, finishCb) {
const lastPositon = [];
const linearData = [];
const ret = [];
function getLinearData(arr, position) {
arr.forEach(function (obj, index) {
const pos = position.concat([index]);
if (obj[childKey] && obj[childKey].length) {
const treeify = require('file-tree-sync');
const fs=require('fs');
const linearData = [];
const ret = [];
const childKey = "files";
function getLinearData(arr, position) {
arr.forEach(function (obj, index) {
class A {
componentWillMount() { // base first
console.warn("A1");
}
componentDidMount() {
console.warn("A2");
}
componentWillUnmount() {
console.warn("A3");
}
@blackmiaool
blackmiaool / .bashrc
Last active June 24, 2018 06:04
git shorthand
alias gls='git status'
alias gdf='git diff'
alias glg='git log'
alias gam='git commit -am'
alias gaa='git add -A :/'
alias np='npm publish'
alias op='xdg-open'
@blackmiaool
blackmiaool / addParam.js
Last active October 26, 2018 09:58
addParam
export function addParam(url, key, value) {
url = url.replace(new RegExp(`[?&]${key}=[^&]*&?`, 'g'), str => (str[str.length - 1] === "&" ? str[0] : ""));
const hashReg = /#[\w-]+$/;
let hash = url.match(hashReg) || [];
hash = hash[0] || "";
url = url.replace(hashReg, "");
let linkSymbol = "&";
if (url.indexOf("?") === -1) {
linkSymbol = "?";
}
function dailyTask(time, task) {
var gap = (new Date("1970-1-1 " + time)).getTime() - (Date.now()) % (24 * 36e5);
if (gap < 0) {
gap += 24 * 36e5;
}
setTimeout(function() {
task();
setInterval(task, 24 * 36e5);
}, gap);
}