Skip to content

Instantly share code, notes, and snippets.

View Guaderxx's full-sized avatar

顾阿德 Guaderxx

View GitHub Profile
@Guaderxx
Guaderxx / GetCurrentDir.go
Last active January 8, 2022 08:17
GetCurrentDir
func GetCurrentDir() string {
path, err := filepath.Abs(filepath.Dir(os.Args[0]))
if err != nil {
log.Fatalln("GetCurrentDir Error: ", err)
}
return path
}
@Guaderxx
Guaderxx / createDir.go
Created January 8, 2022 08:31
CreateDir
func CreateDir(path, dirName string) string {
dirPath := filepath.Join(path, dirName)
if _, err := os.Stat(dirPath); os.IsNotExist(err) {
os.Mkdir(dirPath, 0777)
os.Chmod(dirPath, 0777)
}
return dirPath
}
@Guaderxx
Guaderxx / regImg.go
Created January 8, 2022 08:38
reg demo
func getUrls(b []byte) []string {
text := `<figure><img src="/file/fe6c70eb7d91b89ed9082.jpg"><figcaption></figcaption></figure>
<figure><img src="/file/fa176712a283f7c3d9ed1.jpg"><figcaption></figcaption></figure>
<figure><img src="/file/199530a4defd3427eb8df.jpg"><figcaption></figcaption></figure>
<figure><img src="/file/3a0bc14da38f4f3022662.jpg"><figcaption></figcaption></figure>
<figure><imgsrc="/file/51b0eb8b8893a56c0d7a8.jpg"><figcaption></figcaption></figure>
<figure><img src="/file/75b0d40cafc8cf212bbb6.jpg"><figcaption></figcaption></figure>
<figure><img src="/file/b9e628bfa1aada10ac554.jpg"><figcaption></figcaption></figure>`
r := regexp.MustCompile(`/file/[a-z0-9]*.jpg`)
@Guaderxx
Guaderxx / ss.go
Created November 23, 2022 05:04
sort index for unsorted array
arr := []int{8,4,2,5,1}
idx := make([]int, len(arr))
for i := range idx {
idx[i] = i
}
sort.Slice(ids, func(i, j int) bool {
return arr[ids[i]] < arr[ids[j]]
})
@Guaderxx
Guaderxx / ffmpeg.md
Created January 16, 2023 16:38 — forked from liangfu/ffmpeg.md
using ffmpeg to extract audio from video files

ffmpeg

Converting Audio into Different Formats / Sample Rates

Minimal example: transcode from MP3 to WMA:
ffmpeg -i input.mp3 output.wma

You can get the list of supported formats with:
ffmpeg -formats

Convert WAV to MP3, mix down to mono (use 1 audio channel), set bit rate to 64 kbps and sample rate to 22050 Hz:

@Guaderxx
Guaderxx / sse.go
Created May 29, 2023 08:44
go_sse
package main
import (
"fmt"
"log"
"net/http"
"time"
)
// server
@Guaderxx
Guaderxx / main.go
Created September 20, 2023 09:46
Memory System Performance
package main
func CopyIJ(src [2048][2048]int, dst [2048][2048]int) {
for i := 0; i < 2048; i++ {
for j := 0; j < 2048; j++ {
dst[i][j] = src[i][j]
}
}
}
@Guaderxx
Guaderxx / channel_1.go
Created December 8, 2023 04:52
Alternate output between numbers and letters
package main
import (
"fmt"
"sync"
)
var wg sync.WaitGroup
func workerNumber(ok <-chan byte, next chan<- int) {
@Guaderxx
Guaderxx / web_unicode.go
Created December 8, 2023 09:21
web unicode
package main
import (
"log"
"github.com/gin-gonic/gin"
)
func main() {
r := gin.Default()
@Guaderxx
Guaderxx / trim.go
Created December 8, 2023 09:27
strings.Trim example
package main
import (
"fmt"
"strings"
)
func TrimBrackets(str string) string {
return strings.Trim(str, "()[]{}")
}