This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"net/http" | |
) | |
type CustomResponseWriter struct { | |
body []byte | |
statusCode int |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"crypto/hmac" | |
"crypto/sha512" | |
"encoding/base64" | |
"encoding/json" | |
"errors" | |
"fmt" | |
"net/url" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
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
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"crypto/aes" | |
"crypto/cipher" | |
"crypto/rand" | |
"crypto/rsa" | |
"crypto/sha256" | |
"crypto/x509" | |
"encoding/pem" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"database/sql" | |
"encoding/json" | |
"flag" | |
"fmt" | |
"log" | |
"net/http" | |
"os" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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}') |
NewerOlder