development

Redis Expire Key: How TTL behaves?

An operation that modifies a key’s value resets the TTL. DEL, SET, GETSET and all the *STORE An operation that alters the key’s value leaves TTL untouched. Create a list with TTL = 120 redis> rpush “mylist” “first” (integer) 1 redis> rpush “mylist” “second” (integer) 2 redis> expire “mylist” 120 (integer) 1 Add new elements […]

Read more
development

Liveness vs Readiness Health Checks in Application

The liveness check finds if the application is alive or not. The application defines the logic and the liveness check verifies the expected output. A webserver liveness check could include an HTTP handler that returns a fixed response or checks application dependencies. Sample Liveness check send a pong response in the handler combine health check […]

Read more
development

Why be careful with defer in Golang

When does defer function executes? The standard answer is: defer runs a function before the enclosing function returns. It is a wrong explanation. The defer executes as follows: The enclosing function has processed returned values and stored them in registers All defer functions run in a LIFO order of definition. If the return parameters are […]

Read more
development

How to Fix File is not `gofumpt`-ed (gofumpt) error

gofumpt is a stricter version of gofmt. The lint tool finds more errors and reports. One such error is that File is not gofumpt-ed. The solution to the problem is as follows: Please install gofumpt The easiest solution is to run gofumpt on the troubled files. gofumpt -w <fileame> Written with StackEdit.

Read more
development

Time Complexity of a Memoized Algorithm

The memoization eliminated duplicate calls to a function. A memoized implementation of Fibonacci code is as follows: package complexity import “fmt” var mem map[int]int func fibo(count int) int { if count == 0 || count == 1 { return count } if mem[count] != -1 { return mem[count] } s := fibo(count-1) + fibo(count-2) mem[count] […]

Read more
development

Set and Clear Bits in Golang

Set and Clear Bits in Golang There are bitwise operators in golang for bit manipulation. However, there is an unusual NOT operator. golang uses the ^ operator for NOT. Code NOT of a number a := 101 notOfA := a ^ a // 101 ^ 101 = 010 Setting a bit of a number a […]

Read more
development

git pull, merge and rebase

It is always better to rebase local commits while pulling remote published changes. git merge will create a merge entry in the history, rebase is preferred because it orders your local commit on top of the latest remote commits. To avoid typing –rebase whenever you pull you can config git to use it as default: […]

Read more
development

Summary: How to Write Go Code

Summary: How to Write Go Code The code organization follows repository -> module -> packages. Use go mod init and initialize module root as desired e.g. example.com/user/hello The Go binary goes to the path set in GOBIN All imported modules are stored in GOPATH/pkg/mod subdirectory The command go clean -modcache cleans downloaded packages. Reference https://golang.org/doc/code.html […]

Read more
development

MySQL: Convert Character Set and Collation

The character set and collation changes for a DB have important changes on the storage requirements and query result behavior. The character set for a table can be changed in two ways: a. Using CONVERT TO query b. Using MODIFY <column name> Methods The CONVERT TO method makes sure that each column fits the new […]

Read more