Skip to content

Instantly share code, notes, and snippets.

@kevinclcn
kevinclcn / shell_tips.sh
Last active October 11, 2019 14:11
shell使用技巧
# 遍历一个数字范围, https://stackoverflow.com/questions/169511/how-do-i-iterate-over-a-range-of-numbers-defined-by-variables-in-bash
for i in $(seq 1 $END); do echo $i; done
# 枚举多台机器上的java堆栈
for i in $(seq 204 231); do ssh 192.168.12.$i "ls -lh /opt/log/stash/customer/java_pid1.hprof"; done
# 使用sed做替换
gsed -i -e 's/\(FROM .*alpine-openjdk8[^:]*\)$/\1:8u221/g' */*/Dockerfile
# 使用ruby处理json行, 并设定encoding
@kevinclcn
kevinclcn / benchmark+go+nginx.md
Created July 26, 2019 05:18 — forked from hgfischer/benchmark+go+nginx.md
Benchmarking Nginx with Go

Benchmarking Nginx with Go

There are a lot of ways to serve a Go HTTP application. The best choices depend on each use case. Currently nginx looks to be the standard web server for every new project even though there are other great web servers as well. However, how much is the overhead of serving a Go application behind an nginx server? Do we need some nginx features (vhosts, load balancing, cache, etc) or can you serve directly from Go? If you need nginx, what is the fastest connection mechanism? This are the kind of questions I'm intended to answer here. The purpose of this benchmark is not to tell that Go is faster or slower than nginx. That would be stupid.

So, these are the different settings we are going to compare:

  • Go HTTP standalone (as the control group)
  • Nginx proxy to Go HTTP
  • Nginx fastcgi to Go TCP FastCGI
  • Nginx fastcgi to Go Unix Socket FastCGI
@kevinclcn
kevinclcn / LC_CTYPE.txt
Created February 22, 2019 10:28 — forked from ibrahimlawal/LC_CTYPE.txt
Centos warning: setlocale: LC_CTYPE: cannot change locale (UTF-8): No such file or directory
vi /etc/environment
add these lines...
LANG=en_US.utf-8
LC_ALL=en_US.utf-8
@kevinclcn
kevinclcn / gophers.txt
Created February 3, 2019 07:25
golang gopher logos
https://raw.githubusercontent.com/ashleymcnamara/gophers/master/7TH_BIRTHDAY.png
https://raw.githubusercontent.com/ashleymcnamara/gophers/master/ASHLEY_STEVE.png
https://raw.githubusercontent.com/ashleymcnamara/gophers/master/Azure_Bit_Gopher.png
https://raw.githubusercontent.com/ashleymcnamara/gophers/master/Azure_Gophers.png
https://raw.githubusercontent.com/ashleymcnamara/gophers/master/BATMAN_GOPHER.png
https://raw.githubusercontent.com/ashleymcnamara/gophers/master/BELGIUM.png
https://raw.githubusercontent.com/ashleymcnamara/gophers/master/BLUE_GLASSES_GOPHER.png
https://raw.githubusercontent.com/ashleymcnamara/gophers/master/BLUE_GOPHER.png
https://raw.githubusercontent.com/ashleymcnamara/gophers/master/BUFFALO_CASTS.png
https://raw.githubusercontent.com/ashleymcnamara/gophers/master/Biker_Gopher.png

Kafka 0.11.0.0 (Confluent 3.3.0) added support to manipulate offsets for a consumer group via cli kafka-consumer-groups command.

  1. List the topics to which the group is subscribed
kafka-consumer-groups --bootstrap-server <kafkahost:port> --group <group_id> --describe

Note the values under "CURRENT-OFFSET" and "LOG-END-OFFSET". "CURRENT-OFFSET" is the offset where this consumer group is currently at in each of the partitions.

  1. Reset the consumer offset for a topic (preview)
package main
import (
"fmt"
"log"
"net"
"time"
)
// Dialer .
@kevinclcn
kevinclcn / docker-cleanup-resources.md
Created September 16, 2018 12:46 — forked from bastman/docker-cleanup-resources.md
docker cleanup guide: containers, images, volumes, networks

Docker - How to cleanup (unused) resources

Once in a while, you may need to cleanup resources (containers, volumes, images, networks) ...

delete volumes

// see: https://github.com/chadoe/docker-cleanup-volumes

$ docker volume rm $(docker volume ls -qf dangling=true)

$ docker volume ls -qf dangling=true | xargs -r docker volume rm

@kevinclcn
kevinclcn / bench.txt
Created August 21, 2018 02:49 — forked from rodaine/bench.txt
Code snippets for my blog post "The X-Files: Avoiding Concurrency Boilerplate with golang.org/x/sync"
BenchmarkMutexCache/10-8 10000000 180 ns/op 0 B/op 0 allocs/op
BenchmarkMutexCache/100-8 10000000 187 ns/op 0 B/op 0 allocs/op
BenchmarkMutexCache/1000-8 10000000 214 ns/op 0 B/op 0 allocs/op
BenchmarkMutexCache/10000-8 10000000 231 ns/op 0 B/op 0 allocs/op
BenchmarkMutexCache/100000-8 5000000 254 ns/op 2 B/op 0 allocs/op
BenchmarkMutexCache/1000000-8 1000000 1159 ns/op 102 B/op 1 allocs/op
BenchmarkMutexCache/10000000-8 1000000 1481 ns/op 184 B/op 2 allocs/op
BenchmarkMutexCache/100000000-8 1000000 1655 ns/op 187 B/op 3 allocs/op
BenchmarkSyncMapCache/10-8 5000000 221 ns/op 0 B/op 0 allocs/op
@kevinclcn
kevinclcn / gist:1df8bf7116acc9fda96576c79531527f
Last active August 15, 2018 07:39 — forked from Capncavedan/gist:2844679
Analyze MySQL binary log file
# from http://dzone.com/snippets/analyse-binary-log
# cat /bin/mylog
#!/bin/sh
# usage:
#$ mylog /mysql-bin-log/db-bin.000223
# 2132 insert into customers
# 1887 update userlog_access
# 788 insert into gn_commission
# 718 insert into con_tab
@kevinclcn
kevinclcn / manual.md
Last active September 21, 2024 05:50
pandoc导出中文pdf的模板

http://code.haleby.se/2017/01/27/markdown-to-pdf-in-macosx/

  • 安装pandoc,mactex和xelatex
  • 命令行程序都在/Libarary/Tex/Root/bin/x86_64-darwin/下面,需要将pdflatex, xelatex, tlmgr链接到/user/local/bin下面
  • 需要使用tlmgr安装titling, lastpage
  • 需要提供一个导出pdf的latex模板,默认的模板不支持中文
  • 调用命令生成pdf

pandoc --pdf-engine=xelatex --template=template accesstoken.md create.md customer.md customerevent.md list.md tag.md -o customer.pdf