Skip to content

Instantly share code, notes, and snippets.

@kougazhang
kougazhang / my.cnf
Last active October 28, 2021 01:11 — forked from fevangelou/my.cnf
Optimized my.cnf configuration for MySQL/MariaSQL (on Ubuntu, CentOS etc. servers)
# === Optimized my.cnf configuration for MySQL/MariaSQL (on Ubuntu, CentOS etc. servers) ===
#
# by Fotis Evangelou, developer of Engintron (engintron.com)
#
# ~ Updated February 2021 ~
#
#
# The settings provided below are a starting point for a 8-16 GB RAM server with 4-8 CPU cores.
# If you have different resources available you should adjust accordingly to save CPU, RAM & disk I/O usage.
#
@kougazhang
kougazhang / git_sync.sh
Created October 20, 2021 06:25
#shell #git
#!/usr/bin/env bash
# sync src to git repository.
# src is file
src=$1
# dest is dir
dest=$2
cp $src $dest
@kougazhang
kougazhang / clean-hdfs.awk
Last active January 17, 2023 04:03
#shell #awk
# run command: hdfs dfs -ls /cdn-logs/<pvdName>/raw/*/*/*|awk -f ./clean.awk
BEGIN{
# file expiration date
remaining = 25 * 24 * 3600
}
{
# $8 is filepath, get datetime from filepath
@kougazhang
kougazhang / tool.sh
Last active February 28, 2022 00:55
#shell #delete #rsync
# clean the same relative path in echo disk. the disk name like /disk/sata01, /disk/sata02
for i in {1..12};do
if [ $i -lt 10 ]; then
i=0$i
fi
rm -rf /disk/sata$i/<filepath>
done
@kougazhang
kougazhang / batch-remove-docker-images.sh
Created September 15, 2021 10:59
批量删除镜像 #shell #docker
# delete images that contains none.
docker images|grep none|awk '{print $3}'|xargs -n1 -I{} docker rmi {}
@kougazhang
kougazhang / Dockerfile
Last active September 15, 2021 11:11
分阶段打包 #Dockfile
FROM golang:1.6 as builder
RUN mkdir -p /home/filex
RUN mkdir -p /disk/ssd1
WORKDIR /home/filex
ARG project
COPY ./filex/$project .
FROM builder as job
# 注意,如果 stage 中想要使用 ARG 需要重新在此重新定义
@kougazhang
kougazhang / readAndWrite.java
Last active September 9, 2021 03:34
读写文件 #java
@Test
public void toUpyunLog2() throws Exception {
InputStream in = getClass().getResourceAsStream("/aliyun-3");
BufferedReader in2 = new BufferedReader(new InputStreamReader(in));
String lineTxt;
// System.getProperty("user.home") 获取用户主目录
File file = new File(System.getProperty("user.home") + "/aliyun-3-wanted");
// 文件不存在则创建
file.createNewFile();
FileWriter fw = new FileWriter(file);
@kougazhang
kougazhang / Difference.go
Created September 3, 2021 08:08
#golang
func Difference(a, b []string) []string {
res := make([]string, 0)
for _, aItem := range a {
var same bool
for _, bItem := range b {
if aItem == bItem {
same = true
break
}
}
@kougazhang
kougazhang / GZIPOutputFormat.java
Created September 1, 2021 05:50
#java #flink
import org.apache.flink.api.java.io.TextOutputFormat;
import org.apache.flink.core.fs.Path;
import java.io.IOException;
public class GZIPOutputFormat<T> extends TextOutputFormat<T> {
public GZIPOutputFormat(Path outputPath) {
super(outputPath);
}
var dataUnitPattern, _ = regexp.Compile(`(\d+)\s*([a-zA-Z]+)`)
func ParseDataStorage(s string) (int64, error) {
all := dataUnitPattern.FindAllStringSubmatch(s, -1)
if len(all) != 1 || len(all[0]) != 3 {
return 0, fmt.Errorf("invalid %s", s)
}
d, u := all[0][1], all[0][2]
num, err := strconv.ParseInt(d, 10, 32)
if err != nil {