Vue Composition API - Nuxtjs

I had been using Nuxtjs 3 for sometime, and I’ve started to like it more. I started using Nuxtjs 3 ever since Nextjs got messier with Server first move. After working with Nuxt 3, I also found myself having fun with Nuxt UI 3 as well. The simplicity and structured approach of Nuxt and Nuxt UI are pretty good. I like the composition api of Vue3, which is a very good feature. ...

Docker - Docker Swarm

I had been using docker compose for a while to deploy, I started noticing there is a slight downtime while deploying docker compose. Moreover, If there is some error while deploying it could be disruptive. I finally started using docker swarm, It’s not very different from docker compose, It is good for rolling updates. Running docker in swarm mode is just a single command docker swarm init which will spin up the manager node. And we can add more nodes to the swarm later on. ...

Nginx and Certbot settings

Certbot is a very useful tool to setup auto renewal of certificates. Here is how I’m setting up certbot and nginx quick and easy. Initial Setup Here is the docker-compose.yaml file with nginx and certbot services: nginx: image: "nginx:alpine" container_name: app_nginx ports: - 80:80 - 443:443 volumes: - ./platform/config/nginx/nginx.conf:/etc/nginx/nginx.conf:ro - ./platform/config/certbot/www:/var/www/certbot:ro - ./platform/config/certbot/conf:/etc/letsencrypt:ro restart: always certbot: image: certbot/certbot container_name: app_certbot volumes: - ./platform/config/certbot/www:/var/www/certbot:rw - ./platform/config/certbot/conf:/etc/letsencrypt:rw Every file that’s generated by certbot will be stored in ./platform/config/certbot ...

Data Loading for Machine Learning

When we load data to train a neural network model, We usually split data into the training data and testing data. Then the training data is further split into batches to train the model. This is done to reduce the memory usage and speed up the training process. Let’s see how to load data into a neural network model using PyTorch. Dataset pytorch provides a Dataset class to load data into a neural network model. We can create a custom dataset by inheriting the Dataset class and implementing the __len__ and __getitem__ methods. ...

Neural Network Model Dissection

Data Flow Inside a Neural Network Model Inside a Neural Network Model, when we pass in a value it should some other value. Let’s inspect an example model import torch import torch.nn as nn class NeuralNetwork(nn.Module): def __init__(self): super(NeuralNetwork, self).__init__() self.input_layer = nn.Linear(1, 1) def forward(self, x): x = self.input_layer(x) return x Here, we have a simple neural network model with a single input and output layer. The input layer has a single node and the output layer has a single node. ...

Neural Networks

AI had been really influencing our daily life, It’s a powerful tool to help us with a lot of tasks. As of 2024 There are prototypes of self driving cars to humanoid robots that does chores. Neural Network is the core of the whole Machiene Learning and AI all around us. Let’s break down Neural Networks with examples in pytorch. What is a Neural Network? Neural Network is a programmable network of neurons called nodes with layers to compute and return few outputs. It’s a model that can be trained to recognize patterns in data. ...

Why Go error handling is my favorite

Go has very simple and efficient error handling mechanism. Error as value is very powerful concept and some people find it annoying. I think errors should be annoying so that we don’t ignore them. Most notable aspects of go’s error handling I found myself are: It is just straight forward and simple, I didn’t have to do anything clever to tweak it and make it more erganomic. I got used to it quickly after a bit of skepticism. I believe It’s common for us to force a familiar paradigm when we try new languages and when it’s different, we tend to question it. I had to think more about error handling and it made me write more robust code. I always write prototypes in other languges by ignoring errors and it can slip to production, even if I ignore errors in go, there is an explicit _ which reminds me that I’m ignoring an error. Error as value In go, a typical function defintion can give away if it returns an error or not. If a function returns an error, it’s usually the last return value. This makes it very easy to identify if a function can return an error or not. ...

Zig Overview

Zig is a systems programming language that emphasizes simplicity, performance, and safety. It has gained attention for its minimalistic approach and powerful features. Zig is particularly well-suited for developing low-level systems and applications where control over hardware and performance are critical. Features of Zig No hidden control flow: Zig has no hidden control flow, which means that the behavior of the program is predictable and easy to understand. This makes debugging and optimization easier. Error handling: Zig has a unique error handling mechanism that is designed to be simple, efficient, and safe. It uses compile-time checks to ensure that errors are handled correctly. Compile-time execution: Zig supports compile-time execution, which allows developers to run code at compile time to generate data or perform computations. This feature can be used to generate code, perform optimizations, or validate data. Memory Management: Zig provides fine-grained control over memory management, allowing developers to manage memory allocation and deallocation manually. This can help reduce memory overhead and improve performance. Interop with C: Zig has excellent interoperability with C, allowing developers to call C functions and use C libraries directly. This makes it easy to integrate Zig code with existing C codebases. Variables In Zig, variables are declared using the var keyword followed by the variable name and type. Zig supports type inference, allowing developers to omit the type when it can be inferred from the value. ...

Implementing Redis in Golang

Redis is well known for a in-memory data store which is widely used as cache, database and message broker. In this article, we will implement a simple Redis client in Golang. Let’s look at the basic parts like, Listening to a port Accepting connections Reading the commands Parsing the commands Handling the commands Listening to a port We can use the net package in Golang to listen to a port. We can use the net.Listen function to listen to a port. ...

Setting up Observability in your app

Observability is a very important topic to consider in any application just like Tests. It helps understand a lot about how our system works, and measure a lot of aspects to make data-driven decisions. It can mostly be a go-to guide to what is happenning in your system, and how to improve it. Parts of Observability I’d like to categorize Observability into 3 parts: Logging: Logging is the logs we generate from our application usually in levels like info, debug, error, warn, etc. These logs are custom messages that we can use to debug our application or monitor each event that happens in our application. Metrics: Metrics or data points are the data we collect from our application to monitor the performance of our application. These metrics can be anything like the number of requests, response time, etc. Tracing: Tracing is the process of monitoring the flow of a request through our application. It helps us understand how a request is processed in our application. Setting up Observability For logging ...