Skip to content

Instantly share code, notes, and snippets.

View oscarzhao's full-sized avatar

Zhao Shuaihu oscarzhao

  • Beijing
View GitHub Profile
@oscarzhao
oscarzhao / echo_server_epoll.go
Created February 12, 2023 02:36
Epoll EchoServer
package main
import (
"fmt"
"log"
"net"
"os"
"os/signal"
"syscall"
)
@oscarzhao
oscarzhao / fd_set_linux_amd64.go
Created January 26, 2023 10:49
Go echo server by Select
//go:build amd64 && linux
package fdsetutil
import "syscall"
/**
// filepath: ztypes_linux_amd64.go
type FdSet struct {
Bits [16]int64

There are three easy to make mistakes in go. I present them here in the way they are often found in the wild, not in the way that is easiest to understand.

All three of these mistakes have been made in Kubernetes code, getting past code review at least once each that I know of.

  1. Loop variables are scoped outside the loop.

What do these lines do? Make predictions and then scroll down.

func print(pi *int) { fmt.Println(*pi) }
@oscarzhao
oscarzhao / week-01-class-without-ptr.md
Last active July 15, 2016 10:34
C++面向对象高级编程学习笔记

第一周:设计和实现一个不含指针的class(Geekband)

设计class的注意事项

  1. 数据要封装(尽量private)
  2. 参数和返回值尽量用reference(返回local variable除外)
  3. 能用const一定要用const
  4. 构造函数尽量用initializer_list进行参数初始化

临时对象

临时对象是指在函数作用域块作用域内定义的变量。