美文网首页
ARTS 第15周

ARTS 第15周

作者: 陈卧虫 | 来源:发表于2019-07-15 00:34 被阅读0次

    ARTS 第15周分享

    [TOC]

    Algorithm

    232. 用栈实现队列

    难度简单

    [思路]

    通过两个栈来逆向取出第一个元素

    [参考代码]

    package main
    
    import (
        "fmt"
        "github.com/pkg/errors"
    )
    
    type MyStack struct {
        myStack []int
        front   int
    }
    
    func NewMyStack() *MyStack {
        return &MyStack{myStack: make([]int, 0), front: -1}
    }
    
    func (s *MyStack) isEmpty() bool {
        return s.front == -1
    }
    
    func (s *MyStack) push(num int) {
        s.myStack = append(s.myStack, num)
        s.front++
    }
    
    func (s *MyStack) pop() (num int, err error) {
        if s.isEmpty() {
            return 0, errors.New("empty stack")
        }
        num = s.myStack[s.front]
        s.myStack = s.myStack[:s.front]
        s.front--
        return
    }
    
    type MyQueue struct {
        myStackIn  MyStack
        myStackOut MyStack
    }
    
    /** Initialize your data structure here. */
    func Constructor() MyQueue {
        return MyQueue{myStackIn: *NewMyStack(), myStackOut: *NewMyStack()}
    }
    
    /** Push element x to the back of queue. */
    func (this *MyQueue) Push(x int) {
        this.myStackIn.push(x)
    }
    
    /** Removes the element from in front of queue and returns that element. */
    func (this *MyQueue) Pop() int {
        if this.myStackIn.isEmpty() {
            return -1
        }
        for !this.myStackIn.isEmpty() {
            tmp, _ := this.myStackIn.pop()
            this.myStackOut.push(tmp)
        }
        res, _ := this.myStackOut.pop()
        for !this.myStackOut.isEmpty() {
            tmp, _ := this.myStackOut.pop()
            this.myStackIn.push(tmp)
        }
        return res
    }
    
    /** Get the front element. */
    func (this *MyQueue) Peek() int {
        if this.myStackIn.isEmpty() {
            return -1
        }
        for !this.myStackIn.isEmpty() {
            tmp, _ := this.myStackIn.pop()
            this.myStackOut.push(tmp)
        }
        res, _ := this.myStackOut.pop()
        this.myStackIn.push(res)
        for !this.myStackOut.isEmpty() {
            tmp, _ := this.myStackOut.pop()
            this.myStackIn.push(tmp)
        }
        return res
    }
    
    /** Returns whether the queue is empty. */
    func (this *MyQueue) Empty() bool {
        return this.myStackIn.isEmpty()
    }
    

    Review

    Channels in Go:https://go101.org/article/channel.html

    <本文详细的讲述的 go中Channel的原理与内部结构和一些使用细节>

    • In the same period of one computation is writing data to a memory segment, another computation is reading data from the same memory segment. Then the integrity of the data read by the other computation might be not preserved. In the same period of one computation is writing data to a memory segment, another computation is also writing data to the same memory segment. Then the integrity of the data stored at the memory segment might be not preserved.
      These circumstances are called data races.

    • One of the duties in concurrent programming is to control resource sharing among concurrent computations, so that data races will not happen.

    • Most operations in Go are not synchronized. In other words, they are not concurrency-safe.

    • In Go, generally, each computation is a goroutine.

    Tips

    Git分支管理实践:https://mp.weixin.qq.com/s/k53LQi5UdQBcmT3YwoYKSQ

    某位大佬的一篇介绍关于分支管理经验的总结,满满的都是干货!

    个人笔记,只有部分(是本人觉得需要掌握的)

    • 我们的关注点是commit, 用唯一的sha1标识, 他有两种含义快照和补丁。

    • 一些操作:

      • 当需要显示某次提交的具体内容,可以使用git show
      • 当需要对比差异时, 可以使用git diff
      • 当需要制作反向补丁时, 可以使用git revert
      • 当需要复制补丁时, 可以使用git cherry-pick
    • 我们至少要设定一个保护分支(以 master 为例), 作为功能分支。 该分支应该有以下特性:

    • 只能前进, 也就是不允许 force push;

    • 不允许直接 commit, 只能通过 merge 动作使分支前进;
    • 收紧 merge 权限, 只允许部分高级工程师执行 merge;
    • 只允许 merge 满足 fast-forward 条件的 commit;
    • 每次 merge 前, 必须进行 code review 和持续集成(CI);
    • Commit 提交者, code review 者, merge 者都要对代码变更负责.
    • 在我们自己的分支(草稿纸)上, 我们可以相对随意地修改, 但是当提交 PR 时, 必须整理出一份干净整洁的提交记录,可以通过git rebase -i 对commit历史进行修改

    • 对于分支的规范:

      • master 主功能分支;
      • feature-xxx-[developer name] 特性开发分支;
      • fix-xxx-[developer name] 非紧急bug修复分支;
      • hotfix-xxx-[developer name] 线上紧急bug修复分支;
      • dev-[date] 开发环境发布分支(或tag);
      • test-[date] 测试环境发布分支(或tag);
      • uat-[date] 准生产环境发布分支(或tag);
      • release-[date] 线上发布分支(或tag)。

    [其他]

    因为最近负责公司阿里云服务器的管理,需要远程安装一个应用,可以不同的linux发行版有不同的安装命令,但尴尬的是不知道是哪个发行版,所以上网查了如何查看系统版本:

    • uname -a # 查看内核/操作系统/CPU信息
    • lsb_release -a # 即可列出所有版本信息

    share

    什么是Socket

    • socket接口是操作系统提供的,底层是调用操作系统的接口
    • socket保证了不同计算机之间的通信,也就是网络通信。对于网站,通信模型是客户端服务器之间的通信。两个端都建立一个socket对象,然后通过socket对象对数据进行传输。
    • TCP/IP只是一个协议栈,就像操作系统的运行机制一样,必须要具体实现,同时还要提供对外的操作接口,这就是Socket编程接口
    • Socket是应用层与TCP/IP协议族通信的中间软件抽象层,它是一组接口。
    • 在设计模式中,Socket其实就是一个门面模式,它把复杂的TCP/IP协议族隐藏在Socket接口后面
    • socket的出现只是可以更方便的使用TCP/IP协议栈而已,其对TCP/IP进行了抽象,形成了几个最基本的函数接口,所以:socket只是对TCP/IP协议栈操作的抽象,套接字(socket)是通信的基石,是支持TCP/IP协议的网络通信的基本操作单元。
    • 它是网络通信过程中端点的抽象表示,包含进行网络通信必须的五种信息:
      • 连接使用的协议,
      • 本地主机的IP地址,本地进程的协议端口,
      • 远地主机的IP地址,远地进程的协议端口。

    进程管理工具:supervisord

    • 进程管理工具,可以很方便的对用户定义的进程进行启动,关闭,重启,并且对意外关闭的进程进行重启 ,只需要简单的配置一下即可,且有web端,状态、日志查看清晰明了。
    • 组成部分:
      • supervisord[服务端,所以要通过这个来启动它]
      • supervisorctl[客户端,可以来执行stop等命令]
    • 更新新的配置到supervisord : supervisorctl update
    • ​ 重新启动配置中的所有程序:supervisorctl reload
    • 启动某个进程(program_name=你配置中写的程序名称):supervisorctl start program_name
    • 官方文档地址:http://supervisord.org/
    • 运行 echo_supervisord_conf 即可看到默认配置情况.

    适配器模式:

    Adapter Pattern,通常被翻译成适配器模式,有时候也叫做包装模式(wrapper pattern)

    • 主要作用是将一个类的接口转换成客户希望的另外一个接口。适配器模式使得原本由于接口不兼容而不能一起工作的那些类可以一起工作。

    • GOF中将适配器模式分为类适配器模式和对象适配器模式。

      • 对象适配器模式

      在这种适配器模式中,适配器容纳一个它包裹的类的实例。在这种情况下,适配器调用被包裹对象的物理实体。

      • 类适配器模式

      这种适配器模式下,适配器继承自已实现的类(一般多重继承)。

      • 二者区别仅在于是通过继承还是组合来实现的
    • 适配器模式(对象适配器模式),是一种组合优于集成的思想的实现。通过使用适配器模式,我们可以最大程度的复用已有的了类和代码。

    • 将目标类和适配者类解耦,通过引入一个适配器类来重用现有的适配者类,而无须修改原有代码。

    本周阅读

    第二周:1, 2, 3, 4, 5, 
    如何打造一份优雅的简历?https://mp.weixin.qq.com/s/GJbGPQxpCPrfUFNE8ZZPnA
    同步/异步/阻塞/非阻塞/BIO/NIO/AIO https://mp.weixin.qq.com/s/e-HPyBtQ1zlcKXnFu8ADog
    什么是适配器模式? https://mp.weixin.qq.com/s/25oyWPGZAasJUePNX9sEgA
    
    我的程序员蜕变之路: https://mp.weixin.qq.com/s/VgPR828g_vJJs1REUMQUQg
    代码重构!你敢吗?https://mp.weixin.qq.com/s/2HK7t8GJUfF99HUDUYqzcA
    Channels in Go https://go101.org/article/channel.html
    
    golang实现set集合,变相实现切片去重  https://studygolang.com/articles/3291
    为什么“剩男”大多因为穷,“剩女”却什么类型都有?https://mp.weixin.qq.com/s/Ol1Zb6GIiBrnpjNTJSG78Q
    解决 Git 在 windows 下中文乱码的问题:https://gist.github.com/nightire/5069597
    
    supervisor 管理进程简明教程: https://www.jianshu.com/p/bf2b3f4dec73
    Git分支管理实践: https://mp.weixin.qq.com/s/k53LQi5UdQBcmT3YwoYKSQ   // good
    
    常用查看Linux系统信息命令: https://blog.51cto.com/liguxk/152912
    FFrequently Asked Questions:  https://www.johnvansickle.com/ffmpeg/faq/
    开发 7 年,我学到了什么?https://mp.weixin.qq.com/s/kt4ZPSWTc8gtWoI_Qc_bHA
    Channels in Go:https://go101.org/article/channel.html
    
    

    相关文章

      网友评论

          本文标题:ARTS 第15周

          本文链接:https://www.haomeiwen.com/subject/ltwwkctx.html