Skip to content

Instantly share code, notes, and snippets.

View wubin1989's full-sized avatar

武斌 wubin1989

View GitHub Profile
@wubin1989
wubin1989 / gist:673f4f6b4456b9841ec44f5cd9158c46
Created June 30, 2023 15:00 — forked from jedp/gist:3166329
Hash to small integer
// Hash 'string' to a small number (digits default: 6)
function hash(string, digits) {
digits = digits || 6;
var m = Math.pow(10, digits+1) - 1;
var phi = Math.pow(10, digits) / 2 - 1;
var n = 0;
for (var i = 0; i < string.length; i++) {
n = (n + phi * string.charCodeAt(i)) % m;
}
return n.toString();
@wubin1989
wubin1989 / errgroup_withcontext.go
Created June 3, 2023 04:31 — forked from dragonsinth/errgroup_withcontext.go
Using errgroup.WithContext() in Golang server handlers
package main
import (
"context"
"encoding/json"
"fmt"
"io"
"log"
"sync/atomic"
"time"
@wubin1989
wubin1989 / html_entities.go
Created May 5, 2023 11:42 — forked from brandonrachal/html_entities.go
A Go Lang Program to Convert Special Symbols to HTML Entities
package main
import (
"fmt"
"bufio"
"os"
"strconv"
)
func ReadLinesFromFile(file_path string) ([]string, error) {

Two approaches to handle error responses from Spring WebClient calls globally:

  • Exceptions with webclients are all wrapped in WebClientResponseException class. So we can handle that using Spring's ExceptionHandler annotation.

  • Using ExchangeFilterFunction while constructing the webclient bean.

@wubin1989
wubin1989 / prometheus.yml
Created January 3, 2023 08:27 — forked from weibeld/prometheus.yml
Example Prometheus configuration (scrape config)
global:
scrape_interval: 10s
scrape_configs:
- job_name: node
static_configs:
- targets:
- localhost:9100
- job_name: python-app
static_configs:
- targets:
@wubin1989
wubin1989 / latency.txt
Created November 28, 2022 02:46 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@wubin1989
wubin1989 / docker-compose.yml
Created October 24, 2022 07:01 — forked from bocharovf/docker-compose.yml
Complete Jaeger docker-compose deployment with ElasticSearch (oss) and Apache Kafka. Jaeger Query and Kibana to search logs and traces. Monitoring with Prometheus and Grafana.
version: "3"
services:
# Using ElasticSearch as a storage for traces and logs
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch-oss:6.7.1
networks:
- elastic-jaeger
ports:
@wubin1989
wubin1989 / Docker
Created October 4, 2022 04:21 — forked from mitchwongho/Docker
Docker 'run' command to start an interactive BaSH session
# Assuming an Ubuntu Docker image
$ docker run -it <image> /bin/bash
@wubin1989
wubin1989 / call_method_with_reflection.go
Created July 16, 2022 16:41 — forked from tkrajina/call_method_with_reflection.go
Golang, call method (and fill arguments) with reflection
package main
import (
"fmt"
"reflect"
)
type Aaa struct {
a string
}
@wubin1989
wubin1989 / hash.go
Created June 27, 2022 12:55 — forked from kchugalinskiy/hash.go
golang get hash from interface{}
package hash
import (
"crypto/md5"
"encoding/base64"
"reflect"
"unsafe"
)
// Hash returns md5 hash taken from any object