Skip to content

Instantly share code, notes, and snippets.

@nevill
nevill / pre-commit.py
Last active December 6, 2017 09:39
hooks to test if a file contains BOM, compatible with python 2 and 3
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import print_function
from __future__ import unicode_literals
import os.path
import sys
import subprocess
UTF8_BOM = b'\xef\xbb\xbf'
@nevill
nevill / install.sh
Last active January 5, 2023 00:49
Script to install Kubernetes for mainland China
# This script is for Ubuntu 16.04 (xenial)
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
cat <<EOF >/etc/apt/sources.list.d/docker.list
deb https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/ xenial stable
EOF
# from https://yq.aliyun.com/articles/66474
curl https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | apt-key add -
cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
@nevill
nevill / ingress-svc.yml
Last active October 25, 2018 08:14
k8s monitoring
apiVersion: v1
kind: Service
metadata:
name: ingress-nginx
namespace: ingress-nginx
labels:
app.kubernetes.io/name: ingress-nginx
app.kubernetes.io/part-of: ingress-nginx
spec:
type: NodePort
package main
import (
"log"
"math/rand"
"net/http"
"time"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
@nevill
nevill / tips.sh
Last active November 6, 2021 11:31
Useful shell commands
# 在执行程序10秒后终止
ping 192.168.1.1 & read -t 10 || kill $!
ping 192.168.1.1 & sleep 10s; kill $!
# 计算 pi 2000 位
perl -Mbignum=bpi -wle "print bpi(2000)"
@nevill
nevill / memory.md
Last active February 15, 2020 16:36
Go Memory Allocation

Allocator

Data structures

  • fixalloc
    • a free-list allocator for fixed-size off-heap objects, used to manage storage used by the allocator.
  • mheap
    • the malloc heap, managed at page (8192-byte) granularity.
  • mspan
    • a run of pages managed by the mheap.
  • mcentral
@nevill
nevill / bench-metal.log
Created February 27, 2020 08:02
Benchmark results of RangeQuery on VM vs Dedicated
BenchmarkRangeQuery/expr=holt_winters(a_hundred[1d],_0.3,_0.3),steps=1000-48 10 6634700849 ns/op 1875759 B/op 9705 allocs/op
BenchmarkRangeQuery/expr=holt_winters(a_hundred[1d],_0.3,_0.3),steps=1000-48 10 6637383642 ns/op 1875784 B/op 9705 allocs/op
BenchmarkRangeQuery/expr=holt_winters(a_hundred[1d],_0.3,_0.3),steps=1000-48 10 6637649343 ns/op 1875805 B/op 9706 allocs/op
BenchmarkRangeQuery/expr=holt_winters(a_hundred[1d],_0.3,_0.3),steps=1000-48 10 6637758314 ns/op 1875820 B/op 9706 allocs/op
BenchmarkRangeQuery/expr=holt_winters(a_hundred[1d],_0.3,_0.3),steps=1000-48 10 6637945397 ns/op 1870044 B/op 9705 allocs/op
BenchmarkRangeQuery/expr=holt_winters(a_hundred[1d],_0.3,_0.3),steps=1000-48 10 6638105296 ns/op 1870020 B/op 9705 allocs/op
BenchmarkRangeQuery/expr=holt_winters(a_hundred[1d],_0.3,_0.3),steps=1000-48 10 6638157506 ns/op 1875834 B/op 9706 allocs/op
BenchmarkRangeQuery/expr=holt_winters(a_hundred[1d],_0.3,_