Skip to content

Instantly share code, notes, and snippets.

package main
import (
"context"
"fmt"
"time"
)
func gen(ctx context.Context) <-chan int {
out := make(chan int)
package main
import (
"fmt"
"math/rand/v2"
"time"
)
type Ch struct {
ch chan int
@dannyvelas
dannyvelas / unpushed-git-branches.fish
Created January 12, 2025 00:25
This script will iterate through a directory of arbitrarily-nested github repos and for each one, print a detailed warning message when it finds branches that are updated on local but not updated on remote
#!/usr/bin/env fish
for match in (find /Users/dannyvelasquez/RemoteGit/MyGithub/ -type d -name ".git")
cd "$match/.."
echo $match
# Get all local branches
for branch in (git branch --format="%(refname:short)")
# Checkout the branch
git checkout -q $branch
@dannyvelas
dannyvelas / runes.go
Created June 15, 2024 21:14
playing with UTF-8 in go and seeing how it is self-synchronizing. (e.g. https://en.wikipedia.org/wiki/Self-synchronizing_code)
package main
import (
"fmt"
)
func main() {
const placeOfInterest = `⌘`
fmt.Println(placeOfInterest)
fmt.Println(len(placeOfInterest))
@dannyvelas
dannyvelas / streams.go
Created May 1, 2024 03:18
Code to show that channels aren't the only way to pass values concurrently from one go-routine to another. io.Writers/io.Readers can be used for this purpose as well
package main
import (
"bufio"
"fmt"
"io"
"os"
"sync"
)
@dannyvelas
dannyvelas / servemux.go
Created February 23, 2024 04:28
playing around with go 1.22
package main
import (
"encoding/json"
"fmt"
"github.com/rs/cors"
"net/http"
"net/url"
)
@dannyvelas
dannyvelas / valreceiver.go
Created April 7, 2023 01:18
Gist to show that it is safe to take the reference of a value receiver and mutate the value it points to. This will not mutate the object that dispatched the receiver.
package main
import "fmt"
type MyStruct struct {
field string
}
func (s MyStruct) setFieldValReceiver(newField string) MyStruct {
ptrToS := &s
@dannyvelas
dannyvelas / receivers.go
Last active April 8, 2023 02:27
Some examples of the behavior of pointer receivers vs value receivers
package main
import "fmt"
type A struct {
myMap map[string]string
otherVar string
}
func (a A) MutateMapByVal(k, v string) {
@dannyvelas
dannyvelas / mutateprops.go
Created March 22, 2023 16:50
This gist shows examples of when struct properties inside of slices will and wont be changed. This depends on whether the struct in question is copied by value or reference.
// You can edit this code!
// Click here and start typing.
package main
import "fmt"
type S struct {
Name string
}
@dannyvelas
dannyvelas / generics.go
Created April 1, 2022 21:08
Generics in Go
package main
import (
"fmt"
)
// Define a type constraint
type StringOrUint interface {
string | uint
}