Skip to content

Instantly share code, notes, and snippets.

View BruceChen7's full-sized avatar
🎯
Focusing

insects BruceChen7

🎯
Focusing
View GitHub Profile
@BruceChen7
BruceChen7 / linux.md
Created July 15, 2022 13:39
#linux#smp#ebpf

参考资料

命令

cat /proc/cpuinfo

[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
@BruceChen7
BruceChen7 / hello.zig
Last active August 1, 2022 15:29
#ziglang#type#zig#async
// 固定数组,类型体操
// [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),
@BruceChen7
BruceChen7 / gofmt.sh
Created June 28, 2022 15:35
#git#shell#go#gofmt
#!/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
@BruceChen7
BruceChen7 / api.md
Last active June 20, 2022 06:27
#api#practice

资料来源

考虑的事情

  • 做一件事情,并把它做好
  • Make it fast and easy to get started
  • 努力实现直觉上的一致性
    • 反映在你的URL,输入和输出响应中。开发人员应该能够猜到你的API的部分内容,即使不看文档。
    • 与工业标准的一致性。它应该尽可能地遵守行业中公认的最佳实践。
  • 与你的产品保持一致。你应该根据你在产品中对这些概念的称呼来选择字段名。避免使用缩写、首字母缩写和行话。要啰嗦。
@BruceChen7
BruceChen7 / namespace.sh
Last active May 31, 2022 13:57
#networking#lab#k8s#namespace#ip#link
// 创建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
@BruceChen7
BruceChen7 / effective.go
Last active December 28, 2022 14:52
#golang#effective#practice#go
// [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++ {
@BruceChen7
BruceChen7 / test.c
Last active April 26, 2022 14:02
#c#memory
// 在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];
@BruceChen7
BruceChen7 / dop.rs
Last active July 9, 2022 16:09
#dop#rust#zig
// 传统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),
}
@BruceChen7
BruceChen7 / ebpf.c
Last active April 24, 2022 15:28
#ebpf#c#bcc#perf
// 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 */
};
}
@BruceChen7
BruceChen7 / goversion.go
Last active April 18, 2022 07:15
#goversion
//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)