Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2019.7.15 - 7.21 中你学到什么? #1

Open
KieSun opened this issue Jul 15, 2019 · 41 comments
Open

2019.7.15 - 7.21 中你学到什么? #1

KieSun opened this issue Jul 15, 2019 · 41 comments

Comments

@KieSun
Copy link
Owner

KieSun commented Jul 15, 2019

周报

新的记录地址

@KRISACHAN
Copy link

KRISACHAN commented Jul 15, 2019

CSS houdini

  • 鱼头嘤语:把的JS文件存为houdnini.js,html文件存为index.html,然后开个静态服务器,就可以看效果了
/* 新建一个js文件,就叫houdnini.js吧 */
'use strict'
registerPaint('overdraw', class {
    static get inputProperties() { return ['--border-width']; }
    paint(ctx, geom, properties) {
        const borderWidth = parseInt(properties.get('--border-width'));
        ctx.shadowColor = 'rgba(0,0,0,0.25)';
        ctx.shadowBlur = borderWidth;

        ctx.fillStyle = 'rgba(255, 255, 255, 1)';
        ctx.fillRect(borderWidth,
                     borderWidth,
                     geom.width - 2 * borderWidth,
                     geom.height - 2 * borderWidth);
    }
});
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta name="screen-orientation" content="portrait">
    <meta name="x5-orientation" content="portrait">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <meta http-equiv="Cache-Control" content="no-siteapp">
    <title>demo</title>
    <style>
      .overdraw {
        --border-width: 10;
        border-style: solid;
        border-width: calc(var(--border-width) * 1px);
        border-image-source: paint(overdraw);
        border-image-slice: 0 fill;
        border-image-outset: calc(var(--border-width) * 1px);
        width: 200px;
        height: 200px;
      }
    </style>
  </head>
  <body>
    <div class="overdraw"></div>
    <script>
      'use strict';
      if (window.CSS) {
        CSS.paintWorklet.addModule('houdnini.js');
      }
    </script>
  </body>
</html>

嗯,可以看效果

@KRISACHAN
Copy link

KRISACHAN commented Jul 16, 2019

2019/7/16份学习

今天学的是栈

代码如下:

'use strict'
const items = new WeakMap()  // 保存栈里的元素
class Stack {
    constructor () {
        items.set(this, [])
    }
    push (elements) { // 添加一个(或几个)新元素到栈顶
        let s = items.get(this) 
        s.push(elements)
    }
    pop () {
        let s = items.get(this)
        let r = s.pop()
        return r
    }
    peek () { // 将返回栈顶的元素
        let s = items.get(this)
        return s[s.length - 1]
    }
    isEmpty () { // 能简单地判断内部数组的长度是否为0
        let s = items.get(this)
        return s.length === 0
    }
    clear () { // 把数组中的元素全部移除
        items.set(this, [])
    }
    print () { // 打印数组
        let s = items.get(this)
        console.log(s)
    }
}

const stack = new Stack()
stack.push(1)
stack.push(2)
console.log(stack.isEmpty())
stack.print()
stack.clear()
stack.print()
console.log(stack.isEmpty())

    const baseConverter = (decNumber, base) => {
      const remStack = new Stack()
      let rem, binaryString = '', digits = '0123456789ABCDEF'
      while (decNumber > 0) {
        rem = Math.floor(decNumber % base)
        remStack.push(rem) 
        decNumber = Math.floor(decNumber / base) 
      }
      while (!remStack.isEmpty()) {
        binaryString += digits[remStack.pop()]
      }
      return binaryString
    }
    console.log(baseConverter(233, 2))

@KieSun
Copy link
Owner Author

KieSun commented Jul 16, 2019

以下都为微信环境下:

  • 安卓直接使用原生 video 会导致全屏播放,盖住所有元素,因此使用 x5 播放器。但是 x5 播放器还是存在问题,虽然不会盖住元素,但是会自己添加特效(盖一层导航栏蒙层)。后续使用 videojs 解决该问题,播放效果同 iOS 相同,但是右上角还是会出现一个全屏按钮(没办法去除)。
  • 在 iOS HTTPS 页面下,不可使用 ws 协议,必须使用 wss 协议。
  • iOS 下输入框弹起键盘前后,页面都可能出现问题,需要监听下键盘弹起收起的状态,然后自己滚一下。

