Skip to content

Instantly share code, notes, and snippets.

@anyu
anyu / tzdatetime-to-unix1.txt
Last active July 24, 2023 18:04
convert-date-time-to-unix-with-timezone
package main
import (
"fmt"
"time"
)
func main() {
inputDate := "2023-03-10"
inputTime := "00:00:00"
package main
import (
"fmt"
"io"
"net"
)
// Test with TCP clients:
// $ echo "heyo" | nc localhost 9000
@anyu
anyu / file_io.go
Created September 9, 2021 15:13
Basic file IO
package main
import (
"bufio"
"fmt"
"log"
"os"
)
func main() {
// Simplest mutex example
package main
import (
"fmt"
"sync"
"time"
)
// Go1.16+'s signal.NotifyContext to concisely handle graceful shutdowns on OS interrupts.
// Simple example from original submitter: https://henvic.dev/posts/signal-notify-context/
func main() {
// Pass a context with a timeout to tell a blocking function that it
// should abandon its work after the timeout elapses.
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt)
defer stop()
select { // blocks until
// Simple Go implementation of AES-GCM-256 encryption/decryption, with explanations
// https://play.golang.org/p/sQABEg5fR1T
package main
import (
"crypto/aes"
"crypto/cipher"
"crypto/rand"
"fmt"
@anyu
anyu / curl_cheatsheet.md
Last active July 7, 2021 19:30
curl_cheatsheet

cURL cheatsheet

Core flags

Flag Description
-H, --header 'name: value' Send request headers
-d, --data Send request data
-X, --request The request method. -X POST is implied if -d is used.
-b, --cookie 'SOME-COOKIE=val1;OTHER-COOKIE=val2' Send request cookies