Welcome to my personal blog

  • This blog will be about every technology related topic that will cross my mind

Back to blogging

Hugo Blogging I’ve tried different blog platforms over the years: ghost, wordpress. Hugo is very popular nowadays, so I wanted to try it out. Moreover, I came across that theme that looked cool: I don’t have a specififc goal in mind for that blog, it’s a just a cool way for me to look back and see what I’ve been doing. AWS Amplify I also wanted to try out AWS Amplify....

March 31, 2021 · 1 min · Nolan

Using Variadic in Go

Nothing new Variadic arguments are present in many many languages. In golang the syntax is like so: package main import "fmt" func addNubers(nums int { s := 0 for _, n := range nums { s += n } return s } func main() { res := addNubers(1,2,3) } In python: def func(a, *t): for e in t: print(e) func(1,2,3,3,4) Usage in go In go variadic functions are used to make configuration easily extendable, without changing existing interface....

October 3, 2021 · 1 min · Nolan

Go testing

Testing in golang Simple test in go package main import "testing" func add(a, b int) int { return a + b } func TestAddingNumber(t *testing.T) { res := add(1, 7) if res != 8 { t.Errorf("Sum is incorrect, got: %d, expected: %d", res, 8) } } Run tests: go test -v ./... Avoiding repeating tests Instead of duplicating code for similar tests, there is a different way to test. package main import ( "strings" "testing" ) func rep(s string) string { return strings....

October 2, 2021 · 1 min · Nolan

Golang Encoding/Decoding JSON

Encoding JSON Encoding Decoding is not as straight forward as other languages as it needs to be mapped to a struct. Or a generic map[interface] can be used if you don’t know the type in advance. package main import ( "encoding/json" "fmt" ) type Data struct { Id int `json:"id"` List []string `json:"list"` NotPrint string `json:"-"` } func main(){ d := Data{Id: 123, List: []string{"abc", "b"}, NotPrint: "This won't print"} result, err := json....

September 25, 2021 · 1 min · Nolan

Go templates

Templating with Sprig Templating can be useful, for instance it is heavily used in helm. Below a simple example to get started, sprig is just library on top of golang templating that provides extra functions. package main import ( "os" template "text/template" "" ) var temp = ` start {{ .Title | repeat 2 | indent 2}}{{ .Text }}{{ first .List }}end ` type Values struct { Title string Text string List []int } func main() { t, err := template....

September 24, 2021 · 1 min · Nolan

PostgreSQL in Docker

Running DB from a dump in seconds I will take this free dataset from postgresql website. docker run -d --name my_db \ -v /Users/nolan/Downloads/french-towns-communes-francaises-1.0/french-towns-communes-francaises.sql:/docker-entrypoint-initdb.d/create_table.sql \ -p 54320:5432 -e POSTGRES_PASSWORD=my_password -e POSTGRES_USER=nolan postgres Connect to DB pgcli -h localhost -p54320 -Unolan nolan@localhost:nolan> SELECT count(*) FROM towns where name like 'Mont%'; Result: count 826

September 21, 2021 · 1 min · Nolan

Using multiple versions of the same library

Golang Looking into dependency management in golang and I was quite surprised that it’s possible to import multiple versions of the same library. However it only works for major version that are considered as a different module. Which must be specified when creating the package E.g module multiversion go 1.15 require ( v7.0.0 v8.0.0 ) package main import ( redisv1 "" redisv2 "" ) func main() { redisv1.NewClient(&redisv1.Options{ Addr: "localhost:6379", Password: "", DB: 0, }) redisv2....

September 6, 2021 · 1 min · Nolan

Visual Studio

Get a sharable Git URL of a specific line of code When collaborating it’s useful to share the URL that will point to a specific line. To do that you will need the gitlens extension. Then just do cmd + shift + p it will open up the pallet, and then look for Copy remote URL. Here is an example of the result: Click here More to come …

September 3, 2021 · 1 min · Nolan


Tickers I was looking into timers and I came across tickers. Basically they allow you to trigger an event at a regular time interval. One simple example could be some kind of monitoring. What’s interesting is that it pushes a Ticker to a channel. Here is a basic example: package main import ( "fmt" "os" "sync" "time" ) func checkInBackground(ticker time.Ticker, wg *sync.WaitGroup) { wg.Add(1) for ; true; <-ticker.C { fmt....

August 30, 2021 · 1 min · Nolan

Limit number of concurrent requests  [draft]

Limiting the number of concurrent http requests I was looking to use gorountine in the context of http requests. More specifically, how to limit the number of concurrent of http call made to a service. Let’s say you are making call to an API that is rate limited.

August 29, 2021 · 1 min · Nolan