How I deploy my production stack on VPS

We can deploy applications to VPS / Cloud Instances to avail it in the public internet. When deploying for production we need some standard practices to ensure application is easy to manage. Some of the feature to consider are: Auto TLS Easy image building and deployment Rolling updates Rollback when needed Preparing VPS for deployment Setup a brand new VPS with SSH and Necessary settings example Install Docker on VPS ssh into VPS using ssh vps1.example.com install docker curl -fsSL https://get.docker.com | sudo sh Setting up Docker Context We can use docker context to configure docker client to connect to the VPS. We can create a context using: ...

How I Setup a brand new VPS

VPS or A Cloud Server will come with basic OS setup. Here are some of my basic practices getting started with setting up a VPS for deploying applications. Setting up SSH Keys Create SSH Keys on local machine ssh-keygen -t ecdsa -f ~/.ssh/id_rsa_vps Copy SSH Keys to VPS ssh-copy-id -i ~/.ssh/id_rsa_vps.pub username@ip Add ~/.ssh/config entry for easy access cat ~/.ssh/config Host vps1 HostName ip User username IdentityFile ~/.ssh/id_rsa_vps ServerAliveInterval 240 (Optional) Disable password authentication ...

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. ...