Skip to content

Instantly share code, notes, and snippets.

@hosszukalman
hosszukalman / gen.json
Created October 29, 2022 14:13
[POC] Creating a dynamic generator with dynamic options using node's yargs package
{
"requiredArgs": [
"where",
"command"
],
"optionalArgs": [
"mutation-name"
],
"templates": [
{
@hosszukalman
hosszukalman / gen.json
Created October 29, 2022 14:07
[POC] Creating a dynamic generator with dynamic options using node's commander package
{
"requiredArgs": [
"where",
"command"
],
"optionalArgs": [
"mutation-name"
],
"templates": [
{
@hosszukalman
hosszukalman / bash.sh
Created June 15, 2020 12:50
Set up docker to handle more than 31 neworks
#!/bin/bash
vim /etc/docker/daemon.json
service docker restart
docker network create foo
docker network inspect foo | grep Subnet # "Subnet": "10.10.1.0/24"
@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)
}
@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 / 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 / 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 / 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 / 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 / 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()