Skip to content

Instantly share code, notes, and snippets.

View tsingson's full-sized avatar
🏠
Working from home

tsingson tsingson

🏠
Working from home
View GitHub Profile

mTLS 配置

对于mTLS的配置的证书来说,有如下的提示。

  • 三个文件。 对于大多数系统,如:MySQL, Redis,PostgreSQL。会需要三个文件:CA证书 + CERT 和 KEY。可以在我的这个开源项目(https://github.com/haoel/mTLS/tree/main/certs )中找到我生成的CA,以及 Server 和 Client的 .crt.key 文件。生成的方法也在我的那个开源项目中了。

  • 两个文件。 对于有的系统,比如:MongoDB,他只要两个文件,一个是CA,一个是 pem 文件,对于pem文件,你可以直接把上面的 .crt 和 .key 合并了就好了。如:cat server.crt server.key > server.pem

  • JKS文件。 对于一些系统,比如:Kafka 和 Zookeeper。他要的不是上面的明文的格式,他要的是一种jks的格式,这是Java的格式。怎么从上面的明文的方式转到jks的文件。需要经过下面几步。

@snoyberg
snoyberg / main.rs
Created December 29, 2020 16:33
HTTP reverse proxy in Rust, from December 29, 2020 livestream
use hyper::{Client, Server, Request, Response, Body};
use anyhow::*;
use std::net::SocketAddr;
use hyper::service::{make_service_fn, service_fn};
use std::sync::{Arc, RwLock};
fn mutate_request(req: &mut Request<Body>) -> Result<()> {
for key in &["content-length", "transfer-encoding", "accept-encoding", "content-encoding"] {
req.headers_mut().remove(*key);
}
@anthowave
anthowave / valtio-promise.js
Last active March 27, 2022 23:15
Valtio(proxy-based state management library) demo that natively handles promise with React suspense
import React, { Suspense } from "react";
import { proxy, useProxy } from "valtio";
import { a, useSpring } from "@react-spring/web";
const fetchData = async (id) => {
const response = await fetch(
`https://hacker-news.firebaseio.com/v0/item/${id}.json`
);
return await response.json();
};
@stevevance
stevevance / array_trim.sql
Last active March 8, 2025 23:43
Trim the string elements of an array in PostgreSQL (wrap this function around an array or another function that returns an array, like string_to_array).
CREATE OR REPLACE FUNCTION array_trim(text[])
RETURNS text[]
AS
$$
DECLARE
text ALIAS FOR $1;
retVal text[];
BEGIN
FOR I IN array_lower(text, 1)..array_upper(text, 1) LOOP
retVal[I] := trim(text[I]);
@somombo
somombo / Readme.md
Last active May 21, 2020 09:50
Example of Global (Un)Marshaling with flatbuffers
@faiface
faiface / .md
Last active January 23, 2020 04:53
Go 2 generics counterproposal: giving up restricting types

Go 2 generics counterproposal: giving up restricting types

"I want to make a generic function which works on any type that satisfies these and these constraints."

When we think about generics, this is the sort of problem that pops up into our minds. The critical part is restricting the set of types our function intends to work on. Trying to solve this problem of restriction has led people to what I call reasons why we hesitate to have generics in Go.

C++ templates with horrific error messages, or even it's new concepts, Java's T extends Comparable<T>, Rust's generic traits, Haskell's type classes, and sadly even contracts from the [original generics proposal by the Go Team](https://go.googlesource.com/proposal/+/master/desig

@CAFxX
CAFxX / golang_minimize_allocations.md
Last active March 9, 2025 14:32
Minimize allocations in Go

📂 Minimize allocations in Go

A collection of tips for when you need to minimize the number of allocations in your Go programs.

Use the go profiler to identify which parts of your program are responsible for most allocations.

⚠️ Never apply these tricks blindly (i.e. without measuring the actual performance benefit/impact). ⚠️

Most of these tricks cause a tradeoff between reducing memory allocations and other aspects (including e.g. higher peak memory usage, higher CPU usage, lower maintainability, higher probability of introducing subtle bugs). Only apply these tricks if the tradeoff in every specfic case is globally positive.

@tidwall
tidwall / main.go
Created March 13, 2019 17:46
Go 1.12 network slowdown on Darwin
package main
import (
"fmt"
"io"
"log"
"net"
"os"
"sync"
"sync/atomic"
@beginor
beginor / pg-find-table-foreign-keys.sql
Last active July 19, 2019 16:48
[查找表的外键关联] find a table's foreign keys postgresql #PostgreSQL
SELECT
tc.table_schema,
tc.constraint_name,
tc.table_name,
kcu.column_name,
ccu.table_schema AS foreign_table_schema,
ccu.table_name AS foreign_table_name,
ccu.column_name AS foreign_column_name
FROM
information_schema.table_constraints AS tc
type ConnPool struct {
pgx.ConnPool
}
type AfterAcquireFunc func(c *pgx.Conn) error
// NewConnPool creates a new ConnPool. config.ConnConfig is passed through to
// Connect directly.
func NewConnPool(config pgx.ConnPoolConfig) (p *ConnPool, err error) {
pp, err := pgx.NewConnPool(config)