@qdlaoyao
Copy link

qdlaoyao commented Jul 16, 2019

数组求和新法

今天在掘金上看到了,一种数组求和方法。妙!虽然不会真这么用,但从未这么想过。

let arr = [1, 2, 3, 4, 5]
eval(arr.join('+'))

@Flcwl
Copy link

Flcwl commented Jul 17, 2019

数组完全展开

function myFlat(arr) {
  while (arr.some(t => Array.isArray(t))) {
   	arr = ([]).concat.apply([], arr);
  }
  return arr;
}
var arrTest1 = [1, [2, 3, [4]], 5, 6, [7, 8], [[9, [10, 11], 12], 13], 14];  
console.log(myFlat(arrTest1)) // Expected Output: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]

@Mikerui
Copy link

Mikerui commented Jul 17, 2019

实现sleep函数

function sleep(interval) {
  return new Promise(resolve => {
    setTimeout(resolve, interval);
  })
}
async function test() {
  for (let index = 0; index < 10; index++) {
    console.log(index);
    await sleep(2000)
  }
}

@jiongzai0819
Copy link

数组求和新法

今天在掘金上看到了,一种数组求和方法。妙!虽然不会真这么用,但从未这么想过。

let arr = [1, 2, 3, 4, 5]
eval(arr.join('+'))

eval 太消耗性能,也不是很安全

@dale426
Copy link

dale426 commented Jul 17, 2019

又一种Vue组件数据通信方式

vue 2.6.0 新增方法 Vue.observable()
使用方法,点这里

@RichardPear
Copy link

Express 服务器用compression中间件开启gzip压缩, 响应体能减少2/3的体积

const express = require('express');
const compression = require('compression');
const app = express();
app.use(compression());

@majiang666
Copy link

majiang666 commented Jul 17, 2019

yygmind/blog#17

1:今天深入研究了一下作用域链和闭包的原理,获益匪浅,但是还有闭包出栈的问题,还是有困惑。
困惑点在于:闭包函数会出栈吗?
2:写了一个npm的loading【vue】组件包 https://www.npmjs.com/package/vue-simples-loading

@Glenfiddish
Copy link

Glenfiddish commented Jul 17, 2019

分享一个获取git 统计代码行数的代码

const { exec } = require('child_process');
const { argv } = require('yargs');

const readLines = stdout => {
  const stringArray = stdout
    .toString()
    .split(/(\n)/g)
    .filter(str => str !== '\n' && str);
  const dataArray = [];
  stringArray.map(str => {
    const data = str.split(/(\t)/g).filter(str => str !== '\t');
    const [newLine, deletedLine, filePath] = data;
    dataArray.push({ newLine, deletedLine, filePath });
  });
  return dataArray;
};


try {
  if (!argv.commit) throw new Error('commit args is needed, use should run like "node fileName --commit=xxx"')
  exec(`git diff ${argv.commit} --numstat`, (error, stdout, stderr) => {
    console.table(readLines(stdout));
  });
} catch (e) {
  console.log(e);
}

@Guanyuwu
Copy link

Guanyuwu commented Jul 17, 2019

实现一个only函数

看到这里 https://github.com/tj/node-only 自己也实现一个

/**
 * 
 * 
 * An array or space-delimited string may be given:

var obj = {
  name: 'tobi',
  last: 'holowaychuk',
  email: 'tobi@learnboost.com',
  _id: '12345'
};

var user = only(obj, 'name last email');
You can also use array form:

var user = only(obj, ['name', 'last', 'email']);
 */

var obj = {
    name: 'tobi',
    last: 'holowaychuk',
    email: '[email protected]',
    _id: '12345'
};

const only = (obj, para) => {
    if (!obj || !para) { new Error('please check your args!') }
    let newObj = {};
    let newArr = Array.isArray(para) ? para : typeof (para) === 'string' ? para.split(/ +/) : [];
    newArr.forEach((item) => {
        if (item && obj[item] && !newObj[item]) {
            newObj[item] = obj[item];
        }
    })
    return newObj;
}

