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
@xykong
xykong / k8sdump.sh
Last active Dec 13, 2022
Export Kubernetes cluster resource to yaml.
View k8sdump.sh
#!/usr/bin/env bash
readonly SCRIPT=$(basename "$0")
readonly VERSION='1.0.0'
readonly AUTHOR='xy.kong@gmail.com'
readonly SOURCE='https://gist.github.com/xykong/6efdb1ed57535d18cb63aa8e20da3f4b'
# For script running robust
set -o nounset # to exit when your script tries to use undeclared variables
set -o errexit # to make your script exit when a command fails
@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 (
@madkoding
madkoding / install-docker.sh
Last active Nov 26, 2022
Install Docker-CE script for Deepin Linux
View install-docker.sh
#!/bin/sh
# Shell script to add docker-ce to Deepin Linux repositories
# Remove old docker
sudo apt-get remove -y docker docker-engine docker.io containerd runc
# Install dependencies
sudo apt-get install -y apt-transport-https ca-certificates curl gnupg2 software-properties-common
@nanmu42
nanmu42 / openinbrowser.go
Created May 20, 2019
Golang: Open URL in Browser
View openinbrowser.go
func openBrowser(url string) {
var err error
switch runtime.GOOS {
case "linux":
err = exec.Command("xdg-open", url).Start()
case "windows":
err = exec.Command("rundll32", "url.dll,FileProtocolHandler", url).Start()
case "darwin":
err = exec.Command("open", url).Start()
@nanmu42
nanmu42 / Dockerfile
Last active Jan 29, 2021
Minimal-sized Golang Docker Image
View Dockerfile
FROM golang:1-alpine as golang
RUN apk --no-cache add git zip tzdata ca-certificates
# avoid go path, use go mod
WORKDIR /app
COPY . .
RUN CGO_ENABLED=0 go build -ldflags "-s -w -extldflags "-static"" ./cmd/appnamehere
WORKDIR /usr/share/zoneinfo
# -0 means no compression. Needed because go's
# tz loader doesn't handle compressed data.
RUN zip -r -0 /zoneinfo.zip .
@nanmu42
nanmu42 / pkcs7padding.go
Last active Dec 20, 2022
Golang PKCS7 Padding/Unpadding
View pkcs7padding.go
// pkcs7strip remove pkcs7 padding
func pkcs7strip(data []byte, blockSize int) ([]byte, error) {
length := len(data)
if length == 0 {
return nil, errors.New("pkcs7: Data is empty")
}
if length%blockSize != 0 {
return nil, errors.New("pkcs7: Data is not block-aligned")
}
padLen := int(data[length-1])
@nanmu42
nanmu42 / update_tmux.sh
Last active Apr 5, 2022
Update tmux to latest version
View update_tmux.sh
#!/usr/bin/env bash
set -e
# dependecies
apt update
apt install -y git automake build-essential pkg-config libevent-dev libncurses5-dev byacc
# where our temp file locates
rm -rf /tmp/tmux
@den-crane
den-crane / gist:6eff375752a236a456e1b3dc2ca7db62
Last active Dec 11, 2022
Clickhouse example AggregatingMergeTree, (max, min, avg ) State / Merge
View gist:6eff375752a236a456e1b3dc2ca7db62
DROP TABLE IF EXISTS requests;
CREATE TABLE requests (
request_date Date,
request_time DateTime,
response_time Int,
request_uri String)
ENGINE = MergeTree(request_date, (request_time, request_uri), 8192);