Skip to content

Instantly share code, notes, and snippets.

package main
import "fmt"
func main() {
ben := &Ben{name: "Ben"}
jerry := &Jerry{name: "Jerry"}
var maker IceCreamMaker = ben
var loop0, loop1 func()
@kougazhang
kougazhang / http.go
Created December 22, 2021 07:38
#golang #http
// request https
// disable security checks globally for all requests of the default client
func main() {
http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
_, err := http.Get("https://golang.org/")
if err != nil {
fmt.Println(err)
}
}
@kougazhang
kougazhang / sync_atomic_test.go
Created December 31, 2021 01:02
#geektime #golang
package main
import (
"sync"
"sync/atomic"
"testing"
)
type Config struct {
a []int
@kougazhang
kougazhang / fork.c
Created December 31, 2021 09:21
#copy-on-write
#include <stdio.h>
#include <unistd.h>
int main(void) {
pid_t fpid; // fpid 表示 fork 函数返回值
int count=0;
// 调用 fork, 创建出子进程
fpid = fork();
@kougazhang
kougazhang / cow.go
Created January 4, 2022 09:34
#golang #geektime
package main
import (
"sync"
"sync/atomic"
)
func main() {
type Map map[string]string
var m atomic.Value
@kougazhang
kougazhang / cow-usage.go
Created January 4, 2022 09:46
#golang #geektime
package main
func main() {
// holds current server configuration 动态更新当前服务的配置
var config atomic.Value
go func() {
// Reload config every 10 seconds 每 10 秒重载配置
// and update config value with the new version 用新版本的值更新配置项
for {
@kougazhang
kougazhang / mutex.go
Created January 5, 2022 07:33
#golang #geektime
package main
import "time"
import "sync"
import "flag"
import "os"
import "log"
import "runtime"
import "runtime/pprof"
import "runtime/trace"
@kougazhang
kougazhang / embadding.go
Created January 10, 2022 10:05
#golang
type InterfaceA interface {
A()
B()
C()
D()
}
type ImplA struct {
InterfaceA
}
@kougazhang
kougazhang / with-deadline.go
Created January 14, 2022 11:07
#golang #context
package main
import (
"context"
"fmt"
"time"
)
const shortDuration = time.Millisecond
@kougazhang
kougazhang / static.cpp
Last active January 17, 2022 07:11
#c++
#include <iostream>
// 函数声明
void func(void);
static int count = 10; /* 全局变量 */
int main()
{
while(count--)