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
# apt-get update && apt-get install -y curl host dnsutils nano netcat | |
apiVersion: v1 | |
kind: Pod | |
metadata: | |
name: toolbox-pod | |
namespace: client | |
spec: | |
restartPolicy: Always | |
containers: | |
- name: toolbox |
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
func main() { | |
for { | |
ticker := time.NewTicker(1 * time.Second) | |
// do something with the ticker | |
_ = <-ticker.C | |
// stop the ticker to release associated resources | |
ticker.Stop() | |
} | |
} |
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
func main() { | |
for { | |
ticker := time.NewTicker(1 * time.Second) | |
// do something with the ticker | |
_ = <-ticker.C | |
} | |
} |
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
func processManyFiles(files []string) error { | |
for _, file := range files { | |
err := process(file) | |
if err != nil { | |
return err | |
} | |
} | |
return nil | |
} |
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
func processManyFiles(files []string) error { | |
for _, file := range files { | |
f, err := os.Open(file) | |
if err != nil { | |
return err | |
} | |
defer f.Close() | |
process(f) | |
} |
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
func runJobs(cancel <-chan struct{}) { | |
for { | |
go func() { | |
// create a 1Gb slice | |
bigSlice := make([]byte, 1_000_000_000) | |
// do some work with the data | |
_ = bigSlice | |
// wait until a cancellation signal is received |
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
func readFileDetails(name string) []byte{ | |
data, err := os.ReadFile(name) | |
if err != nil { | |
return err | |
} | |
return data[5:10] | |
} | |
// not holding reference to underlying memory anymore |
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
var cache = map[int]int{} | |
func main() { | |
for i:=0; ; i++ { | |
// max items cache can hold is 1_000_000 | |
if len(cache) >= 1_000_000 { | |
delete(cache, i-len(cache)) | |
} | |
cache[i] = i |
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
var cache = map[int]int{} | |
func main() { | |
// keep allocating memory indifinitely | |
for i:=0; ; i++ { | |
cache[i] = i | |
} | |
} |
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" | |
"io" | |
"log" | |
"net/http" | |
"sync/atomic" | |
"time" | |
) |
NewerOlder