Skip to content

Instantly share code, notes, and snippets.

View poberwong's full-sized avatar
🎯
Focusing

PoberWong poberwong

🎯
Focusing
View GitHub Profile
@poberwong
poberwong / binarySearch.js
Last active August 14, 2020 15:52
优化递归深度
function binarySearch(arr, left, right, target) {
let mid = Math.floor((left + right) / 2);
function getLeft() {
return mid - 1 < left ? left : mid - 1;
}
function getRight() {
return mid + 1 > right ? right : mid + 1;
}
if (left === right) return right; // 可以优化掉一次函数调用
/**
* if immediate is true, the value will be returned synchronously or else will return a Promise
* @returns {Function}
*/
export const debounce = (params: Object = {}) => (target: any, name: any, descriptor: any) => {
let timer = null
const { delay = 300, immediate = false } = params
// high order function
@poberwong
poberwong / communicate.js
Created October 24, 2018 14:42
IM 新升级内容
import { observable, action } from 'mobx'
import config from 'app/config'
import { message } from 'antd'
import NIM from 'app/utils/NIM_Web_NIM_v5.2.1.js'
import WebRTC from 'app/utils/NIM_Web_WebRTC_v5.2.1.js'
import globalStore, { PLAY_TYPE } from 'app/stores/global'
import { getToken } from 'app/utils/localTools'
import { computed } from 'mobx'
const FREE = 'free'
let wxRequest = function (params) {
setTimeout(() => {
params.success(params.message)
}, params.time)
}
const limitedRequest = function (max) {
const LIMIT = max || 5
const cacheQueue = []
let count = 0
/**
* Created by dowin on 2017/8/3.
*/
import React from 'react'
import PropTypes from 'prop-types'
import {
Clipboard,
StyleSheet,
Image,
package com.drr;
import android.content.pm.PackageManager;
import android.os.Build;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Layout;
import android.util.Log;
@poberwong
poberwong / spring.md
Last active May 1, 2017 14:10
春游计划

策划分析:

  1. 交通方式——驾车
  2. 省内北 8 环,单程控制在 2h 以内

活动意义:

5.1 劳动节是用来犒劳全世界光荣劳动人民的节日。下至农田劳作的农民叔叔,上至为国家、为社会作出杰出贡献的科学家,都值得拥有这意义非凡的三天假期。作为互联网中底层劳动人民的我们同样为这三天假期庆祝一番,在一起奋斗些许日子了,因此在这三天的休养生息结束后,立即为大家延长了一天时间来外出春游,感受春天带来的盎然生机,为接下来的工作和事业积蓄力量,迎来更大的挑战。

地点:

古北水镇—— 距离望京 129 公里,车程预算 2h 以内。

古北水镇位于北京市密云区古北口镇,背靠中国最美、最险的司马台长城,坐拥鸳鸯湖水库,是京郊罕见的山水城结合的旅游度假景区。夜景堪称一绝,目前已成为北京夜游新地标。景区内建有精美的民国风格的山地四合院建筑43万平方米,总占地面积9平方公里,是长城脚下独具北方风情的度假式小镇。

/*
* time complexity = O(n)
*/
function twoWayMerge (arr1, arr2) {
if (!arr1 || !arr2) {
return 'illegal params'
}
if (arr1.length === 0 || arr2.length === 0) {
return arr1.concat(arr2)
@poberwong
poberwong / applyMiddleware.js
Last active December 25, 2019 20:27
source code for applyMiddleware of redux
/* v3.5.2*/
export default function (...middlewares) {
return (createStore) => (reducers, initialState, enhancer) => {
const store = createStore(reducers, initialState, enhancer)
const dispatch = store.dispatch
const chain = []
const middleWareAPI = {
getState: store.getState,
dispatch: action => dispatch(action)
}
@poberwong
poberwong / highOrderComponent.js
Created January 17, 2017 03:01
a simple high order component
export default (Component) => (props) => {
return (
<YourWrapper ...>
<Component />
</YourWrapper>
)
}
// Usage:
// in your component, you can use it with