This file contains hidden or 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
{"lastUpload":"2021-07-07T07:01:56.235Z","extensionVersion":"v3.4.3"} |
This file contains hidden or 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
import { Options, pinoHttp } from 'pino-http'; | |
import { formatError } from '@elastic/ecs-helpers'; | |
// Taken as it is from @elastic/ecs-pino-format | |
function bindings(bindingsObject: Record<string, unknown>) { | |
const { pid, hostname, ...ecsBindings } = bindingsObject; | |
if (pid !== undefined) { | |
ecsBindings.process = { pid }; | |
} |
This file contains hidden or 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" | |
) |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 | |
} | |
} |
OlderNewer