Skip to content

Instantly share code, notes, and snippets.

View XUJiahua's full-sized avatar

许嘉华 XUJiahua

View GitHub Profile
@XUJiahua
XUJiahua / main.go
Created May 26, 2021 09:51
use channel as callback
package main
import (
"fmt"
"time"
)
// oneshot_channel make sender/receiver
func oneshot_channel() (chan<- int, <-chan int) {
ch := make(chan int)
@XUJiahua
XUJiahua / main.go
Created October 22, 2020 07:59
structured logging using logrus/context
package main
import (
"context"
"encoding/json"
"github.com/google/uuid"
"github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus"
"github.com/sirupsen/logrus"
"log"
"math/rand"
package main
import (
"context"
"encoding/json"
"github.com/google/uuid"
"github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus"
"github.com/sirupsen/logrus"
"log"
"math/rand"
@XUJiahua
XUJiahua / buggy.js
Created October 22, 2020 02:11
find bugs
/*
输入一个数字数组,找出数组的中位数
找出其中的bug
*/
function findMedian(arr) {
arr.sort();
mid = arr.length / 2;
if (arr.length % 2 === 1) {
return arr[mid];
} else {
@XUJiahua
XUJiahua / main.go
Created April 30, 2019 03:28
find num of common friends between users
package main
import (
"fmt"
"github.com/davecgh/go-spew/spew"
)
type adjList []int
@XUJiahua
XUJiahua / gdm.py
Created February 2, 2019 02:24
梯度下降法求函数最低点
# 计算函数的最低点,也就是最优化问题
# f(x) = (x-1)^2 + 2,理论解为(1,2)
def f(x):
return (x-1)*(x-1) + 2
# 计算导数(梯度),数值计算的方式
@XUJiahua
XUJiahua / fabric-ca-server-config.yaml
Last active November 21, 2018 09:02
fabric-ca-server-config.yaml说明
# reference: https://hyperledger-fabric-ca.readthedocs.io/en/latest/users-guide.html#fabric-ca-server
#
# 本文件是由fabric-ca-server生成,由
# fabric-ca-server init -b admin:adminpw
# 或是
# fabric-ca-server start -b admin:adminpw
# 生成
#
# 如果不通过命令行指定 -u <parent-fabric-ca-server-URL>
# 默认生成的是self-signed CA
@XUJiahua
XUJiahua / cat_repo.go
Created October 18, 2018 07:30
proxy = struct embedding + interface
package embintf
import (
"github.com/sirupsen/logrus"
"time"
)
type Cat struct {
ID int64
}
@XUJiahua
XUJiahua / cat_repo.go
Created October 18, 2018 07:19
proxy = embedding + interface
package embintf
import (
"github.com/sirupsen/logrus"
"time"
)
type Cat struct {
ID int64
}
@XUJiahua
XUJiahua / bar.go
Created October 11, 2018 11:20
golang wire failure case
package foobarbaz
type Bar struct {
X int
Y int
}
// ProvideBar returns a Bar: a negative Foo.
func ProvideBar(foo Foo, y int) Bar {
return Bar{X: -foo.X, Y: y}