Skip to content

Instantly share code, notes, and snippets.

View kaichao's full-sized avatar

Kaichao kaichao

  • CNIC
  • Beijing, China
View GitHub Profile
@kaichao
kaichao / memo.md
Last active May 15, 2020 22:39
备忘
@kaichao
kaichao / log-http-headers.md
Last active March 7, 2024 18:43
nginx: Log complete request/response with all headers

1. switch nginx image to openresty/openresty

2. add the following to server/location (/etc/nginx/conf.d/default.conf)

   set $req_header "";
   set $resp_header "";
   header_filter_by_lua_block{ 
      local h = ngx.req.get_headers();
      for k, v in pairs(h) do
         ngx.var.req_header = ngx.var.req_header .. k.."="..v.." ";
@kaichao
kaichao / shell-cmd.md
Last active August 13, 2023 08:37
常用shell命令

CentOS7上的git2

yum -y remove git git-*
yum -y install https://packages.endpointdev.com/rhel/7/os/x86_64/endpoint-repo.x86_64.rpm
yum -y install git

双远端rsync设置

  • 源端、本地、目标端使用相同用户名
  • 将源端、本地的pub文件拷贝到目标端(ssh-copy-id或直接文本编辑authrized_keys)
@kaichao
kaichao / digital-ocean.md
Last active June 18, 2020 03:08
centos7升级内核,安装docker-ce

安装CentOS 7.x,升级内核

rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
rpm -Uvh https://www.elrepo.org/elrepo-release-7.0-4.el7.elrepo.noarch.rpm
yum --disablerepo="*" --enablerepo="elrepo-kernel" list available
yum --enablerepo=elrepo-kernel install -y kernel-ml

# 若出错,则运行以下命令
#grub2-mkconfig -o /boot/grub2/grub-efi.cfg
awk -F\' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfg
@kaichao
kaichao / bbr.txt
Created September 16, 2019 08:24
BBR
1.升级Linux内核达到4.9以上
2.验证BBR是否已经可用。
A. 验证当前TCP控制算法的命令:
sysctl net.ipv4.tcp_available_congestion_control
返回值一般为:
net.ipv4.tcp_available_congestion_control = bbr cubic reno
或者为:
net.ipv4.tcp_available_congestion_control = reno cubic bbr
B. 验证BBR是否已经启动。
sysctl net.ipv4.tcp_congestion_control
@kaichao
kaichao / disable-ipv6-in-centos7.txt
Created September 3, 2019 08:23
centos7下禁用IPv6
编辑/etc/default/grub文件:
GRUB_CMDLINE_LINUX参数加上ipv6.disable=1
以root运行命令:
grub2-mkconfig -o /boot/grub2/grub.cfg
编辑/etc/ssh/sshd_config 文件,增加一行:
AddressFamily inet
@kaichao
kaichao / oi-template.md
Last active April 18, 2020 11:21
oi template

信息学程序模板

#include<iostream>
#include<stdio.h>
using namespace std;
int main(){
    if(freopen("bus.in","r",stdin)==NULL)
        printf("error while opening input file.\n");
    if(freopen("bus.out","w",stdout)==NULL)
 printf("error while opening output file.\n");
@kaichao
kaichao / Grib2Reader.java
Last active September 7, 2019 06:03
read grib2 大气数据文件
String dataFile = "data/NWP_NMC_T639R/Z_NAFP_C_BABJ_20161108000000_P_CNPC-T639-GMFS-HNEHE-00000.grib2";
try {
// open netcdf/grib/grib2 file from argument
NetcdfDataset gid = NetcdfDataset.openDataset(dataFile);
// get all grid tables in the file
List<Variable> variables = gid.getReferencedFile().getVariables();
for (int i = 0; i < variables.size(); i++) {
Variable var = variables.get(i);
if ((!var.isMetadata()) && (!var.getRanges().isEmpty())) {
System.out.format("%s, %s: %s %s\n", var.getName(), var.getDataType().toString(),var.getRanges().toString(),var.getUnitsString());
@kaichao
kaichao / HanoiTower.java
Last active September 7, 2019 05:54
Hanoi Tower
import java.util.Stack;
/**
* 递归求解汉诺塔
*/
public class HanoiTower {
// 三个塔 a、b、c
Stack<Integer> a,b,c;
public static void main(String[] args) {