Skip to content

Instantly share code, notes, and snippets.

View snowcrumble's full-sized avatar
🏠
Working from home

Lijingfeng snowcrumble

🏠
Working from home
View GitHub Profile
@snowcrumble
snowcrumble / 理解 Golang 的 GC.md
Last active September 26, 2020 08:12
理解 Golang 的 GC.md

理解 Golang 的 GC

GC

GC 的实现方式主要分为三大类

  • 引用计数
  • 标记清除
  • 复制
@snowcrumble
snowcrumble / TLS 1.3 进行时.md
Last active September 26, 2020 08:18
TLS 1.3 进行时.md

TLS 1.3 进行时

本文是对 TLS 1.3 相关内容的一些整理和看法,包括 TLS 1.3 解决了哪些问题,带来了哪些提升,一些细节的探究,和 QUIC 的比较以及对 TLS 1.3 的看好。

早期版本的 TLS 存在的问题

HTTPS 已经是互联网通信的主流协议,它是互联网安全通信的保障,但是也存在一些性能问题和不少安全漏洞,从 90 年代诞生到 2018 年 TLS 1.3 出现之前的二三十年里,TLS 的握手流程都没有结构性变化,建立一个 TLS 链接需要消耗两个 RTT(round-trip time),这导致 TLS 链接会比较慢,假设你 ping 服务器的延迟是 100ms,两个 RTT 就是 200ms,再加上 DNS 请求和 TCP 三次握手和最终的 HTTP 链接进行数据通信,你看到网站主页面开始响应的延迟起码是 400ms 以上,而人类的对 100ms 以上的延迟是有感的,根据 Amazon 的统计首页打开时间每增加 100 毫秒,网站销售量会减少 1%。伴随着 TLS 的发展,越来越多的针对性攻击也开始出现,包括 Heartbleed , BERserk , goto fail; ,这些是由于 TLS 实现的缺乏测试导致的,都属于代码 BUG 的范围,但是 POODLEROBOT 这种就是属于协议设计上的漏洞了。

TLS 1.3 改进和重构

@snowcrumble
snowcrumble / Go 基于 Interface 的泛型.md
Created September 26, 2020 08:00
Go 基于 Interface 的泛型

Go 基于 Interface 的泛型

Go 泛型的草案截止今日已经基本定型了,与其他语言最大的不同应该就是 Go 的泛型利用 Interface 做 Constraint,可以说是与现有的 Interface 充分结合,之前的草案本来要引入新的关键字 contracts 在这次改动后被现有的 interface 代替,这使得 Interface 的概念更像 Rust 的 trait(实际上 Go 的泛型概念也与 Rust 相似),不过 Go 中实现 Interface 不需要显示声明,所以我想先谈一下 Interface 这个 Go 语言中最出色的“发明”。

Interface

Interface 实现了 Go 风格的 Duck typing。它实现的方法查表方式与其他语言有些不同,有方法的语言大概有两个阵营

  1. C++ 和 Java 在编译时生成方法的静态方法表,比如 C++ 的 vtable
  2. Js 和 Python 动态查询,并花式缓存
@snowcrumble
snowcrumble / golang单元测试实践.md
Created September 26, 2020 07:59
golang单元测试实践.md

我的 golang 单元测试实践

本文不涉及 go 的单元测试的基本结构,以及为什么我们要写单元测试,和 TDD 的好处。简单是说就是 what why how 这里只提 how,而且是 how I did。

测试框架选择

无框架

或叫原生框架

@snowcrumble
snowcrumble / Optional,错误处理,部分更新.md
Last active September 26, 2020 07:52
Optional,错误处理,部分更新

Optional,错误处理,部分更新

Go2 提案

前几天无意间看到 Go2 有一个关于语言修改的提案,增加 sum types 或者叫 union types,与 Protobuffer 中的 oneof 语义很像,基本概念是定义一个新的类型,为其他类型之和,用|分割不同的类型,组合起来的类型 type 只能是各个类型的其中一个。比如

type maybeInt nil | int
@snowcrumble
snowcrumble / gist:8e970a95c452afc4e779cdba612cb041
Created June 20, 2019 03:45 — forked from perusio/gist:1326701
Mobile device detection in Nginx with just 7 lines of configuration
### Testing if the client is a mobile or a desktop.
### The selection is based on the usual UA strings for desktop browsers.
## Testing a user agent using a method that reverts the logic of the
## UA detection. Inspired by notnotmobile.appspot.com.
map $http_user_agent $is_desktop {
default 0;
~*linux.*android|windows\s+(?:ce|phone) 0; # exceptions to the rule
~*spider|crawl|slurp|bot 1; # bots
~*windows|linux|os\s+x\s*[\d\._]+|solaris|bsd 1; # OSes
@snowcrumble
snowcrumble / contributor_guide.sh
Last active February 1, 2019 07:39
Golang contributor guide template
mkdir -p $GOPATH/src/github.com/someone_or_organization/
cd $GOPATH/src/github.com/someone_or_organization/
git clone git@github.com:$YOUR_GITHUB_USERNAME/the_repo_name.git
cd the_repo_name
git remote add upstream git@github.com:someone_or_organization/the_repo_name.git
git remote set-url --push upstream no_push
@snowcrumble
snowcrumble / latency.txt
Created January 15, 2019 04:01 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@snowcrumble
snowcrumble / README-Template.md
Created January 15, 2019 04:01 — forked from PurpleBooth/README-Template.md
A template to make good README.md

Project Title

One Paragraph of project description goes here

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites