[root@zorrozou-pc ~/test]# cat /proc/cpuinfo
processor : 23
vendor_id : GenuineIntel
cpu family : 6
model : 63
model name : Intel(R) Xeon(R) CPU E5-2620 v3 @ 2.40GHz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 固定数组,类型体操 | |
// [Zig lang 初体验 -- 『大道至简』的 comptime - 纯纯的 Blog](https://blog.zhuangty.com/zig-lang-comptime/) | |
const std = @import("std"); | |
const ArrayList = std.ArrayList; | |
const DynamicBitSet = std.bit_set.DynamicBitSet; | |
fn FixedArray(comptime T: type) type { | |
return struct { | |
const Self = @This(); | |
data: ArrayList(T), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
errors=0 | |
for file in $(git diff --cached --name-only | grep "\.go"); do | |
diff="$(gofmt -d "${file}")" | |
if [[ -n "$diff" ]]; then | |
echo "# *** ERROR: *** File ${file} has not been gofmt'd." >> $1 | |
errors=1 | |
fi | |
done |
- 做一件事情,并把它做好
- Make it fast and easy to get started
- 努力实现直觉上的一致性
- 反映在你的URL,输入和输出响应中。开发人员应该能够猜到你的API的部分内容,即使不看文档。
- 与工业标准的一致性。它应该尽可能地遵守行业中公认的最佳实践。
- 与你的产品保持一致。你应该根据你在产品中对这些概念的称呼来选择字段名。避免使用缩写、首字母缩写和行话。要啰嗦。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 创建bridge | |
create_bridge() { | |
local nsname="$1" | |
local ifname="$2" | |
echo "Creating bridge ${nsname}/${ifname}" | |
ip netns add ${nsname} | |
ip netns exec ${nsname} ip link set lo up | |
ip netns exec ${nsname} ip link add ${ifname} type bridge |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// [Go语言高性能编程手册(万字长文)](https://mp.weixin.qq.com/s/iSxWFsnNLGgilzKIsSDBgg) | |
// Bad | |
for i := 0; i < b.N; i++ { | |
s := fmt.Sprint(rand.Int()) | |
} | |
BenchmarkFmtSprint-4 143 ns/op 2 allocs/op | |
// Good | |
for i := 0; i < b.N; i++ { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 在64机器上,返回16字节 | |
// 存在 pading | |
// http://www.catb.org/esr/structure-packing/ | |
struct foo3 { | |
char *p; /* 8 bytes */ | |
char c; /* 1 byte */ | |
}; | |
struct foo3 singleton; | |
struct foo3 quad[4]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 传统oop的方式 | |
// [jamesmcm/data-oriented-example: Example of Data Oriented Design in Rust](https://github.com/jamesmcm/data-oriented-example) | |
// https://jamesmcm.github.io/blog/2020/07/25/intro-dod/ | |
pub struct Player { | |
name: String, | |
health: f64, | |
location: (f64, f64), | |
velocity: (f64, f64), | |
acceleration: (f64, f64), | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// bpf_map的属性 | |
union bpf_attr { | |
struct { | |
__u32 map_type; /* one of the values from bpf_map_type */ | |
__u32 key_size; /* size of the keys, in bytes */ | |
__u32 value_size; /* size of the values, in bytes */ | |
__u32 max_entries; /* maximum number of entries in the map */ | |
__u32 map_flags; /* flags to modify how we create the map */ | |
}; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//go:build go1.12 | |
// +build go1.12 | |
// goversion.go | |
// Package goversion enforces the go version supported by the tsdb module. | |
package goversion | |
const _SoftwareRequiresGOVERSION1_12 = uint8(0) |