Posts

Showing posts from May, 2025

Managing FastAPI Projects with Poetry: A Step-by-Step Guide

Image
This guide will walk you through how to use Poetry to manage dependencies and structure your project in FastAPI . It includes detailed explanations of Poetry's core concepts and commands to help prevent issues that can arise during team collaboration and deployment. 1. What is Poetry? Poetry is a dependency management and packaging tool for Python. It goes beyond simply installing libraries by allowing you to clearly declare the dependencies your project needs and ensuring that all developers on the project have the same library versions. Clarity in Dependency Management : Explicitly manage your project's basic information and required libraries through the pyproject.toml file. Reproducible Builds : By locking all dependency versions in the poetry.lock file, it fundamentally prevents "it works on my machine" problems. Integrated Development Environment : It automatically creates and manages isolated virtual environments for each project and handles mo...

How Modern Java Improves Exception Handling (Java 21)

Image
In recent Java releases, especially Java 21, exception handling mechanisms have been significantly enhanced to improve both code safety and system reliability . These improvements help developers write more robust, maintainable, and error-resilient applications. 1. switch Statements Now Handle null and Support Pattern Matching In Java versions prior to 21, passing a null value to a switch statement would throw a NullPointerException . Java 21 allows developers to explicitly handle null values inside switch , preventing unexpected crashes. switch (input) { case null -> System.out.println("Input is null."); case "YES" -> System.out.println("Yes!"); default -> System.out.println("Other input."); } Benefits Prevents NullPointerException by design Improves clarity and readability 2. Pattern Matching and when Clauses in switch Java 21 introduces pattern matching for switch , allowing developers to write m...

How to Set an SSH Login Banner on Ubuntu 24.04

This guide walks you through setting up an SSH login banner on Ubuntu 24.04, along with best practices and real-world security tips — including how to prevent accidental logins to production servers, reduce legal exposure, and avoid exposing sensitive OS details. The benefits of SSH Login Banner Legal Notice : Warns unauthorized users and may help with legal defense. Security Deterrent : Reminds users that activity is logged and monitored. Environment Clarity : Helps clearly label dev/staging/prod servers to avoid mistakes. Attack Surface Reduction : Prevents exposing OS/version info (which /etc/issue might leak). Step 1. Create or Edit the Banner File Start by creating or editing the banner file that will be displayed before the SSH login prompt. The standard location is /etc/issue.net . $ sudo vim /etc/issue.net Sample Banner Text ##################################################################### # This system is for the use of authorized users only. ...

How to get rid of ^M from a text file on Linux or Unix

Image
When you transfer text files from Windows to Linux or Unix systems, you often see ' ^M' characters at the end of lines. This happens because Windows and Linux/Unix handle line breaks differently—Windows uses CR+LF ( \r\n ) , while Linux/Unix just uses LF ( \n ) . In this guide, we’ll look at a few simple ways to remove these characters and explain how each method works. $ cat -v HelloWorld.java public class HelloWorld^M {^M public static void main(String[] args) {^M System.out.println("Hello World!");^M }^M }^M Using the dos2unix command The dos2unix command is a simple and widely used method. $ dos2unix filename Using vi/vim editor In Vi/Vim, You can directly search for and remove the ' ^M' character. The command above searches for ' ^M' at the end of each line throughout the entire file and removes it. To input '^M', push Ctrl down and then press v and n consecutively. Vim on Linux: 'Ctrl + v + m' Gvim ...

Spring Boot Actuator, How to Monitor Application Health with actuator-health

Image
Spring Boot Actuator provides a wide range of features to monitor and manage your application when it's deployed in a production environment. These features can be accessed via HTTP endpoints or JMX, and they automatically enable capabilities such as auditing, health checks, and metrics collection in your application. Actuator is essential in cloud-native and microservice architectures, allowing real-time monitoring of application status, metrics, and traffic data. In particular, the /actuator/health endpoint offers a basic mechanism to check if the application is running properly, making it crucial for integration with load balancers, Kubernetes, and other orchestration tools. Spring Boot Actuator Setup 1. Add Actuator Dependency pom.xml (maven) <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> </dependencies...

Managing Shared Libraries in Microservice Architecture Using GCP Artifact Registry

Image
In a microservice architecture, it's common for multiple services to share common functionality or utility classes. To handle this effectively, I manage these shared components as a reusable library (like libs.jar ) that each service can depend on. In this post, I’ll show you how I use GCP Artifact Registry to efficiently manage and distribute a shared library across microservices. Step 1: Enable the Artifact Registry API $ gcloud services enable artifactregistry.googleapis.com --project=[PROJECT_ID] Step 2: Create a Maven Repository in GCP Artifact Registry $ gcloud artifacts repositories create maven-repo \ --repository-format=maven \ --location=us-central1 \ --description="Shared Maven Repo for common libraries" $ gcloud artifacts repositories list --location=us-central1 REPOSITORY FORMAT LOCATION DESCRIPTION maven-repo MAVEN us-central1 Shared Maven repo Step 3: Configure pom.xml for the Shared Library Project In the share...

