Showing posts with the label Programming

Golang Append

While working on some code base, I found out a weird quirk of append built-in function in Golang.

There was a string slice defined and after some operations, the function was returning two things, a string and a string slice.
... s := []string{"a", "b", "c", "d"} ... return s[1], append(s[:1], s[1+1:]...) The output is supposed to be "b" and "a", "c", "d" but what I got was "c" and "a", "c", "d". At first I thought I have discovered a bug but after reading the documentation it became clear that it is intentional. Turns out it has to do with implementation of Slice described in this blog. So, append modifies the underlying array and since arguments are evaluated from right to left, append is executed first which modified the underlying array to become "a", "c", "d" and then s[1] returns the 1st element of the modified array "c"…
I finally bought the Interpreter Book on Kindle store.


This project is a very simple webapp inspired by Google's internal “go” system. First time I came to know about this was from this Gitlab thread. Also from the same thread I came to know about an open-source implementation of it at kellegous/go.

I have been working with Golang extensively at work and otherwise for the past year but this is my first web application in Go. The application is analogous to a URL shortner with the different that you get to choose the slug. It implements the functionality of adding and deleting as well as listing all links. I also semi-implemented authentication where it assumes an external system (middleware) to do it and set a specific HTTP header. I am using Cloudflare Access for implementing this in my current setup.

I used Mux router to build the endpoints with two middlewares for logging and authentication. For logging, I used a leveled logging library by Netflix engineer called zerolog. I used Go implementation of LevelDB which is an embedded …

Interpreter Book and Compiler Book

Someone at work shared the link of Interpreter Book. It looks interesting and I want to read it. The book is about writing an interpreter for Monkey language in Go and learning through the process. The author has also written the Compiler Book. The books are available as both eBook and physical copy.

Resize Problem

As I mentioned in my Facebook post, this problem deserves a blog post of its own, so here it is. Note: This post will not help you in anyway to solve the Resize Problem. It is just a summary of my experience with this problem. So, It all started after I finished the previous problem, that is, Whodunit. So, I quickly went to check the docs for next problem, that is, Resize. There was some distribution code, so I quickly downloaded it with Wget on both my Local Machine and CS50 IDE by Cloud9. Background of it was just to read the docs of previous problem and understand it, which I already did. BTW, those docs where about how a Bitmap file is stored, its Headers, and RGB triples. Specifications were to resize the image with a factor of “n”. I thought, that’s easy to do. And then a bunch of bullet points for error codes for specific errors. Then came the 11 minutes long Walkthrough, as always by Zamyla Chan. A very good one, in which she quite accurately explained how to break down the pr…