Skip to content

Instantly share code, notes, and snippets.

View wangdahoo's full-sized avatar
🎯
Focusing

王大虎 wangdahoo

🎯
Focusing
  • Shanghai
View GitHub Profile
@wangdahoo
wangdahoo / parasitic-composition-inheritance.js
Created July 21, 2020 13:43
Parasitic Composition Inheritance
// 寄生组合继承 (相对完美的继承范式)
// 父类
function Animal (name) {
// 实例方法
this.name = name
this.sleep = function () {
console.log(`${this.name} is sleeping...`)
}
@wangdahoo
wangdahoo / redux.js
Created April 22, 2020 16:11
Tiny Redux in 40 Lines
// Tiny Redux
export const combineReducers = reducers => {
return (state = {}, action) => {
return Object.keys(reducers).reduce(
(nextState, key) => {
nextState[key] = reducers[key](state[key], action)
return nextState
},
{}
@wangdahoo
wangdahoo / Logger.ts
Created November 29, 2019 17:01
Logger
enum LoggerLevel {
VERBOSE = 0,
DEBUG = 1,
INFO = 2,
WARN = 3,
ERROR = 4
}
enum ConsoleMethod {
log = 'log',
@wangdahoo
wangdahoo / rem.html
Created October 2, 2019 07:42
rem script
<script>!function(e,t){function n(){t.body?t.body.style.fontSize=12*o+"px":t.addEventListener("DOMContentLoaded",n)}function d(){var e=i.clientWidth/10;i.style.fontSize=e+"px"}var i=t.documentElement,o=e.devicePixelRatio||1;if(n(),d(),e.addEventListener("resize",d),e.addEventListener("pageshow",function(e){e.persisted&&d()}),o>=2){var a=t.createElement("body"),s=t.createElement("div");s.style.border=".5px solid transparent",a.appendChild(s),i.appendChild(a),1===s.offsetHeight&&i.classList.add("hairlines"),i.removeChild(a)}}(window,document);</script>
@wangdahoo
wangdahoo / whoisyourdaddy.js
Created June 18, 2019 09:25
字符串转数字
const COUNT = 1000 * 1000 * 10
function run (sum, fn) {
const startTime = Date.now()
for (let i = 0; i < COUNT; i++) {
sum = fn(sum)
}
console.log(`duration: ${Date.now() - startTime}`)
}
@wangdahoo
wangdahoo / tmux-cheatsheet.markdown
Created March 25, 2019 12:52 — forked from ryerh/tmux-cheatsheet.markdown
Tmux 快捷键 & 速查表

注意:本文内容适用于 Tmux 2.3 及以上的版本,但是绝大部分的特性低版本也都适用,鼠标支持、VI 模式、插件管理在低版本可能会与本文不兼容。

Tmux 快捷键 & 速查表

启动新会话:

tmux [new -s 会话名 -n 窗口名]

恢复会话:

@wangdahoo
wangdahoo / call.go
Last active October 12, 2018 12:21
reflect-call
// 反射
package main
import (
"errors"
"reflect"
"fmt"
)
func Call(m map[string]interface{}, name string, params ...interface{}) ([]reflect.Value, error) {
@wangdahoo
wangdahoo / input.html
Created August 17, 2017 09:13
手机号码输入框
<!DOCTYPE html>
<html lang="en">
<head>
<title></title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="http://unpkg.qkcdn.com/lodash@4.17.4/lodash.min.js"></script>
<script src="http://unpkg.qkcdn.com/vue@2.4.2/dist/vue.min.js"></script>
</head>
<body>
@wangdahoo
wangdahoo / Vue component module
Created April 10, 2017 05:57 — forked from znck/ Vue component module
Example for `rollup-plugin-vue`
Create a module for vue component.
@wangdahoo
wangdahoo / reset.css
Created March 25, 2017 12:17
Eric Meyer's reset-css
/* http://meyerweb.com/eric/tools/css/reset/
v2.0 | 20110126
License: none (public domain)
*/
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,