- Definition: A combination of values, variables, operators, and function calls that evaluates to a single value.
- Examples:
2 + 2
(evaluates to4
)x * y
(evaluates to the product ofx
andy
)time.Second * 10
(evaluates to atime.Duration
value of 10 seconds)
- Usage: Expressions are used to compute values. They can appear within statements, assignments, or function arguments.
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
brew install imagemagick | |
magick example.png -quality 70 optimised.jpg |
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
// https://play.golang.com/p/GoyqwZ5jW_L | |
// https://pkg.go.dev/golang.org/x/sync/singleflight | |
// https://victoriametrics.com/blog/go-singleflight/index.html | |
package main | |
import ( | |
"fmt" | |
"math/rand" | |
"sync" |
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 ( | |
"errors" | |
"fmt" | |
"io" | |
) | |
func main() { | |
err := doSomething() |
This article is about a few quick thumb rules I use when writing shell scripts that I’ve come to appreciate over the years. Very opinionated.
- Use
bash
. Usingzsh
orfish
or any other, will make it hard for others to understand / collaborate. Among all shells,bash
strikes a good balance between portability and DX.
If you've not used YAML before you might be wondering what &<name>
means.
What this will do is create an 'anchor'.
Anchors allow you to inject the associated block of data any where else within your YAML configuration file.
This allows you to avoid duplicating those particular settings.
The way to do that injection is to 'dereference' the anchor with an asterisk.
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
// https://play.golang.com/p/TbawROSRv8X | |
package main | |
import ( | |
"fmt" | |
"golang.org/x/net/idna" | |
) |
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
// zones == complete list of dns zones | |
// denyList == list of zones to remove | |
for _, deniedZone := range denyList { | |
for i := 0; i < len(zones); i++ { | |
if zones[i] == deniedZone { | |
zones = append(zones[:i], zones[i+1:]...) | |
i-- // Adjust index to stay at the correct position after removal | |
} | |
} | |
} |
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
// Probably should just use https://github.com/sergi/go-diff | |
// printDiff prints the differences between two files line by line. | |
func printDiff(file1, file2 string) error { | |
f1, err := os.Open(file1) | |
if err != nil { | |
return fmt.Errorf("failed to open file1: %w", err) | |
} | |
defer f1.Close() |
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
// https://play.golang.com/p/tfop7CgoGF5 | |
// https://goplay.tools/snippet/aZatTtNaElZ | |
package main | |
import ( | |
"context" | |
"fmt" | |
"log/slog" | |
"os" |