Skip to content

Instantly share code, notes, and snippets.

View avary's full-sized avatar

Abdulhafiz KAŞGARLI avary

View GitHub Profile
@avary
avary / CustomResponseWriter.go
Created January 9, 2024 05:51 — forked from prakashpandey/CustomResponseWriter.go
Implement custom http.ResponseWriter in golang
package main
import (
"fmt"
"net/http"
)
type CustomResponseWriter struct {
body []byte
statusCode int
@avary
avary / benchmarks_test.go
Created January 9, 2024 06:08 — forked from alaindet/benchmarks_test.go
Go slice mapping concurrently
package main
import "testing"
func BenchmarkConcMap100(b *testing.B) {
b.StopTimer()
input := createRange(100)
output := make([]int, 0, len(input))
b.StartTimer()
@avary
avary / example.go
Created January 25, 2024 09:11 — forked from nd2408/example.go
fsnotify wrapper
logger := slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{
AddSource: false,
Level: slog.LevelDebug,
}))
slog.SetDefault(logger)
watcher, err := watcher.New(logger)
defer watcher.Shutdown()
err = watcher.Watch("/home/user", func(e watcher.Event) error {
@avary
avary / folder_structure.md
Created February 12, 2024 06:17 — forked from ayoubzulfiqar/folder_structure.md
The Folder Structure for Every Golang Project

Go - The Ultimate Folder Structure

Organizing your Go (Golang) project's folder structure can help improve code readability, maintainability, and scalability. While there is no one-size-fits-all structure, here's a common folder structure for a Go project:

project-root/
    ├── cmd/
    │   ├── your-app-name/
    │   │   ├── main.go         # Application entry point
    │   │   └── ...             # Other application-specific files
@avary
avary / update-golang.md
Created March 1, 2024 06:23 — forked from nikhita/update-golang.md
How to update the Go version

How to update the Go version

System: Debian/Ubuntu/Fedora. Might work for others as well.

1. Uninstall the exisiting version

As mentioned here, to update a go version you will first need to uninstall the original version.

To uninstall, delete the /usr/local/go directory by:

@avary
avary / main.go
Created March 12, 2024 08:37 — forked from mcheviron/main.go
Golang array map, concurrency problem
package main
import (
"fmt"
"runtime"
"sync"
"time"
)
func Map[T1, T2 any](arr []T1, f func(item T1, index int) T2) []T2 {
@avary
avary / pagination.js
Created March 12, 2024 08:44 — forked from arturo-source/pagination.js
Simple pagination JS script. Paginator class is 100 lines of JavaScript code to paste into your project and easily handle an array of elements.
class Paginator {
constructor({
elements,
cellsPerRow = 5,
rowsPerPage = 4,
renderFunc,
prevBtn,
nextBtn,
firstBtn,
lastBtn,
@avary
avary / main.go
Created April 2, 2024 09:33 — forked from buroz/main.go
Golang SOAP Request Example
package main
import (
"bytes"
"crypto/tls"
"encoding/xml"
"fmt"
"io/ioutil"
"net/http"
"strings"
@avary
avary / android-backup-apk-and-datas.md
Created April 12, 2024 23:28 — forked from AnatomicJC/android-backup-apk-and-datas.md
Backup android app, data included, no root needed, with adb

Backup android app, data included, no root needed, with adb

Note: This gist may be outdated, thanks to all contributors in comments.

adb is the Android CLI tool with which you can interact with your android device, from your PC

You must enable developer mode (tap 7 times on the build version in parameters) and install adb on your PC.

Don't hesitate to read comments, there is useful tips, thanks guys for this !

@avary
avary / network-tweak.md
Created September 26, 2024 17:36 — forked from mustafaturan/network-tweak.md
Linux Network Tweak for 2 million web socket connections

Sample config for 2 million web socket connection

    sysctl -w fs.file-max=12000500
    sysctl -w fs.nr_open=20000500
    # Set the maximum number of open file descriptors
    ulimit -n 20000000

    # Set the memory size for TCP with minimum, default and maximum thresholds 
 sysctl -w net.ipv4.tcp_mem='10000000 10000000 10000000'