Skip to content

Instantly share code, notes, and snippets.

Avatar

LI Zhennan nanmu42

View GitHub Profile
@nanmu42
nanmu42 / Flink: throttle messages to walkaround deadlock under heavy iteration feedback load.md
Last active Oct 11, 2021
Flink: throttle messages to walkaround deadlock under heavy iteration feedback load
View Flink: throttle messages to walkaround deadlock under heavy iteration feedback load.md
@nanmu42
nanmu42 / Dockerfile
Created Mar 22, 2021
Golang: Dockerfile based on Debian
View Dockerfile
FROM golang:buster as golang
RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y \
ca-certificates \
tzdata \
build-essential \
tar \
bash
WORKDIR /app
COPY . .
@nanmu42
nanmu42 / firstn.go
Created Mar 8, 2021
Golang: returns first n UTF-8 character at Most
View firstn.go
func firstNUTF8AtMost(s string, n int) string {
i := 0
for j := range s {
if i >= n {
return s[:j]
}
i++
}
return s
}
@nanmu42
nanmu42 / fileserver.go
Created Mar 6, 2021
Golang Quick Static File Server
View fileserver.go
package main
import (
"flag"
"fmt"
"net"
"net/http"
)
var (
@nanmu42
nanmu42 / isPrivateIP.go
Created Jan 19, 2021
Golang: check if IP address is private
View isPrivateIP.go
// source: https://stackoverflow.com/questions/41240761/check-if-ip-address-is-in-private-network-space
var privateIPBlocks []*net.IPNet
func init() {
for _, cidr := range []string{
"127.0.0.0/8", // IPv4 loopback
"10.0.0.0/8", // RFC1918
"172.16.0.0/12", // RFC1918
"192.168.0.0/16", // RFC1918
"169.254.0.0/16", // RFC3927 link-local
@nanmu42
nanmu42 / vue.config.js
Created Jan 13, 2021
A vue.config.js example for starting new project
View vue.config.js
const CompressionPlugin = require("compression-webpack-plugin");
const fileToCompressRegex = /\.(js|css|htm|html|svg|png|txt|json|wasm)$/
const productionMode = process.env.NODE_ENV === 'production'
let plugins = []
if (productionMode) {
plugins.push(new CompressionPlugin({
filename: '[path][base].br[query]',
algorithm: 'brotliCompress',
test: fileToCompressRegex,
@nanmu42
nanmu42 / remove_slice_duplicates.go
Created Nov 18, 2020
Golang Remove Slice Duplicates
View remove_slice_duplicates.go
// source: https://www.reddit.com/r/golang/comments/5ia523/idiomatic_way_to_remove_duplicates_in_a_slice/db6qa2e/
func SliceUniqMap(s []int) []int {
seen := make(map[int]struct{}, len(s))
j := 0
for _, v := range s {
if _, ok := seen[v]; ok {
continue
}
seen[v] = struct{}{}
s[j] = v
@nanmu42
nanmu42 / detect-touchscreen.js
Last active Mar 23, 2020
Javascript: Does the device have a touchscreen?
View detect-touchscreen.js
function isTouchDevice() {
return 'ontouchstart' in window
}
@nanmu42
nanmu42 / awk.sh
Created Mar 11, 2020
awk examples
View awk.sh
# unique line
awk '{!seen[$0]++};END{for(i in seen) if(seen[i]==1)print i}' file
# second column of a csv, with white spaces and quotes stripped
awk -F',' '{gsub(/[ "]/, "", $0);print $2}' some.csv > dest.txt
View delete-k3s.md

Run /usr/local/bin/k3s-uninstall.sh