Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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)
}
}
package main
import "fmt"
func main() {
ben := &Ben{name: "Ben"}
jerry := &Jerry{name: "Jerry"}
var maker IceCreamMaker = ben
var loop0, loop1 func()
  • 声明变量都加 $
  • 调用类 a 的方法b 使用 $a->b

php 执行文件需要写:

<? php
  echo "hello"
?>
cmake_minimum_required(VERSION 3.15)
project(run_curl C)
set(CMAKE_C_STANDARD 99)
# 设置头文件
set(INC_DIR ./curl/include)
# 设置源码
set(LINK_DIR ./curl/lib)
@kougazhang
kougazhang / fctl.sh
Created November 10, 2021 02:39
#shell #render #template
#!/usr/bin/env bash
function exitIfEmpty() {
if [ -z "$2" ]; then
echo "$1 is empty"
exit 1
fi
}
function initJob() {
@kougazhang
kougazhang / scan.lua
Created November 1, 2021 08:30
#lua #redis
-- scan whole keys in redis by key_pattern and filter
-- key_pattern: key regexp
-- count: match count for once scan
-- filter: one function that accepts the value of key as param.
local scan=function(key_pattern, count, filter)
local start = "-1"
local lst = {}
while (start ~= "0") do
if (start == "-1") then