console.log(only(obj, ['name', 'last', 'email']));
console.log(only(obj, 'name last    email'));

这里是大佬的实现https://github.com/tj/node-only/blob/master/index.js

npm包的使用 同时启动前端和后端 https://www.npmjs.com/package/concurrently

@dale426
Copy link

dale426 commented Jul 17, 2019

有深度的vue生命周期示意图

image
原文链接

@singzis
Copy link

singzis commented Jul 17, 2019

今天学了什么我是不知道,但是有个问题很疑惑😅😅😅

公众号推的一个防抖函数,其中加了个result,用以获取触发函数的返回值,但是,如果不用全局的话,我该怎么取到这个值呢?还有就是,非立即执行函数中,timer=null这一步是否有必要

function debounce(fn,wait,immediate){
  let timer;
  let result; // 在这里
  let debounced = function(){
    let context = this;
    let args = arguments;
    if(timer) clearTimeout(timer);
    if(immediate){
      const callNow = !timer;
      timer = setTimeout(() => {
        timer = null;
      }, wait);
      if(callNow) result = fn.apply(context,args); // 获取值在这里
    }else{
      timer = setTimeout(()=>{
        result = fn.apply(context,args); // 获取值在这里
        timer = null // 这个是否有必要呢
      },wait);
    }
  }
  debounced.cancel = function(){
    clearTimeout(timer);
    timer = null;
  }
  return debounced
}

@majiang666
Copy link

今天学了什么我是不知道,但是有个问题很疑惑

公众号推的一个防抖函数,其中加了个result,用以获取触发函数的返回值,但是,如果不用全局的话,我该怎么取到这个值呢?还有就是,非立即执行函数中,timer=null这一步是否有必要

function debounce(fn,wait,immediate){
  let timer;
  let result; // 在这里
  let debounced = function(){
    let context = this;
    let args = arguments;
    if(timer) clearTimeout(timer);
    if(immediate){
      const callNow = !timer;
      timer = setTimeout(() => {
        timer = null;
      }, wait);
      if(callNow) result = fn.apply(context,args); // 获取值在这里
    }else{
      timer = setTimeout(()=>{
        result = fn.apply(context,args); // 获取值在这里
        timer = null // 这个是否有必要呢
      },wait);
    }
  }
  debounced.cancel = function(){
    clearTimeout(timer);
    timer = null;
  }
  return debounced
}

有必要,为了释放内存,防止内存泄露,了解一下闭包的副作用。

@KieSun
Copy link
Owner Author

KieSun commented Jul 17, 2019

今天学了什么我是不知道,但是有个问题很疑惑😅😅😅

公众号推的一个防抖函数,其中加了个result,用以获取触发函数的返回值,但是,如果不用全局的话,我该怎么取到这个值呢?还有就是,非立即执行函数中,timer=null这一步是否有必要

function debounce(fn,wait,immediate){
  let timer;
  let result; // 在这里
  let debounced = function(){
    let context = this;
    let args = arguments;
    if(timer) clearTimeout(timer);
    if(immediate){
      const callNow = !timer;
      timer = setTimeout(() => {
        timer = null;
      }, wait);
      if(callNow) result = fn.apply(context,args); // 获取值在这里
    }else{
      timer = setTimeout(()=>{
        result = fn.apply(context,args); // 获取值在这里
        timer = null // 这个是否有必要呢
      },wait);
    }
  }
  debounced.cancel = function(){
    clearTimeout(timer);
    timer = null;
  }
  return debounced
}

result 并不是一个全局变量啊

@ghost
Copy link

ghost commented Jul 17, 2019

@naihe138
Copy link

中间件实现的两种方式~~~~

// 第一种、
let arr = [] // 中间件队列
let app = function (str) {
  let index = 0
  function next () {
    const fn = arr[index++]
    if (fn) {
      fn(str, next) // 把next交到外部函数来调用
    }
  }
  next() 
}
app.use = function (fn) {
  arr.push(fn)
}
// 使用
app.use(function (str, next) {
  console.log(1, str)
  next()
})
app.use(function (str, next) {
  console.log(2, str)
  next()
})
app.use(function (str, next) {
  console.log(3, str)
  next()
})

