We are all in the gutter, but some of us are looking at the stars.

Recent

go test 工具 file with name endwith `_test.go` was build by `go test` instead of `go build` there are three kind of Function need to be remember: Function which Name starts with `Test` was used as UnitTest or FunctionalTest Function which Name starts with `Benchmark` was used as Benmark. Function which Name starts with ‘Example` was used as Example. Test Function test function must: import `testing` package has `t *testing.T` as only argument use tool-function in `testing.
Jul 18, 2021
3 min read
introduce 在编译是不知道类型的情况下,可在运行时查看值,调用方法,更新变量,以及对布局进行操作的机制. 反射让我们把类型当作头等值 动态类型 vs 动态值 反射定义了两个重要的类型 reflect.Type, reflect.Value reflect.Type 类型描述符 接口值的动态类型也是类型描述符 满足fmt.Stringer接口 t := reflect.TypeOf(3) fmt.Println(t.String()) fmt.Println(t) // 反射总是返回具体类型 var w io.Writer = os.Stdout fmt.Println(reflect.TypeOf(w)) // return os.File int int *os.File reflect.Value v := reflect.ValueOf(3) fmt.Println(v) // this will handle reflect.Value fmt.Println("%v\n", v) // implement the fmt.Stringer interface, but only return `Type` if not string fmt.Println(v.String()) // get `Value` Type t := v.Type() fmt.Println(t.String()) // the reverse operator x := v.Interface() // return `interface{}` i := x.
Jul 18, 2021
6 min read
tree root 树根 node 节点 leaf 叶子节点 parent 父节点 children 子节点 兄弟节点 二叉查找树 性质 parent have two child, left and right key(left) <= key(parent) <= key(right) TODOAVL树 带平衡条件的特殊二叉树. TODO 源码实现 性质 every node has a height property every node: abs(height(left(node)) - height(right(node)) <= 1 支持的操作 查找 同二叉树 插入 需要通过旋转来保持AVl性质. 分四种情况: 左左 右右 左右 右左 两两对称, 同方向使用单旋, 不同方式需要使用双旋转. 递归向上保持??? TODO伪码 TODO删除 TODOred-black tree concept black-height 黑高度, 从节点到叶子节点的黑节点数
Jul 18, 2021
1 min read
rest vs graphql good things from rest stateless API, which make web-scalable and easy-manage resource-oriented programming and structured accessto resources, which make many goods, such as cacheable, retriable. the bad things with rest `1+N` problem: fetch list api, fetch every detail api to get more message. overfetching(fetch too much data which was not requried) underfetching(not-enough data from api, which make it need multi request to get the data). too flexible, may things this like dynamic(rest) vs static(graphql).
Dec 5, 2020
2 min read
bokeh can provide interactive visualization for modern web browsers. elegant, concise, vesatile graphics, *afford high-performacne interactiivity onver lagerge or streaming datasets. bokeh provide two interface levels: bokeh.models: low-level interface provide most flexibility bokeh.plotting: higher-level interface centered around composing visual glyphs. this focus on bokeh.plotting. installation # recommend way # conda install deps, and exmaples in *examples/* subdirectory conda install bokeh # using pip, you need install ~numpy~ and so on. pip install bokeh get-starting [] TODO output bokeh plot to or-babel result you can download sample-date and example from bokeh
Nov 17, 2020
3 min read
package main import ( "fmt" "http" "reflect" ) // search ... func search(resp http.ResponseWriter, req *http.Request) { var data struct { Labels []string `http:"1"` MaxResults int `http:"max"` Exact bool `http:"x"` } data.MaxResults = 10 if err := Unpack(req, &data); err != nil { http.Error(resp, err.Error(), http.StatusBadRequest) return } fmt.Fprintf(resp, "Search: %+v\n", data) } // Unpack func Unpack(req *http.Request, ptr interface{}) error { if err := req.ParseForm(); err != nil { return err } fields := make(map[string]reflect.
Jul 18, 2021
1 min read
schema-driven development define your types and the appropriate queries and mutations for them. implemetns functions called resolvers to handle these types and their fields. as new requirements arrive, go back to step 1 update the schema. about relay a mechanism for refetching an object a description of how to page through connections structure around mutation to make them prediatable
Dec 5, 2020
1 min read
concurrent-programming: programs can run in independent with each other. parallel programming: program can run at same time. as a low-level language, rust need less abstraction and more control. use thread process vs thread programs: Race conditions: data-race. resource-race. DeakLock difficult concurrent bug. os-thread vs green-thread: 1:1 vs M:N /// thread examples /// when the main-thread exit, the fork-thread will exit too. /// just like python thread.deamon flag. use std::thread; use std::time::Duration; fn main() { thread::spawn(|| { for i in 1.
Nov 4, 2020
4 min read
unsafe-rust advance-trait trait-ref-type 与trait相关的关联类型 default type param 默认参数类型 fully qualified syntax 完全限定语法 supertraits 超父类 newtype模式 advance-type more about new-type pattern type alias 类型别名 never type dymatic-size type 动态大小类型 advance function and closure function point 函数指针 return closure 返回闭包 macro 宏 unsafe-rust the-addional-super power of unsafe 解引用裸指针 调用不安全的函数或方法 访问或修改可变静态变量 实现不安全的trait 访问union字段 the owner-check is still on unref-raw-point ignore owner-rule, allow mut and immute ref.
Nov 8, 2020
5 min read