2023-06-30 18:06:13 +00:00
|
|
|
# Throw away pastebin
|
|
|
|
|
|
|
|
Just a place to throw away some text.
|
|
|
|
|
2023-07-30 10:23:34 +00:00
|
|
|
## `.gitignore`
|
|
|
|
|
|
|
|
```txt
|
|
|
|
# macOS
|
|
|
|
.DS_Store
|
|
|
|
|
|
|
|
# Window
|
|
|
|
*.exe
|
|
|
|
|
|
|
|
# IntelliJ
|
|
|
|
.idea
|
|
|
|
|
|
|
|
# VSCode
|
|
|
|
.vscode
|
|
|
|
|
|
|
|
# Go
|
|
|
|
coverage.out
|
|
|
|
vendor
|
|
|
|
|
|
|
|
# GoReleaser
|
|
|
|
dist
|
|
|
|
```
|
|
|
|
|
2023-06-30 18:06:13 +00:00
|
|
|
## GitHub Actions
|
|
|
|
|
|
|
|
`dependabot.yml`:
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
version: 2
|
|
|
|
updates:
|
|
|
|
- package-ecosystem: "gomod"
|
|
|
|
directory: "/"
|
|
|
|
schedule:
|
|
|
|
interval: "daily"
|
|
|
|
- package-ecosystem: "github-actions"
|
|
|
|
directory: "/"
|
|
|
|
schedule:
|
|
|
|
interval: "daily"
|
|
|
|
```
|
|
|
|
|
|
|
|
`go.yml`:
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
name: Go
|
|
|
|
|
|
|
|
on:
|
|
|
|
push:
|
|
|
|
branches:
|
|
|
|
- main
|
|
|
|
paths:
|
|
|
|
- "**.go"
|
|
|
|
- "go.mod"
|
|
|
|
- "go.sum"
|
|
|
|
pull_request:
|
|
|
|
branches:
|
|
|
|
- main
|
|
|
|
paths:
|
|
|
|
- "**.go"
|
|
|
|
- "go.mod"
|
|
|
|
- "go.sum"
|
|
|
|
|
|
|
|
concurrency:
|
|
|
|
group: ${{ github.workflow }}-${{ github.ref }}
|
|
|
|
cancel-in-progress: true
|
|
|
|
|
|
|
|
jobs:
|
|
|
|
test:
|
|
|
|
name: Test
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
|
|
- uses: actions/checkout@v3
|
|
|
|
- uses: actions/setup-go@v4
|
|
|
|
with:
|
|
|
|
go-version: "stable"
|
|
|
|
- run: go test -race -failfast ./...
|
|
|
|
build:
|
|
|
|
name: Build
|
|
|
|
runs-on: ${{ matrix.os }}
|
|
|
|
strategy:
|
|
|
|
matrix:
|
|
|
|
os: [ubuntu-latest, macos-latest, windows-latest]
|
|
|
|
steps:
|
|
|
|
- uses: actions/checkout@v3
|
|
|
|
- uses: actions/setup-go@v4
|
|
|
|
with:
|
|
|
|
go-version: "stable"
|
|
|
|
- run: go build .
|
|
|
|
golangci-lint:
|
|
|
|
name: golangci-lint
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
|
|
- uses: actions/checkout@v3
|
|
|
|
with:
|
|
|
|
fetch-depth: 0
|
|
|
|
- uses: actions/setup-go@v4
|
|
|
|
with:
|
|
|
|
go-version: "stable"
|
|
|
|
- uses: golangci/golangci-lint-action@v3
|
|
|
|
with:
|
|
|
|
version: latest
|
|
|
|
```
|
|
|
|
|
|
|
|
## Go
|
|
|
|
|
|
|
|
`.golangci.yml`:
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
run:
|
|
|
|
timeout: 5m
|
|
|
|
tests: false
|
|
|
|
skip-dirs:
|
|
|
|
- ".*test.*"
|
|
|
|
- ".*mock.*"
|
|
|
|
- ".*example.*"
|
|
|
|
- ".*utils.*"
|
|
|
|
skip-files:
|
|
|
|
- ".*Mock.*"
|
|
|
|
- ".*_mock.*"
|
|
|
|
|
|
|
|
output:
|
|
|
|
sort-results: true
|
|
|
|
|
|
|
|
linters:
|
|
|
|
disable-all: true
|
|
|
|
enable:
|
|
|
|
# Default
|
|
|
|
- errcheck
|
|
|
|
- gosimple
|
|
|
|
- govet
|
|
|
|
- ineffassign
|
|
|
|
- staticcheck
|
|
|
|
- typecheck
|
|
|
|
- unused
|
|
|
|
# Custom
|
|
|
|
- errchkjson
|
|
|
|
- errname
|
|
|
|
- errorlint
|
|
|
|
- execinquery
|
|
|
|
- forcetypeassert
|
|
|
|
- gocritic
|
|
|
|
- goerr113
|
|
|
|
- gofumpt
|
|
|
|
- gosec
|
|
|
|
- importas
|
|
|
|
- makezero
|
|
|
|
- nilnil
|
|
|
|
- noctx
|
|
|
|
- prealloc
|
|
|
|
- reassign
|
|
|
|
# - rowserrcheck
|
|
|
|
- sqlclosecheck
|
|
|
|
- unconvert
|
|
|
|
# - wastedassign
|
|
|
|
fast: true
|
|
|
|
|
|
|
|
linters-settings:
|
|
|
|
# Default
|
|
|
|
govet:
|
|
|
|
check-shadowing: false
|
|
|
|
disable-all: true
|
|
|
|
enable:
|
|
|
|
- assign
|
|
|
|
- atomic
|
|
|
|
- bools
|
|
|
|
- buildtag
|
|
|
|
- composites
|
|
|
|
- copylocks
|
|
|
|
- fieldalignment
|
|
|
|
- httpresponse
|
|
|
|
- loopclosure
|
|
|
|
- lostcancel
|
|
|
|
- nilfunc
|
|
|
|
- printf
|
|
|
|
- unmarshal
|
|
|
|
- unreachable
|
|
|
|
- unusedresult
|
|
|
|
staticcheck:
|
|
|
|
checks: ["all", "-SA1019"]
|
|
|
|
# Custom
|
|
|
|
gocritic:
|
|
|
|
disabled-checks:
|
|
|
|
- ifElseChain
|
|
|
|
- singleCaseSwitch
|
|
|
|
- unnamedResult
|
|
|
|
- whyNoLint
|
|
|
|
enabled-tags:
|
|
|
|
- diagnostic
|
|
|
|
- style
|
|
|
|
gosec:
|
|
|
|
excludes:
|
|
|
|
- G101
|
|
|
|
- G112
|
|
|
|
- G402
|
|
|
|
- G404
|
|
|
|
- G501
|
|
|
|
- G505
|
|
|
|
exclude-generated: true
|
|
|
|
reassign:
|
|
|
|
patterns:
|
|
|
|
- ".*"
|
|
|
|
```
|
|
|
|
|
|
|
|
`.goreleaser.yml`:
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
before:
|
|
|
|
hooks:
|
|
|
|
- go mod tidy
|
|
|
|
builds:
|
|
|
|
- main: .
|
|
|
|
goos:
|
|
|
|
- linux
|
|
|
|
- windows
|
|
|
|
- darwin
|
|
|
|
goarch:
|
|
|
|
- amd64
|
|
|
|
- arm64
|
|
|
|
universal_binaries:
|
|
|
|
- replace: true
|
|
|
|
archives:
|
|
|
|
- format_overrides:
|
|
|
|
- goos: windows
|
|
|
|
format: zip
|
|
|
|
changelog:
|
|
|
|
skip: false
|
|
|
|
use: github
|
|
|
|
```
|
|
|
|
|
2024-02-08 17:13:49 +00:00
|
|
|
## Git clean up
|
2023-06-30 18:06:13 +00:00
|
|
|
|
2023-08-03 10:33:40 +00:00
|
|
|
```sh
|
|
|
|
# Delete untracked
|
|
|
|
git clean -fdx
|
2023-06-30 18:06:13 +00:00
|
|
|
|
2023-08-03 10:33:40 +00:00
|
|
|
git gc
|
2023-07-30 10:23:34 +00:00
|
|
|
```
|
2023-06-30 18:06:13 +00:00
|
|
|
|
2023-08-03 10:33:40 +00:00
|
|
|
## Delete `.DS_Store`
|
2023-06-30 18:06:13 +00:00
|
|
|
|
2023-08-03 10:33:40 +00:00
|
|
|
With [find](https://stackoverflow.com/q/30483670):
|
|
|
|
|
|
|
|
```sh
|
|
|
|
find . -name ".DS_Store" -print -type f -delete
|
2023-07-30 10:23:34 +00:00
|
|
|
```
|
2023-06-30 18:06:13 +00:00
|
|
|
|
2023-08-03 10:33:40 +00:00
|
|
|
With [fd](https://github.com/sharkdp/fd):
|
2023-06-30 18:06:13 +00:00
|
|
|
|
2023-08-03 10:33:40 +00:00
|
|
|
```sh
|
|
|
|
fd -H '^\.DS_Store$' -tf -X rm
|
|
|
|
```
|
|
|
|
|
2024-01-28 07:10:04 +00:00
|
|
|
## [sd](https://github.com/chmln/sd)
|
|
|
|
|
|
|
|
Remove proto options:
|
|
|
|
|
|
|
|
```sh
|
|
|
|
sd -F 'import "validate/validate.proto";' '' api/raw/*.proto
|
|
|
|
sd -F 'import "marshal-zap.proto";' '' api/raw/*.proto
|
|
|
|
sd -f s '\s\[.*?];' ';' api/raw/*.proto
|
|
|
|
```
|
|
|
|
|
2023-08-03 10:33:40 +00:00
|
|
|
## [fdupes](https://github.com/adrianlopezroche/fdupes)
|
|
|
|
|
|
|
|
Remove duplicated files:
|
|
|
|
|
|
|
|
```sh
|
|
|
|
fdupes -rdN .
|
2023-06-30 18:06:13 +00:00
|
|
|
```
|
2023-07-30 11:13:08 +00:00
|
|
|
|
2023-07-30 18:34:29 +00:00
|
|
|
## [rsync](https://github.com/WayneD/rsync)
|
|
|
|
|
|
|
|
```sh
|
|
|
|
# Result is dst/src
|
2023-08-03 09:22:08 +00:00
|
|
|
rsync -avzP src dst
|
2023-07-30 18:34:29 +00:00
|
|
|
|
|
|
|
# Result is dst/* with * is from src
|
2023-08-03 09:22:08 +00:00
|
|
|
rsync -avzP src/ dst
|
2023-07-30 18:34:29 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
Commonly flags:
|
|
|
|
|
2023-08-03 09:22:08 +00:00
|
|
|
- `-v`: verbose
|
2023-07-30 18:34:29 +00:00
|
|
|
- `-z`: compress
|
|
|
|
- `-P`: enable both `--partial`, `--progress` to easily resume after interupt
|
|
|
|
- `-n`: dry run
|
|
|
|
|
|
|
|
Be careful flags (need dry run if not sure):
|
|
|
|
|
2023-08-05 18:56:25 +00:00
|
|
|
- `-u`: skip if files in **dst** is already newer than in **src**, if you want
|
|
|
|
to sync both ways
|
|
|
|
- `--delete`: delete files in **dst** if not exist in **src**, useful to sync
|
|
|
|
dst with src
|
2023-07-30 18:34:29 +00:00
|
|
|
|
2023-07-30 11:13:08 +00:00
|
|
|
## [F2](https://github.com/ayoisaiah/f2)
|
|
|
|
|
|
|
|
Rename:
|
|
|
|
|
|
|
|
```sh
|
2024-05-12 16:22:38 +00:00
|
|
|
# If dry run, remove --exec
|
2024-06-04 18:45:15 +00:00
|
|
|
f2 --replace "{mtime.YYYY}{mtime.MM}{mtime.DD}_{mtime.H}{mtime.mm}{mtime.ss}_{hash.md5}{ext}" --exec
|
2023-08-03 10:33:40 +00:00
|
|
|
|
2024-05-12 16:22:38 +00:00
|
|
|
# Include ImageSize (require exiftool)
|
2024-06-04 18:45:15 +00:00
|
|
|
f2 --replace "{mtime.YYYY}{mtime.MM}{mtime.DD}_{mtime.H}{mtime.mm}{mtime.ss}_{xt.ImageSize}_{hash.md5}{ext}" --exec
|
|
|
|
|
|
|
|
# Not include time
|
2024-06-05 12:35:42 +00:00
|
|
|
f2 --exclude="\d+x\d+_[a-z\d]{32}" --sort=mtime --replace "{xt.ImageSize}_{hash.md5}{ext}" --exec
|
2023-08-03 10:33:40 +00:00
|
|
|
|
2024-05-12 16:22:38 +00:00
|
|
|
# Remove space in directory
|
|
|
|
f2 --find " " --replace "_" --string-mode --only-dir --exec
|
2023-08-03 10:33:40 +00:00
|
|
|
```
|
|
|
|
|
2024-05-12 16:22:38 +00:00
|
|
|
## [libvips](https://github.com/libvips/libvips)
|
2023-08-03 10:33:40 +00:00
|
|
|
|
2024-05-12 16:22:38 +00:00
|
|
|
Convert:
|
2023-08-21 12:38:37 +00:00
|
|
|
|
|
|
|
```sh
|
2024-05-13 05:14:40 +00:00
|
|
|
# Add --vips-progress to show progress
|
2024-05-12 16:22:38 +00:00
|
|
|
vips jxlsave filename.jpg filename.jxl --keep=none
|
2024-06-23 10:30:11 +00:00
|
|
|
vips jpegsave filename.png filename.jpg --keep=none
|
2024-02-08 17:13:49 +00:00
|
|
|
|
2024-05-12 16:22:38 +00:00
|
|
|
# Batch convert (require fd)
|
2024-06-23 10:30:11 +00:00
|
|
|
fd "jpg|jpeg|png|webp|gif" --exec vips jxlsave {} {.}.jxl --keep=none
|
|
|
|
fd "jpg|jpeg|png|webp|gif" --exec-batch rm
|
|
|
|
|
|
|
|
fd "png|webp|gif" --exec vips jpegsave {} {.}.jpg --keep=none
|
|
|
|
fd "png|webp|gif" --exec-batch rm
|
2024-05-13 05:14:40 +00:00
|
|
|
|
|
|
|
# Rotate
|
|
|
|
vips rot filename.jxl new_filename.jxl d90
|
2024-02-08 17:13:49 +00:00
|
|
|
```
|
2024-06-24 17:29:20 +00:00
|
|
|
|
|
|
|
## [yt-dlp](https://github.com/yt-dlp/yt-dlp)
|
|
|
|
|
|
|
|
Download:
|
|
|
|
|
|
|
|
```sh
|
|
|
|
yt-dlp -f - "https://www.youtube.com/watch?v=video_id"
|
|
|
|
```
|