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 / index.js
Last active April 18, 2019 09:02
compress image
function compress(canvasDom, size){
let ratio = 1;
let dataurl;
do {
dataurl = canvasDom.toDataURL("image/jpeg", ratio);
ratio -= 0.1;
if (ratio < 0.3) {
return null;
}
} while (dataurl.length > size/3*4);
@blackmiaool
blackmiaool / index.js
Created February 3, 2019 14:26
format date
Date.prototype.format = function(format) {
const zeros = ["", "0", "00", "000"];
const c = {
"M+": this.getMonth() + 1,
"d+": this.getDate(),
"h+": this.getHours(),
"m+": this.getMinutes(),
"s+": this.getSeconds(),
"q+": Math.floor((this.getMonth() + 3) / 3),
"S+": this.getMilliseconds()
@blackmiaool
blackmiaool / .zshrc
Last active September 8, 2018 12:53
zsh
# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH
# Path to your oh-my-zsh installation.
export ZSH="/home/blackmiaool/.oh-my-zsh"
# Set name of the theme to load --- if set to "random", it will
# load a random theme each time oh-my-zsh is loaded, in which case,
# to know which specific one was loaded, run: echo $RANDOM_THEME
# See https://github.com/robbyrussell/oh-my-zsh/wiki/Themes
@blackmiaool
blackmiaool / a.sh
Last active September 8, 2018 08:37
set up ubuntu env
# shorten up prompt
echo "PS1=\"\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@xiaomi:\[\033[01;34m\]\w\[\033[00m\]\$ \"" >> ~/.bashrc
@blackmiaool
blackmiaool / .dockerfile
Last active September 3, 2018 15:14
my dev image
FROM ubuntu
RUN apt-get update
RUN apt-get install -y man emacs
@blackmiaool
blackmiaool / sortable-table.vue
Last active October 31, 2022 17:44
sortable el-table
<template>
<div ref="wrapper">
<div :key="tableKey">
<slot></slot>
</div>
</div>
</template>
<script>
/*
@blackmiaool
blackmiaool / index.js
Last active June 24, 2018 07:54
getCircularKeys
function getCircularKeys(obj,opt={left:100}){
if(!obj||typeof obj!=='object'){
return ;
}
let keys=Object.keys(obj);
function appendKeys(keys){
opt.left-=keys.length;
if(opt.left<=0){
return true;
}
function solution(line) {
const [ll, lr] = line.split(" ");
const arr = ll.split(",").map(a => a * 1);
const target = lr * 1;
return ret;
}
@blackmiaool
blackmiaool / index.js
Last active January 22, 2018 03:30
try to open app
function checkOpen() {
const clickTime = Date.now();
let timeout;
let count = 0;
return new Promise((resolve, reject) => {
const interval = setInterval(() => {
count++;
timeout = Date.now() - clickTime > 3000;
if (count >= 10 || timeout) {
clearInterval(interval);
@blackmiaool
blackmiaool / index.js
Last active December 25, 2021 08:25
parallelTask
module.exports = async function parallelTask(task, shouldEnd, max) {
let i = 0;
let runningCnt = 0;
return new Promise((resolve, reject) => {
function check() {
if (shouldEnd(i)) {
return;
}
if (runningCnt > max) {
return;