Skip to content

Instantly share code, notes, and snippets.

@gerep
gerep / compact.go
Last active Jun 29, 2021
Compacting json data removing unused spaces: https://golang.org/pkg/encoding/json/#Compact
View compact.go
package main
import (
"bytes"
"encoding/json"
"fmt"
)
func main() {
data := `{ "spacedValue": "spaced value" }`
View coisa.go
package main
import (
"fmt"
"time"
)
type coisa struct {
nome string
cComecar chan bool
View context.go
package main
import (
"context"
"fmt"
"net/http"
"time"
)
func main() {
View tonto.go
package main
import (
"fmt"
"log"
"math/rand"
"net/http"
"time"
)
@gerep
gerep / sed.sh
Created May 9, 2018
Using `sed` to replace string inside a file
View sed.sh
sed -i '/old text/ s//new text/g' gigantic_file.txt
View random.go
package main
import (
"fmt"
"math/rand"
"reflect"
"time"
)
const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
View load.go
for x := 0; x < 1000; x++ {
wg.Add(1)
go func() {
x := client.EvalSha(redisSha, []string{}, j)
if x.Err() == redis.Nil {
fmt.Println("No return")
} else if err != nil {
panic(err)
} else {
r, _ := x.Result()
View cancel2.go
package main
import (
"context"
"log"
"sync"
"time"
)
var wg sync.WaitGroup
View equal-halfs.go
// Split the integer number into two (n is always even in size)
// Sum each half, if they are equal, return true
package main
import (
"fmt"
"strconv"
)
@gerep
gerep / main.go
Created Nov 24, 2017 — forked from hnakamur/main.go
A go example to stop a worker goroutine when Ctrl-C is pressed (MIT License)
View main.go
package main
import (
"fmt"
"os"
"os/signal"
"time"
"golang.org/x/net/context"
)