app('我是参数') // 打印结果: 1 我是参数   2 我是参数   3 我是参数

// -----------------
// 第二种、
let arr2 = [] // 中间件队列
let app2 = function (str) {
  let promise = Promise.resolve(str)
  while (arr2.length) {
    promise = promise.then(arr2.shift()) // then方法返回的是一个新的Promise实例,(注意,不是原来那个Promise实例)
  }
  return promise
}
app2.use = function (fn) {
  arr2.push(fn)
}

// 使用
app2.use(function(str){
  console.log(1, str)
  return str
})
app2.use(function(str){
  console.log(2, str)
  return str
})
app2.use(function(str){
  console.log(3, str)
  return str
})

app2('我是参数2') // 打印结果: 1 我是参数2   2 我是参数2   3 我是参数2

@Guanyuwu
Copy link

integrate the twitter api

  1. 注册用户以后 登录开发者控制台生成key& secret,再按这个步骤来做https://developer.twitter.com/en/docs/basics/rate-limiting
    2.前端实现还是后端实现 要看api调用次数的限制https://developer.twitter.com/en/docs/basics/rate-limiting

@guxuerui
Copy link

今天复习了下几种继承方式

    //组合继承
    function Parent(value){
      this.val = value
    }  
    Parent.prototype.getValue = function(){
      console.log(this.val)
    }
    function Child(value){
      Parent.call(this,value)
    }
    Child.prototype = new Parent()

    const child = new Child(1)
    console.log(child.getValue()) // 1
    child instanceof Parent // true
    /*
    以上继承的方式核心是在子类的构造函数中通过parent.call(this)来继承父类的属性,然后改变子类的原 
    型为new Parent()来继承父类的函数。
    这种继承方式优点在于构造函数可以传参,不会与父类引用属性共享,可以复用父类的函数,但是也存 
    在一个缺点就是在继承父类函数的时候调用了父类构造函数,导致子类的原型上多了不需要的父类属 
    性,存在内存上的浪费。
    */
    //寄生组合继承
    //这种继承方式对组合继承做了优化,组合继承缺点在于继承父类函数时调用了构造函数,只需要优化 
    掉这点。
    function Parent(value){
      this.val = value
    }
    Parent.prototype.getValue = function () {
      console.log(this.val)
    }
    function Child (value) {
      Parent.call(this, value)
    }
    Child.prototype = Object.create(Parent.prototype,{
      constructor: {
        value: Child,
        enumerable: false,
        writable: true,
        configurable: true
      }
    })
    const child = new Child(1)
    child.getValue() // 1
    child instanceof Parent // true
    /*
      这种方式实现的核心就是将父类的原型赋值给了子类,并且将构造函数设置为子类,这样既解决了无 
      用的父类属性问题,还能正确的找到子类的构造函数。
    */
    //class继承
    //以上两种继承方式都是通过原型去解决的,在 ES6 中,我们可以使用 class 去实现继承,并且实现起 
    来很简单。
    class Parent {
      constructor(value) {
        this.val = value
      }
      getvalue()  {
        console.log(this.val)
      }
    }
    class Child extends Parent {
      constructor (value) {
        super(value)
      }
    }

    const child = new Child(1)
    child.getvalue() // 1
    child instanceof Parent // true

    /*
      class实现继承的核心就是在于使用extends表明继承自哪个父类,并且在子类的构造函数中必须调用 
      super,因为这段代码等同于 parent.call(this,value)。
      当然,这也说明在JS中并不存在类,class的本质就是函数。
    */

@xiezipei
Copy link

今天学习前端框架 F7,顺便翻译了两篇文档:
Framework7 v4 Core 文档翻译(一) - 掘金
Framework7 v4 Core 文档翻译(二) - 掘金

@woshi88ji
Copy link

