Skip to content

Instantly share code, notes, and snippets.

View ifyour's full-sized avatar
🏁
问题解决师

明明 ifyour

🏁
问题解决师
View GitHub Profile
@ifyour
ifyour / css-debugger.js
Last active May 10, 2020 02:04
JavaScript 书签,生成工具:https://mrcoles.com/bookmarklet/
!window.isDebugging && (window.isDebugging = false);
isDebugging ? disableDebugger() : enableDebugger();
function enableDebugger() {
document.querySelectorAll("*").forEach((elm) => {
elm.style.outline =
"1px solid #" + (~~(Math.random() * (1 << 24))).toString(16);
});
isDebugging = true;
}
import fetch from "node-fetch";
const api = "https://jsonbase.com/";
export default class Bucket {
constructor(name) {
this.name = name;
}
async get(key) {
@ifyour
ifyour / machine.js
Created April 4, 2020 04:25
Generated by XState Viz: https://xstate.js.org/viz
const stateMachine = Machine({
initial: 'idle',
states: {
idle: {
on: {
SUBMIT: 'loading',
},
},
loading: {
on: {
@ifyour
ifyour / .npmrc
Last active December 25, 2019 15:00
解决依赖下载慢都问题,临时在项目根目录新建以下文件,分别适用于 Yarn/Npm
sass_binary_site=https://npm.taobao.org/mirrors/node-sass/
phantomjs_cdnurl=https://npm.taobao.org/mirrors/phantomjs/
electron_mirror=https://npm.taobao.org/mirrors/electron/
registry=https://registry.npm.taobao.org
@ifyour
ifyour / usage.sh
Created December 10, 2019 05:03
使用 gifsicle 压缩 gif
# 安装
$ brew install gifsicle
# 使用
$ gifsicle -O3 --lossy=80 -o output.gif input.gif
# 文档
$ gifsicle --help
@ifyour
ifyour / ts2mp4.sh
Last active December 6, 2019 08:02
使用 ffmpeg 转换流媒体文件到 MP4
# 设置快捷方式 保存到 ~/.zshrc
$ alias ts2mp4="ffmpeg -i ./*.ts -c:v libx264 -c:a copy output.mp4"
@ifyour
ifyour / es6.js
Last active December 7, 2019 08:38
ES6 class 中如何使用闭包
const MyObject = (() => {
let id = 0;
return class MyObject {
constructor() {
this.id = id++;
}
};
})();
@ifyour
ifyour / log.js
Last active November 4, 2019 10:16
装饰器模式实现数据埋点
Function.prototype.after = function(afterFn) {
const __this = this;
return function() {
const ret = __this.apply(this, arguments);
afterFn.apply(this, arguments);
return ret;
}
}
let showLogin = function() {
@ifyour
ifyour / after.js
Last active November 3, 2019 09:55
巧妙扩展 Function 原型,实现职责链模式
// eslint-disable-next-line no-extend-native
Function.prototype.after = function(fn) {
const _this = this;
return function() {
const ret = _this.apply(this, arguments);
if (ret === 'nextSuccessor') {
return fn.apply(this, arguments);
}
return ret;
}
@ifyour
ifyour / list2tree.js
Created October 16, 2019 02:28
列表转树形结构
// Data Set
// One top level comment
const comments = [
{
id: 1,
parent_id: null
},
{
id: 2,
parent_id: 1