Using Pkl in Go

Pkl is a config managment language developed by Apple. It is a simple language to manage configuration files. It has plugin support for popular editors and support for golang. Sample project Let’s start with a simple go project. go mod init pkl-sample touch main.go package main import ( "fmt" ) func main() { fmt.Println("Hello, World!") } Install pkl First, let’s install pkl using brew. brew install pkl Then, Let’s install pkl-go library in our project. ...

Swagger Docs in Go

Golang is a very good language to create web api servers. I like gofiber framework for creating web api servers. In this article, we will see how to use Swagger in Go especially with gofiber framework. Install swaggo/swag go install github.com/swaggo/swag/cmd/swag@latest Create a new project go mod init github.com/username/projectname Setup Gofiber and Swagger In the code below, we have created a simple API using gofiber framework. The annotations are used to generate the swagger documentation. ...

Elixir Overview

Elixir leverages the Erlang VM, known for running low-latency, distributed and fault-tolerant systems, while also being successfully used in web development and the embedded software domain. It’s functional paradigm and immutable data structures make it a great choice for building scalable and maintainable applications. Few things I like about Elixir are The syntax is very clean and easy to read. The built-in support for concurrency and fault-tolerance. The ability to write highly concurrent and distributed systems with ease. Few things I dislike about Elixir are ...

Running AI Coder Locally

AI Coding tools like copilot, cody etc.. are becoming very relevant and helpful. But, the problem is that they are not available offline. This became a problem when I wanted to travel and had no internet access. So, I remembered about ollama and was looking for a way to use it for my local development. Ollama Ollama is a tool that allows us to run LLMs locally. You can get it simply by: ...

Go has less features, so I'm more productive

Golang is well known for the simplicity and performance it offers. It follows a procedural programming paradigm and has a very minimalistic syntax. Sometimes, it’s too verbose compared to some enterprise languages like Java, C# and Python. But, it’s the same reason why I’m more productive with Go. Limited but essential features Go allows us to achieve something in one or only limited amount of ways. This itself is a huge productivity booster as there will be limited choices of patterns to choose from, which makes it easier to make decisions. It’s like choosing a flavor of ice cream from a list of 10 flavors vs a list of 100 flavors. It’s easier to choose from 10 flavors than 100. ...

SSH Usage

SSH is an encrypted protocol used to connect between two systems. It’s widely used to gain access to remote server and run shell commands. It is also a common thing we use with VCS like github, gitlab etc. SSH Key Generation Creating ssh key is pretty simple, the CLI generates a public and private key pair. The public key is shared with the server and the private key is kept secret. ...

Python - Multithreaded web crawler

I recently had written a web crawler in Python for crawling through a database website. It was a very interesting experience. I needed to crawl through 6850+ pages and extract data from each page, which required some conditions to be met. I used Python for this task, and it was very easy to write a web crawler in Python. First approach I wanted to make sure it works with a single page ( with 50 links ) properly. I needed the following ...

Blazor - Overview

C# ASP.NET offers a way to build highly interactive web UIs using C# and .NET. Blazor helps us to make the app interactive via different modes such as Static Web Apps Interactive Server ( Blazor Server ) WASM (Web Assembly) A Blazor app is based on Components with .razor extention. It is a combination of C# and HTML. Example: // Counter.razor @page "/counter" @rendermode InterativeServer <PageTitle>Counter</PageTitle> <h1>Counter</h1> <p role="status">Current count: @currentCount</p> <button class="btn btn-primary" @onclick="IncrementCount">Click me</button> @code { private int currentCount = 0; private void IncrementCount() { currentCount++; } } // PageTitle.razor <h3>@ChildContent</h3> @code { [Parameter] public RenderFragment ChildContent { get; set; } } In the above example, <PageTitle> is another component. @code block is used to write the C# code. This block will render a counter and a button to increment the counter. ...

Mirrord - Overview

When we have a large project with a kubernetes cluster, it’s sometimes difficult to debug and test certain parts of the application. Mirrord allows us to bind a local port to a remote server. flowchart TB request --> mirrord subgraph Pod mirrord -.-x|intercepted| live_server:3000 end mirrord -->|db connection| db[(Database db:5000)] mirrord -->|forwarded| local_machiene(local:3000) local_machiene -.-|connects db:5000 via mirrord| db You can run a local server for example on port 3000 and bind it to a remote server. And any request coming to live_server:3000 will be intercepted by mirrord and forwarded to your local machine. We can debug the incoming request, connect to other services etc… Like our local machiene is a part of the kubernetes cluster. ...

Client - Server Patterns

Client-Server is a common architecture pattern in software systems. It is a distributed system architecture that partitions tasks or workloads between the providers of a resource or service, called servers, and service requesters, called clients. There are different patterns in which client and server can communicate with each other. Request-Response The client sends a request to the server and waits for a response. The server processes the request and sends a response back to the client. It is a synchronous communication pattern. It is used in HTTP, RPC, and other synchronous communication protocols. sequenceDiagram participant Client participant Server Client->>Server: Request Server->>Client: Response Short Polling The client sends a request to the server at regular intervals. The server responds with new data if available. It is a synchronous communication pattern with a short interval. sequenceDiagram participant Client participant Server Client->>Server: Request Server->>Client: Response ( no data ) Note left of Client: Wait for some time Client->>Server: Request Server->>Client: Response ( data ready ) Long Polling The client sends a request to the server and waits for a response. The server holds the request until new data is available or a timeout occurs. It is a synchronous communication pattern with a long timeout. sequenceDiagram participant Client participant Server Client->>+Server: Request Note right of Server: Wait Until data is ready Server->>-Client: Response ( delayed ) WebSockets The client and server establish a persistent, two way communication channel. It is used for real-time communication and updates. It is particularly useful for chat applications, online gaming, and financial trading platforms. sequenceDiagram participant Client participant Server Client->>Server: Establish Connection Server->>Client: Establish Connection Client->>Server: Send Message Server->>Client: Send Message Server-Sent Events The server sends updates to the client over a single HTTP connection. Client sends a request and the server uses the response to send updates. Server will not end the response, and will keep sending updates over the established connection. sequenceDiagram participant Client participant Server Client->>Server: Establish Connection Server->>Client: Send Update Server->>Client: Send Update Server->>Client: Send Update Publish-Subscribe The client subscribes to a topic or event on the server. The server publishes messages to the subscribed clients when an event occurs. It’s similar to WebSockets, but the server can send messages to multiple clients and the messages are partitioned by topics. It is an asynchronous communication pattern. sequenceDiagram participant Client participant Server Client->>Server: Subscribe ( establish a connection ) Server->>Client: Publish ( through the connection ) Request-Callback The client sends a request to the server and provides a callback function or URL. The server processes the request and calls the callback function or URL on the client. It is an asynchronous communication pattern. sequenceDiagram participant Client participant Server Client->>Server: Request ( with callback info ) Server->>Client: Invoke the Callback