今天使用 vue-photo-preview 插件来进行图片的放大预览, 在异步获取图片数据时, 发现会出现无法预览图片的问题. 查阅资料后, 在 异步请求后 使用 this.$previewRefresh() . 但还是不起效. 原因不明. 现在的话, 是设置一个定时器. 在异步请求后启动定时器. 在其中调用$previewRefresh() , 这样才能进行图片的预览

@KRISACHAN
Copy link

2019/7/17份学习 - 队列

队列

const Queue = (() => { 
    const items = new WeakMap()
    class __Queue {     
        constructor () {       
            items.set(this, [])  
        }
        enqueue (element) {       
            let q = items.get(this)
            q.push(element)
        }
        dequeue () {       
            let q = items.get(this)
            let r = q.shift()
            return r
        }
        front () {
            let s = items.get(this)
            return s[0]
        }
        isEmpty () { // 能简单地判断内部数组的长度是否为0
            let s = items.get(this)
            return s.length == 0
        }
        size () { // 数组长度
            let s = items.get(this)
            return s.length
        }
        print () { // 打印数组
            let s = items.get(this)
            console.log(s.toString())
        }
    }   
    return __Queue
})()

优先队列

'use strict'
const PriorityQueue = (() => {
    const items = new WeakMap()
    function QueueElement (element, priority) {
        this.element = element
        this.priority = priority
    }
    class __PriorityQueue {     
        constructor () {       
            items.set(this, [])  
        }
        enqueue (element, priority) {       
            let queueElement = new QueueElement(element, priority)
            let added = false
            let s = items.get(this)
            for (let i = 0; i < s.length; ++i) {       
                if (queueElement.priority < s[i].priority) {
                    s.splice(i, 0, queueElement)
                    added = true
                    break
                }     
            }     
            if (!added) {       
                s.push(queueElement)
            }
        }
        dequeue () {       
            let q = items.get(this)
            let r = q.shift()
            return r
        }
        front () {
            let s = items.get(this)
            return s[0]
        }
        isEmpty () { // 能简单地判断内部数组的长度是否为0
            let s = items.get(this)
            return s.length == 0
        }
        size () { // 数组长度
            let s = items.get(this)
            return s.length
        }
        print () { // 打印数组
            let s = items.get(this)
            for (let i = 0; i < s.length; ++i) {       
                console.log(`${s[i].element} - ${s[i].priority}`)   
            }   
        }
    }   
    return __PriorityQueue
})()

@Chrisyjs
Copy link

一、vue 请求数据初始化应该放在哪个生命周期内?为什么?
答:放在 created 或 mounted 中。created 时可以操作 data 和 methods 了。但是如果需要操作 dom 就要放在 mounted 中。

二、elementUI 事件回调函数怎么添加自定义参数?

// $event 是默认参数
<el-switch @change="handleSwitch($event, scope.row)" v-model="scope.row.open"></el-switch>
// 箭头函数传递:a 是默认参数
<el-switch @change="(a) => handleSwitch(a, row)" v-model="scope.row.value"></el-switch>

@MrStrangeBao
Copy link

MrStrangeBao commented Jul 18, 2019

需求正则过滤违规词, 根据违规词库中匹配到的词进行过滤掉:
1,每个违规词的每个字中间的特殊的字符也算,违规词长度2-n个不等.

var ma = "大傻逼".split('');
var regstr = ma.join('([^\u4e00-\u9fa5]*?)');
var str = "这是一篇文章,需要过滤掉大傻逼这三个词,大傻逼中间出汉字以外的字符 大_/_傻a1v逼和 大傻a1v逼";
var reg = new RegExp(regstr , 'g');
str.replace(reg,"<替换的词>");

如果有更加完美的正则,欢迎指点下!

@wanCheng7
Copy link

在react中阻止事件冒泡的正确姿势:

// 阻止冒泡
stopBubble(event) {
    event.nativeEvent.stopImmediatePropagation() //阻止冒泡
}

可以利用这个来做点击空白区域关闭指定元素的实现,完整的整理如下:
在React中实现点击空白区域关闭指定元素的实现--掘金

@yuuk
Copy link

yuuk commented Jul 18, 2019