Mastering GitHub Copilot with IntelliJ

Image
If you're developing Spring Boot applications using IntelliJ and GitHub Copilot (paid plan), this post is your ultimate guide. Learn how to generate boilerplate code, auto-generate tests, refactor suggestions, and much more—all using AI-powered assistance. Supported IDEs IntelliJ IDEA (Community & Ultimate) Visual Studio Code ⚠️ Requires GitHub Copilot Chat plugin installed Summary of GitHub Copilot Usage Feature Description Example 1. Editor Autocomplete Autocomplete suggestions appear after typing comments or method signatures // Create a REST controller → Press Tab 2. Copilot Chat + Slash Commands Use commands like /explain , /doc , /test to analyze, document, or test code /explain → describes what the code does 3. Natural Language Requests Ask questions conversationally without a slash Generate a method that...

Securely Connect to GCP Cloud SQL from Your Local Network Using Cloud SQL Auth Proxy

In the early stages of development on Google Cloud Platform (GCP), I needed to directly connect to the production Cloud SQL (PostgreSQL) instance for debugging and testing. Although Cloud SQL does provide a public IP address, it requires registering the client's IP address for access, so I decided to look for another way. Due to GCP’s strict security policies—such as requiring IAM authentication and often disabling public IP access—direct access can be challenging. That's where the Cloud SQL Auth Proxy comes in. It creates a secure tunnel from my local machine to GCP’s Cloud SQL instance using IAM credentials. Why Use the Cloud SQL Auth Proxy? Secure connections: All traffic is encrypted using TLS 1.3. IAM-based authentication: No need to manage static passwords or SSL certificates. No public IP required: You can connect even if your Cloud SQL instance has only a private IP. Automatic credential management: The proxy handles authentication and token refresh. ⚠️ Important: ...

How To Install Python 3.10 on Ubuntu 24.04 for pyannote.audio Compatibility

Image
I'm currently working with pyannote.audio version 3.1.1, and for full compatibility, it requires Python 3.10—especially because it was trained with torch==1.13.1 and CUDA 11.7. But by default, Ubuntu 24.04 ships with Python 3.12, and that caused some issues with dependencies. Python 3.10 Isn’t Included in Ubuntu 24.04 Ubuntu 24.04 (codename: noble ) only comes with Python 3.12 by default. When I tried to install Python 3.10 using just sudo apt update , the package simply couldn’t be found—because it isn’t included in the official package repositories. To install Python 3.10, I had to add the deadsnakes/ppa . This is a reliable third-party repository that provides older or alternative Python versions not offered in Ubuntu’s official repositories. # Add the Deadsnakes PPA $ sudo add-apt-repository ppa:deadsnakes/ppa $ sudo apt update # Install Python 3.10 and related tools $ sudo apt install python3.10 python3.10-venv python3.10-dev \ python3.10-distutils p...

How to Install Python 3.12 on Ubuntu 22.04

Image
Ubuntu 22.04 ships with Python 3.10 by default. Since I needed Python 3.12 for newer features and compatibility, I installed it manually. Here’s how I safely set it up alongside the system Python. Step 1: Update your system sudo apt update sudo apt upgrade -y Step 2: Install Python 3.12 and tools sudo apt install -y python3.12 python3.12-venv python3.12-setuptools python3.12-dev python3.12 : The main Python 3.12 interpreter. python3.12-venv : Enables creation of virtual environments using python3.12 -m venv . python3.12-setuptools : Provides tools to build and install Python packages (replacement for deprecated distutils). python3.12-dev : Includes headers and libraries needed to build Python C extensions and compile native modules. Step 3: Set python3 to point to Python 3.12 If your system still points to an older version, you can use update-alternatives to switch. sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.12 2 sudo updat...

Speech-to-Text and Speaker Diarization with Wav2Vec2 and pyannote.audio 3.1 on Ubuntu 24.04

Image
In this post, I walk through how to use Wav2Vec2 for speech-to-text (STT) and pyannote.audio 3.1 for speaker diarization on Ubuntu 24.04. I'll use a Python virtual environment with Python 3.10, CUDA GPU acceleration, and Hugging Face models. Step 1: Python 3.10 Installation Ubuntu 24.04 comes with Python 3.12 by default, but since pyannote.audio 3.1.1 was trained with torch==1.13.1 and CUDA 11.7, which support Python 3.10, I need to install Python 3.10: How To Install Python 3.10 on Ubuntu 24.04 Step 2: Create Virtual Environment stt@GU502DU:~$ python3.10 -m venv wav2vec2_env stt@GU502DU:~$ source wav2vec2_env/bin/activate Step 3: Install torch 2.5.1 and cuda 12.1 My laptop is equipped with an NVIDIA GeForce GTX 1660, so I chose to install and use CUDA. Since the GPU driver reports CUDA Version 12.8, I installed the cu121 build of PyTorch, which is compatible with it. (wav2vec2_env) stt@GU502DU:~$ pip install torch==2.5.1+cu121 torchaudio==2.2.1+cu121 \ --extr...

Install NVIDIA Driver for GeForce GTX 1660 Ti on Ubuntu 24.04

Image
If you have an NVIDIA GeForce GTX 1660 Ti installed on your laptop and want to enable GPU support (e.g., for CUDA-enabled libraries like PyTorch), here's how to install the appropriate NVIDIA driver on Ubuntu 24.04. Step 1: Check if your NVIDIA GPU is detected stt@GU502DU:~$ lspci | grep -i nvidia 01:00.0 VGA compatible controller: NVIDIA Corporation TU116M [GeForce GTX 1660 Ti Mobile] (rev a1) 01:00.1 Audio device: NVIDIA Corporation TU116 High Definition Audio Controller (rev a1) 01:00.2 USB controller: NVIDIA Corporation TU116 USB 3.1 Host Controller (rev a1) 01:00.3 Serial bus controller: NVIDIA Corporation TU116 USB Type-C UCSI Controller (rev a1) Step 2: Check current driver status If you see something like this when you run nvidia-smi , it means the driver is not installed yet. root@GU502DU:~# nvidia-smi Command 'nvidia-smi' not found, but can be installed with: apt install nvidia-utils-470 apt install nvidia-utils-535 apt install nvidia-utils...

Speech-to-Text and Speaker Diarization with Whisper and pyannote.audio 3.1 on Ubuntu 24.04

Image
If you want to generate subtitles with speaker labels from an audio file using Whisper and pyannote.audio on Ubuntu 24.04, this blog post walks you through the full setup process. Step 1: Python 3.10 Installation (Manual) Ubuntu 24.04 comes with Python 3.12 by default, but pyannote.audio 3.1.1 was trained with torch==1.13.1 and CUDA 11.7, which supports Python 3.10 . So I need to install Python 3.10: How To Install Python 3.10 on Ubuntu 24.04 Step 2: Create and Activate a Python Virtual Environment stt@GU502DU:~$ python3.10 -m venv whisper_env stt@GU502DU:~$ source whisper_env/bin/activate Step 3: Install torch 2.5.1 and cuda 12.1 My laptop is equipped with an NVIDIA GeForce GTX 1660, so I chose to install and use CUDA. Since the GPU driver reports CUDA Version 12.8, I installed the cu121 build of PyTorch, which is compatible with it. (whisper_env) stt@GU502DU:~$ pip install torch==2.5.1+cu121 torchaudio==2.2.1+cu121 \ --extra-index-url https://download.py...

Use jq to Format JSON in gVim on Windows (Prettify & Minify)

Image
jq is a powerful command-line tool for processing and formatting JSON data. While there's no official Windows version available anymore, you can still use jq on Windows with an unofficial executable. Step 1: Download the jq Executable Visit the following GitHub release page and download the 64-bit version (jq-win64.exe): https://github.com/jqlang/jq/releases/tag/jq-1.6 Rename from jq-win64.exe to jq.exe and move it to your Vim folder like "C:\Program Files\Vim\vim91" Step 2: Add to System Path Open: Control Panel → System → Advanced system settings → Environment Variables Under “System Variables”, find and select Path, then click “Edit”. Add the following path: C:\Program Files\Vim\vim91 Step 3: Test jq in Terminal Open Command Prompt or PowerShell and run: PS C:\Users\jason> jq --version You should see: jq-1.6 Step 4: Use jq Inside Vim/GVim In Vim/GVim, format the current file using: :%!jq . This sends the whole file through jq and repla...

AWS SAM Template: How to Properly Define Inline IAM Policies

AWS Serverless Application Model (SAM) is a powerful framework for defining serverless resources like Lambda functions. One commonly misunderstood part of SAM templates is the Policies section under AWS::Serverless::Function . I used to write YAML files without ever including the Version field, so I habitually left it out in the Policies section as well — this caused unexpected error when deploying, and it took me quite a while to figure out what was wrong and fix the problem. Incorrect: Using Only " - Statement:" Policies: - Statement: - Effect: Allow Action: - transcribe:GetMedicalTranscriptionJob Resource: "*" This will result in errors like: Invalid ARN: Could not be parsed! Template format error: Every policy must contain a Version field Correct: Include Full Policy Document Policies: - Version: '2012-10-17' Statement: - Effect: Allow Action: - transcribe:GetMedicalTranscrip...