Skip to content

Instantly share code, notes, and snippets.

@KevinWang15
KevinWang15 / multi-rsync.sh
Created August 9, 2024 13:32
multi-rsync
#!/bin/bash
# Check if both parameters are provided
if [ $# -ne 2 ]; then
echo "Usage: $0 <target_directory> <comma_separated_word_list>"
exit 1
fi
target_dir="$1"
word_list=$(echo "$2" | tr ',' ' ')
#!/bin/bash
# Function to print usage
print_usage() {
echo "Usage: $0 <github-repo> [branch]"
echo "Example: $0 go-gorm/gorm main"
echo "If branch is not specified, 'master' will be used as default."
}
# Check if at least a repository is provided
@KevinWang15
KevinWang15 / attachable.go
Created July 4, 2024 13:10
go - attaching arbitrary data to any pointer type
package attachable
import (
"fmt"
"strings"
"sync"
)
// valuesAttached is a concurrent map to store values associated with pointer instances
var valuesAttached = sync.Map{}
@KevinWang15
KevinWang15 / convert.sh
Created June 24, 2024 05:13
PDF to Image Grid Conversion
# PDF to Image Grid Conversion
magick convert -density 150 "your-pdf.pdf" -alpha remove -alpha off -background white -resize 1000x page_%d.png
magick montage page_*.png -tile 3x3 -geometry 1000x+10+10 -background gray output.png
# Some fun ...
magick convert -density 150 "your-pdf.pdf" -resize 1000x page_%d.png
magick convert -density 150 "your-pdf.pdf" -background white -resize 1000x -flatten output.png
@KevinWang15
KevinWang15 / mustconverttype.go
Created June 19, 2024 03:49
MustConvertType converts an instance of type A to type B using JSON marshal and unmarshal.
// MustConvertType converts an instance of type A to type B using JSON marshal and unmarshal.
// Both types A and B should have the same structure and JSON tags.
// In case of error, it panics.
func MustConvertType[A any, B any](input A) B {
var output B
// Marshal the input type A to JSON
data, err := json.Marshal(input)
if err != nil {
panic(fmt.Errorf("failed to marshal input: %w", err))
@KevinWang15
KevinWang15 / main.go
Created June 13, 2024 05:17
TCP port forward through HTTP CONNECT PROXY
package main
import (
"bufio"
"fmt"
"io"
"io/ioutil"
"net"
"net/http"
"net/url"
@KevinWang15
KevinWang15 / glog.go
Created December 30, 2020 07:26
glog / klog with cobra
package main
import (
"flag"
"fmt"
"github.com/golang/glog"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)
@KevinWang15
KevinWang15 / .zshrc
Created January 26, 2020 05:32
aliases
alias setp="export http_proxy=127.0.0.1:1087 && export https_proxy=127.0.0.1:1087"
alias unsetp="export http_proxy= && export https_proxy="
@KevinWang15
KevinWang15 / mysql.sh
Created April 23, 2018 16:42
backup mysql
#!/bin/bash
# crontab:
# 30 */8 * * * /root/backup/mysql.sh
databases=(db1 db2 db3)
basepath='/root/backup/mysql/'
<?php
/**
* 如果$_REQUEST中出现可能导致sql注入的字符,就返回400。
* 需要在程序一开始的时候就运行。
*
* 注意:本方法只对默认的html表单类型(application/x-www-form-urlencoded)有效
* 如果有文件上传类型的(enctype="multipart/form-data"),则不能执行本方法
*/
function guardAgainstBadCharactersInRequest()