Skip to content

Instantly share code, notes, and snippets.

View codcodog's full-sized avatar
🤷‍♂️
how to exit vim

h2O codcodog

🤷‍♂️
how to exit vim
  • ShenZhen, China
View GitHub Profile
@codcodog
codcodog / LICENSE
Created September 9, 2021 03:41
MIT License
MIT License
Copyright (c) 2021 codcodog.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
@codcodog
codcodog / lock-for-cron.sh
Created May 19, 2021 01:58
crontab 防止重复执行
0 23 * * * (flock -xn ./test.lock -c "sh /root/test.sh")
@codcodog
codcodog / big-file.sh
Last active April 26, 2021 01:06
大文件生成
# 生成 500M 大小的文件
dd if=/dev/zero of=test bs=1M count=500
@codcodog
codcodog / json-format.vim
Created March 23, 2021 08:44
vim json format
:%!python -m json.tool
@codcodog
codcodog / sql_dump.sh
Last active May 5, 2021 07:49
mysqldump 导出数据库表结构
# 只导出表结构
mysqldump -uroot -p -d DB_NAME | sed 's/ AUTO_INCREMENT=[0-9]*//g' > FILENAME.sql
# 导出表结构和数据
mysqldump -uroot -p DB_NAME > FILENAME.sql
@codcodog
codcodog / bias.py
Created November 13, 2020 07:25
bias calculate
#!/usr/bin/env python
import sys
avg_price = float(sys.argv[1])
new_price = float(sys.argv[2])
bias = float(sys.argv[3])
unit = (new_price - avg_price) / bias
@codcodog
codcodog / upload_image.go
Created September 1, 2020 07:25
上传图片校验
import (
"image"
_ "image/gif"
_ "image/jpeg"
_ "image/png"
)
// 注意,需要 import 图片格式的包,要不 decodeConfig 会报 image: unknown format
func uploadOpcategoryImage(c *bm.Context) {
websiteID := middlewares.GetCurrentWebsiteID(c)
if websiteID == 0 {
@codcodog
codcodog / uploadImage.go
Created August 25, 2020 05:14
golang 上传图片
// 上传图片
func UploadImage(websiteID uint64, name string, file io.Reader, uploadCdn bool) (uint64, string, error) {
url, err := getImageUrl()
if err != nil {
return 0, "", err
}
var isLocal uint64
if uploadCdn {
isLocal = 0
@codcodog
codcodog / curl.md
Created August 6, 2020 05:19 — forked from subfuzion/curl.md
curl POST examples

Common Options

-#, --progress-bar Make curl display a simple progress bar instead of the more informational standard meter.

-b, --cookie <name=data> Supply cookie with request. If no =, then specifies the cookie file to use (see -c).

-c, --cookie-jar <file name> File to save response cookies to.

@codcodog
codcodog / created_updated.sql
Last active June 30, 2020 06:36
Mysql created_at updated_at 字段定义
CREATE TABLE demo (
created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
) ENGINE=InnoDB DEFAULT CHARSET=utf8;