Skip to content

Instantly share code, notes, and snippets.

@mybigman
mybigman / CustomResponseWriter.go
Created November 30, 2024 05:36 — forked from prakashpandey/CustomResponseWriter.go
Implement custom http.ResponseWriter in golang
package main
import (
"fmt"
"net/http"
)
type CustomResponseWriter struct {
body []byte
statusCode int
@mybigman
mybigman / verify_hmac.go
Created October 27, 2024 01:40 — forked from turret-io/verify_hmac.go
Verify HMAC in Go
package main
import (
"crypto/hmac"
"crypto/sha512"
"encoding/base64"
"encoding/json"
"errors"
"fmt"
"net/url"
@mybigman
mybigman / htmx-toast.js
Created July 13, 2024 09:03 — forked from maekoos/htmx-toast.js
Server sent toasts in HTMX
htmx.on("htmx:afterRequest", (e) => {
const toast = e.detail.xhr.getResponseHeader('HX-Toast');
// Can be expanded with HX-Toast-Type or similar to specify success, warning, info, etc
if(toast) {
const el = document.createElement('span');
el.innerText = toast;
el.style.position = 'fixed';
el.style.top = '10px';
// Right aligned:
// el.style.right = '10px';
@mybigman
mybigman / folder_structure.md
Created June 4, 2024 13:37 — 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
@mybigman
mybigman / README.md
Created October 28, 2023 05:30 — forked from sancar/README.md
An upgradable read write lock for go

And upgradable read write lock for go

UpgradableRWMutex is an enhanced version of the standard sync.RWMutex. It has the all methods sync.RWMutex with exact same semantics. It gives more methods to give upgradable-read feature.

The new semantics for upgradable-read are as follows:

  • Multiple goroutines can get read-lock together with a single upgradable-read-lock.
  • Only one goroutine can have a write-lock and no read-lock/upgradable-read-lock can be acquired in this state.
package main
import (
"crypto/aes"
"crypto/cipher"
"crypto/rand"
"crypto/rsa"
"crypto/sha256"
"crypto/x509"
"encoding/pem"
@mybigman
mybigman / paginator.go
Created September 21, 2023 12:35 — forked from alochym01/paginator.go
Create a simple Pagination - golang programming
package main
import (
"database/sql"
"encoding/json"
"flag"
"fmt"
"log"
"net/http"
"os"
@mybigman
mybigman / 0-go-os-arch.md
Created December 9, 2022 09:45 — forked from asukakenji/0-go-os-arch.md
Go (Golang) GOOS and GOARCH

Go (Golang) GOOS and GOARCH

All of the following information is based on go version go1.17.1 darwin/amd64.

GOOS Values

GOOS Out of the Box
aix
android
@mybigman
mybigman / arch-raid1.sh
Created December 6, 2022 07:15 — forked from pvmart/arch-raid1.sh
Install arch linux on btrfs raid1
#!/bin/bash
set -e
set -o pipefail
dd if=/dev/zero of=/dev/sda bs=1024 count=10
dd if=/dev/zero of=/dev/sdb bs=1024 count=10
RAM=$(free -m | awk '/Mem:/{print $2}')