react中让setState支持 async 调用

// 定义
 setStateAsync(state) {
    return new Promise((resolve) => {
         this.setState(state, resolve);
    });
}
// 使用
async fn() {
    await setStateAsync({a: 1})
}

@KRISACHAN
Copy link

2019/7/18 份学习

利用 dispatchEvent 对原生事件的劫持

      'use strict'
      const event = new Event('click')
      const body = document.querySelector('body')
      body.addEventListener('click', ev => {
        console.log('biu')
      }, false)
      body.addEventListener('touchmove', ev => {
        body.dispatchEvent(event)
      }, false)

@Guanyuwu
Copy link

2019/7/18

工作中培养起来的几点认知(和大家分享):

  1. 优先做最重要的事情,(可以自己写在笔记本上,每天的任务,也可以利用todolist类似的软件)
  2. 懂得“闭环思维”,(对领导定期汇报项目进展,对同事、下属及时同步项目进度)
  3. 拥有解决问题并快速解决问题的能力(解决各种问题,锻炼解决问题的思维,一条路不通要想别的方法)
  4. 做一个靠谱、聪明、皮实、值得信赖的人。提高自己的不可替代性。
  5. 凡事有交代,件件有着落,事事有回音。
  6. 感激bug,是bug让自己成长,要成长必须多解决bug.多承担任务。
  7. 积极乐观,做一个正能量的人。(远离负能量的人和事)

@xiezipei
Copy link

最近在学 iOS App 开发,昨天用了 Cordova 成功创建了第一个 HelloWorld iOS App,真是有点小鸡冻,原来没有想象中复杂,整理记录如下:使用 Cordova 创建第一个 iOS App - 掘金

@unclay
Copy link

unclay commented Jul 19, 2019

问题

一段脚本,数组数据量超额后,内存突然变小了?

回答

数组有两种存储模式,1. 线性存储 2. 哈希表存储;
数组存储模式从 “线性存储” 转为 “哈希表存储”

1. 线性存储(空间换时间)
Process:rss 19.63 MB  heapTotal 6.23 MB  heapUsed 3.88 MB  consume 191.41 KB
total time:  0.734ms
2. 哈希表存储(时间换空间)

当线性存储超额之后,会自动转为哈希表存储

Process:rss 19.89 MB  heapTotal 9.23 MB  heapUsed 3.72 MB  consume 27.43 KB
total time:  0.880ms

参考学习:https://blog.csdn.net/xiebaochun/article/details/85711635

@monkey-yu
Copy link

monkey-yu commented Jul 19, 2019

interface ClockConstructor {
    new (hour: number, minute: number): ClockInterface;
}
interface ClockInterface {
    tick();
}

function createClock(ctor: ClockConstructor, hour: number, minute: number): ClockInterface {
    return new ctor(hour, minute);
}

class DigitalClock implements ClockInterface {
    constructor(h: number, m: number) { }
    tick() {
        console.log("beep beep");
    }
}
class AnalogClock implements ClockInterface {
    constructor(h: number, m: number) { }
    tick() {
        console.log("tick tock");
    }
}

let digital = createClock(DigitalClock, 12, 17);
let analog = createClock(AnalogClock, 7, 32);

关于ts中类和接口,这一块代码完全无法理解。谁可以大致解释一下?

@ghost
Copy link

ghost commented Jul 19, 2019

2019/7/19

利用 github issues api 和 react 搭建博客 http://ruizhengyun.cn

@singzis
Copy link

singzis commented Jul 19, 2019

今天学了什么我是不知道,但是有个问题很疑惑😅😅😅
公众号推的一个防抖函数,其中加了个result,用以获取触发函数的返回值,但是,如果不用全局的话,我该怎么取到这个值呢?还有就是,非立即执行函数中,timer=null这一步是否有必要

