Skip to content

Instantly share code, notes, and snippets.

@hosszukalman
hosszukalman / regex_delete.sh
Created September 17, 2019 07:58
Delete files based on regex
#!/bin/bash
find . -type f -regex '.*cloudagents.*romanian.html' -delete
@hosszukalman
hosszukalman / regex_replace_content.sh
Created September 17, 2019 08:00
Replace files content based on regex
#!/bin/bash
find . -type f -regex '.*-romanian.html' -exec sed -i '' -e 's/language: en/language: ro/g' {} \;
find . -type f -regex '.*-romanian.html' -exec sed -i '' -e 's/-english/-romanian/g' {} \;
@hosszukalman
hosszukalman / send_events.sh
Created October 3, 2019 06:48
Randomised curl requests in bash.
#!/bin/bash
# The url to post.
url="http://example.com"
# Token for your user.
bearer=""
start_event_body() {
cat <<EOF
{
@hosszukalman
hosszukalman / last_day_of_month.go
Created October 24, 2019 16:36
Get the last day of the actual month in Golang
package main
import (
"fmt"
"time"
)
func main() {
now := time.Now()
@hosszukalman
hosszukalman / field_level_access_read.go
Created February 14, 2020 11:18
A POC for permission based field reading in Golang
package main
import (
"fmt"
"reflect"
)
type User struct {
Permissions []string
}
@hosszukalman
hosszukalman / field_level_access_write.go
Created February 14, 2020 11:19
A POC for permission based field writing in Golang
package main
import (
"encoding/json"
"fmt"
"reflect"
)
type User struct {
Permissions []string
@hosszukalman
hosszukalman / waitgroup.go
Created April 16, 2020 15:01
An example how to use waitgroup in go.
package main
import (
"fmt"
"sync"
)
type Foo struct {
ID int
}
@hosszukalman
hosszukalman / output.txt
Last active April 23, 2020 07:56
Sum() implementations with concurency
09:55 $ go run speedupfor.go
Using sum function: 64416925
39.187µs
Using sumWG function: 64416925
3.486436ms
Using sumChAndWG function: 64416925
33.303102ms
Using sumAtomic function: 64416925
2.848421ms
Using sumSelect function: 64416925
@hosszukalman
hosszukalman / connection_limits.go
Created April 28, 2020 05:02
Default settings for SQL connections in golang.
// https://golang.org/pkg/database/sql/#DB.SetMaxOpenConns
// Go's default setting is "unlimited" for SetMaxOpenConns() but PG's setting is 100.
// If you don't set a limit, go won't handle it in the application layer and never wait to open a new connection
// so it's possible to throw a "max connections" error. That's why you should set the limits, this can be a starting point
// for small and medium web applictions.
db.SetMaxOpenConns(25)
db.SetMaxIdleConns(25)
db.SetConnMaxLifetime(5*time.Minute)
@hosszukalman
hosszukalman / sliceFillWithConcurency.go
Last active May 6, 2020 16:49
Slice fill with go's concurency based on the number of CPUs.
package main
import (
"fmt"
"sync"
)
func makeResult(i int) string {
return fmt.Sprintf("this is %v", i)
}