Skip to content

Instantly share code, notes, and snippets.

@alwaysLinger
alwaysLinger / 0-go-os-arch.md
Created April 11, 2022 11:50 — forked from asukakenji/0-go-os-arch.md
Go (Golang) GOOS and GOARCH

Go (Golang) GOOS and GOARCH

All of the following information is based on go version go1.17.1 darwin/amd64.

GOOS Values

GOOS Out of the Box
aix
android
@alwaysLinger
alwaysLinger / nginx.conf
Created June 18, 2022 05:32 — forked from sunwu51/nginx.conf
openresty配置详解
# 概述:一共三大部分配置。
# 其中#注释掉的可以在需要的时候开启并修改,没有注释掉的(除了下面location示例)不要删掉,基本都是必须的配置项。
###############################第一部分 全局配置############################
#user nobody; 指定启动进程的用户,默认不用指定即可。
#error_log logs/error.log; 配置日志输出,虽然叫error_log但是可以定义输出的级别,默认不写是ERROR级别
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid; 记录pid的文件,默认就是放到这个位置,可以修改。
@alwaysLinger
alwaysLinger / learn.lua
Created June 18, 2022 13:49 — forked from sunwu51/learn.lua
lua learn
-- 直接赋值是全局变量一般不要这么使用
a = 10
-- local是指定当前作用域(一般指大括号或当前文件内)有效的变量
local a = 10
-- 数字
local b = 10.1
print(a + b) -- 打印20.1,支持常见的运算符以及位运算符
print(15 & (1<<2)) -- 4
@alwaysLinger
alwaysLinger / disk_test.go
Created February 1, 2023 15:15 — forked from scukonick/disk_test.go
Golang Go Threadsafe write to the same file from multiple goroutines
package xxx
import (
"fmt"
"io"
"os"
"strings"
"sync"
"testing"
)
@alwaysLinger
alwaysLinger / weight-utility.php
Created November 25, 2023 07:41 — forked from irazasyed/weight-utility.php
PHP: Utility function for getting random values with weighting.
<?php
/**
* getRandomWeightedElement()
* Utility function for getting random values with weighting.
* Pass in an associative array, such as array('A'=>5, 'B'=>45, 'C'=>50)
* An array like this means that "A" has a 5% chance of being selected, "B" 45%, and "C" 50%.
* The return value is the array key, A, B, or C in this case. Note that the values assigned
* do not have to be percentages. The values are simply relative to each other. If one value
* weight was 2, and the other weight of 1, the value with the weight of 2 has about a 66%
* chance of being selected. Also note that weights should be integers.
@alwaysLinger
alwaysLinger / protoc-encode.md
Last active January 20, 2024 14:54 — forked from henridf/protoc-encode.md
Encoding a protobuf with `protoc --encode`

I needed to quickly encode a protobuf from the command-line, and while I pretty much immediately came across protoc --encode as the obvious solution, I did not find much documentation on the input textual syntax.

Here is the relevant snippet from protoc --help:

--encode=MESSAGE_TYPE       Read a text-format message of the given type
                              from standard input and write it in binary
                              to standard output.  The message type must
                              be defined in PROTO_FILES or their imports.
@alwaysLinger
alwaysLinger / deepcopy.go
Created September 22, 2024 16:10 — forked from soroushjp/deepcopy.go
Golang: deepcopy map[string]interface{}. Could be used for any other Go type with minor modifications.
// Package deepcopy provides a function for deep copying map[string]interface{}
// values. Inspired by the StackOverflow answer at:
// http://stackoverflow.com/a/28579297/1366283
//
// Uses the golang.org/pkg/encoding/gob package to do this and therefore has the
// same caveats.
// See: https://blog.golang.org/gobs-of-data
// See: https://golang.org/pkg/encoding/gob/
package deepcopy
@alwaysLinger
alwaysLinger / main.go
Created October 20, 2024 15:41 — forked from lyuxuan/main.go
Channelz Demo: Client
/*
*
* Copyright 2018 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
@alwaysLinger
alwaysLinger / main.go
Created October 20, 2024 15:41 — forked from lyuxuan/main.go
Channelz Demo: Server
/*
*
* Copyright 2018 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
@alwaysLinger
alwaysLinger / request-response.go
Created January 20, 2025 07:26 — forked from hassansin/request-response.go
Request-response pattern over asynchronous protocol using Go channel
package main
import (
"errors"
"fmt"
"math/rand"
"net/http"
"sync"
"time"