function debounce(fn,wait,immediate){
  let timer;
  let result; // 在这里
  let debounced = function(){
    let context = this;
    let args = arguments;
    if(timer) clearTimeout(timer);
    if(immediate){
      const callNow = !timer;
      timer = setTimeout(() => {
        timer = null;
      }, wait);
      if(callNow) result = fn.apply(context,args); // 获取值在这里
    }else{
      timer = setTimeout(()=>{
        result = fn.apply(context,args); // 获取值在这里
        timer = null // 这个是否有必要呢
      },wait);
    }
  }
  debounced.cancel = function(){
    clearTimeout(timer);
    timer = null;
  }
  return debounced
}

result 并不是一个全局变量啊

就是说在不使用全局的情况下,该怎么用这个result 😂😂

@KRISACHAN
Copy link

KRISACHAN commented Jul 19, 2019

2019/7/19份学习

汉诺塔:有三根杆子A,B,C。A杆上有 N 个 (N>1) 穿孔圆盘,盘的尺寸由下到上依次变小。要求按下列规则将所有圆盘移至 C 杆。

  • 每次只能移动一个圆盘
  • 大盘不能叠在小盘上面
let index = 0
const hanoi = (num, towerA, towerB, towerC) => {
    index++;
    if (num > 0) {
	hanoi(num - 1, towerA, towerC, towerB)
        console.log(num, towerA, towerB, towerC)
        hanoi(num - 1, towerB, towerA, towerC)
   }
}

@ghost
Copy link

ghost commented Jul 20, 2019

20190720

利用 github 提供的接口,调用 github issues ,结合 react + antd + umi 搭建个人博客 Pr's blog

@ghost
Copy link

ghost commented Jul 22, 2019

  1. 学习lodash中关于深拷贝的源码,写了一篇深拷贝的博客,掘金专栏

  2. 看了冴羽的博客的第一篇
    image

  3. 看了汤姆大叔的博客,了解了执行上下文栈,执行上下文,可执行代码的概念

  4. 了解了Node多进程模型,了解了node主从模型的概念

image

以及如何自己开启一个守护进程

image

@KieSun
Copy link
Owner Author

KieSun commented Jul 22, 2019

  1. 学习lodash中关于深拷贝的源码,写了一篇深拷贝的博客,掘金专栏
  2. 看了冴羽的博客的第一篇
    image
  3. 看了汤姆大叔的博客,了解了执行上下文栈,执行上下文,可执行代码的概念
  4. 了解了Node多进程模型,了解了node主从模型的概念

image

以及如何自己开启一个守护进程

image

感谢你的分享,本周记录地址是 这里,接下来可以去新的链接中记录内容。

@ghost
Copy link

ghost commented Jul 22, 2019

@KieSun 好的

@xuhongbo
Copy link

需求正则过滤违规词, 根据违规词库中匹配到的词进行过滤掉:
1,每个违规词的每个字中间的特殊的字符也算,违规词长度2-n个不等.

var ma = "大傻逼".split('');
var regstr = ma.join('([^\u4e00-\u9fa5]*?)');
var str = "这是一篇文章,需要过滤掉大傻逼这三个词,大傻逼中间出汉字以外的字符 大_/_傻a1v逼和 大傻a1v逼";
var reg = new RegExp(regstr , 'g');
str.replace(reg,"<替换的词>");

如果有更加完美的正则,欢迎指点下!

学到了,优秀优秀

需求正则过滤违规词, 根据违规词库中匹配到的词进行过滤掉:
1,每个违规词的每个字中间的特殊的字符也算,违规词长度2-n个不等.

var ma = "大傻逼".split('');
var regstr = ma.join('([^\u4e00-\u9fa5]*?)');
var str = "这是一篇文章,需要过滤掉大傻逼这三个词,大傻逼中间出汉字以外的字符 大_/_傻a1v逼和 大傻a1v逼";
var reg = new RegExp(regstr , 'g');
str.replace(reg,"<替换的词>");

如果有更加完美的正则,欢迎指点下!

优秀优秀,学习了

@loliconer
Copy link

Express 服务器用compression中间件开启gzip压缩, 响应体能减少2/3的体积

const express = require('express');
const compression = require('compression');
const app = express();
app.use(compression());

最好的方式就是直接预先提供gzip文件,这样不需要每次请求的时候都压缩一次,毕竟gzip压缩还是要消耗cpu资源的

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests