Skip to content

Instantly share code, notes, and snippets.

@kougazhang
kougazhang / go_compress.go
Last active June 17, 2021 06:27
golang compress file (golang 压缩文件) #golang
// usage: Tar("~/home", "home.tar.gz")
func Tar(src, dst string) (err error) {
// 创建文件
fw, err := os.Create(dst)
if err != nil {
return
}
defer fw.Close()
// 将 tar 包使用 gzip 压缩,其实添加压缩功能很简单,
@kougazhang
kougazhang / template.go
Last active February 13, 2022 08:13
[golang 模板] golang 模板 #golang #template
package main
import (
"encoding/json"
"flag"
"fmt"
"io/fs"
"log"
"os"
"path/filepath"
@kougazhang
kougazhang / diff.sh
Created June 30, 2021 06:59
使用git把diff结果写入文件,然后把该文件路径用飞书机器人通知 #shell
#!/bin/zsh
root=<ProjectRoot>
pushd $root
diff=`git diff`
tm=`date +"%Y-%m-%d"`
file=$root/diff-history/$tm
echo $diff > $file
curl -X POST -H "Content-Type: application/json" \
-d "{\"msg_type\":\"text\",\"content\":{\"text\":\"file://$file\"}}" \
<飞书Api>
@kougazhang
kougazhang / sscan.lua
Created July 1, 2021 13:32
redis 执行 lua 脚本 #redis #lua
-- 返回 set 中非 download 状态的成员。
local setName = KEYS[1]
local val = redis.call("sscan", setName, KEYS[2])
-- set 为空
if (val[1] == "0") then
return {}
end
local res = {}
@kougazhang
kougazhang / download.sh
Created July 1, 2021 14:35
shell 使用 xargs 执行并发 #shell #redis
#!/bin/bash
providers=("jingdong")
project=/home/filex/download
etc=$project/etc
cfg=$project/cfg
log=$project/log/$(date "+%Y-%m-%d_%H-%M-%S")
parallism=8
echo "start to check missing log time point"
@kougazhang
kougazhang / Makefile
Created July 9, 2021 06:13
#Makefile #golang
gitHash=$(shell git rev-parse HEAD)
built=$(shell date +"%Y-%m-%d_%H:%M:%S")
build_check:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-X main.version=$(gitHash) -X main.built=$(built) " -trimpath -o filex/share/check ./jobs/check
cp -rf ./jobs/check/etc/check.json ./filex/etc
cp ./jobs/check/check ./filex/bin
build_download:
cp -rf ./jobs/download/etc/* ./filex/etc
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-X main.version=$(gitHash) -X main.built=$(built) " -trimpath -o filex/share/download ./jobs/download
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 {
@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);
}
@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 / 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);