Skip to content

Archive / page 97

All articles

Every practical article from the Nalar archive, newest first.

Linux Updated 07 Sep 2025 2 min read

Read and Use `top` on Linux

top is a standard Linux tool for viewing system load and processes in real time. It is useful when diagnosing high CPU use, memory pressure, runaway processes, or general server load. Start top top The display has a system summary at the top and a process table below it.

Linux Updated 02 Sep 2025 1 min read

Monitor Linux Processes with `ps`

ps (process status) prints a snapshot of processes. Unlike top or htop, it does not continuously refresh, which makes it particularly useful in shell pipelines, scripts, and one-time diagnostics. Current Terminal Processes ps All Processes ps -e ps -ef ps -ef uses a Unix-style full-format listing with fields such as UID, PID, PPID, and command.

Python Updated 02 Sep 2025 2 min read

Using `venv` in Python

A Python virtual environment isolates a project’s installed packages from the system Python environment and from other projects. This helps prevent dependency conflicts and makes development environments easier to reproduce. Create a Virtual Environment From the project directory: python3 -m venv .venv .venv is a common directory name because many editors recognize it automatically. You can use another name if your project has a different convention.

Linux Updated 07 Sep 2025 2 min read

Search Text with `grep` and Regular Expressions on Linux

grep can search for literal text or regular-expression patterns. With extended regular expressions, it becomes a compact tool for locating structured values, alternatives, prefixes, suffixes, and other text patterns. Extended Regular Expressions Use -E: grep -E 'regex_pattern' file Single quotes are often convenient in the shell because they prevent accidental expansion of regex metacharacters by the shell itself.

Linux Updated 02 Sep 2025 1 min read

Search for Text from the Linux Terminal

grep is one of the standard Linux tools for searching text in files or command output. Search One File grep 'error' application.log Search Several Files grep 'TODO' *.py Ignore Case grep -i 'warning' /var/log/syslog Show Line Numbers grep -n 'function' script.js Search Recursively grep -rI 'main' ./src -r walks subdirectories and -I skips binary files.

Linux Updated 02 Sep 2025 2 min read

Linux File Permissions: A Practical Guide for Developers

Linux file permissions control who can read, modify, or execute files and who can traverse or modify directories. Understanding them is essential for development, deployment, and server administration. Permission Classes Permissions are defined for: user (u) — the file owner; group (g) — users in the file’s group; others (o) — everyone else. The basic permission bits are: read (r); write (w); execute (x). For directories, r allows listing names, w allows creating/removing entries when combined with appropriate access, and x allows traversal.

Linux Updated 02 Sep 2025 2 min read

Finding Files on Linux with `find`

When a directory tree becomes large and deeply nested, searching manually is inefficient. Linux provides the find command for locating files and directories by name, size, type, modification time, and many other properties. 1. Basic Syntax find [path] [expression] path specifies where the search starts. Use . for the current directory. expression defines the filters and actions. 2. Practical Examples Find a File by Name find . -type f -name "example.txt" This searches the current directory and all subdirectories for a regular file named example.txt.

Linux Updated 02 Sep 2025 2 min read

Extract PSD Layers with Bash and ImageMagick

ImageMagick can read many Photoshop PSD files and export the images it exposes as frames or layers. Combined with a Bash loop, this can automate batch extraction without opening every file manually. Install ImageMagick On Debian/Ubuntu: sudo apt install imagemagick ImageMagick 7 uses the magick command. Some older installations expose commands such as convert directly.

Artificial Intelligence Updated 02 Sep 2025 2 min read

Using YOLOv8 for Object Detection with Labels and Confidence Scores

In this article, we will use YOLOv8 to detect objects in an image and print each object’s label and confidence score. YOLO (You Only Look Once) has long been a popular choice for object detection, and YOLOv8 provides a convenient Python API through the ultralytics package. Here is how to use it. Prerequisites Make sure Python and the ultralytics library are installed on your system. If needed, install the package with pip:

Artificial Intelligence Updated 02 Sep 2025 2 min read

SMS Spam Detection with BERT and PyTorch

BERT can classify SMS messages as spam or legitimate after a sequence-classification model has been fine-tuned on labeled examples. BERT (Bidirectional Encoder Representations from Transformers) is a widely used NLP model architecture that can be adapted to many text tasks, including classification. PyTorch and Hugging Face Transformers provide a convenient way to work with BERT models. Requirements Before you begin, make sure you have: Python PyTorch Hugging Face Transformers An SMS dataset, such as the SMS Spam Collection, if you plan to fine-tune a classifier Install the required libraries with:

Artificial Intelligence Updated 02 Sep 2025 2 min read

Real-Time Object Detection with YOLOv8 and OpenCV

YOLO (You Only Look Once) is one of the most popular object detection approaches. In this article, we will use YOLOv8 with OpenCV to perform real-time object detection through a webcam. Prerequisites Make sure you have: Python 3.8+ The ultralytics library for YOLOv8 The opencv-python library for webcam access Install the dependencies with pip: pip install ultralytics opencv-python Example Code The following Python example performs object detection from a webcam stream:

Artificial Intelligence Updated 02 Sep 2025 2 min read

Object Detection with YOLOv8: Using a Pre-Trained Model on Images

YOLOv8 can run object detection on images with a pre-trained model. YOLO (You Only Look Once) is a well-known object-detection algorithm, and YOLOv8 is designed for fast inference and accurate results. The ultralytics library provides the Python interface used below. Requirements Before you begin, make sure you have: Python The ultralytics library If it is not installed yet, install it with pip: pip install ultralytics Run YOLOv8 on an image This example loads a pre-trained YOLOv8 model, runs it on one image, and exposes the detection results:

Linux Updated 07 Sep 2025 2 min read

Replacing Text in Files with `sed` on Linux

Editing the same text manually across many files is slow and error-prone. The Linux sed stream editor can search, replace, delete, and transform text from the command line. 1. Preview a Replacement Suppose several .txt files contain abc and you want to replace every occurrence with aab: sed 's/abc/aab/g' *.txt Without -i, sed writes the transformed content to standard output and leaves the files unchanged. This makes it useful for previewing a replacement before editing files in place.

Web Development Updated 02 Sep 2025 3 min read

Backing Up a MySQL Database from PHP

Database backups are essential for recovery, migrations, and operational safety. Although PHP can query table definitions and manually generate SQL, a production-ready MySQL backup is better delegated to MySQL’s own mysqldump utility when it is available. This guide shows how a PHP script can invoke mysqldump safely enough for a controlled server environment. 1. Define the Database and Backup Settings <?php $host = 'localhost'; $user = 'backup_user'; $password = getenv('MYSQL_BACKUP_PASSWORD'); $database = 'your_database'; $backupFile = __DIR__ . '/backups/backup-' . date('Ymd-His') . '.sql'; Keep credentials out of source code whenever possible. Environment variables, secret stores, or protected configuration files are preferable to hard-coded passwords.

Go Updated 02 Sep 2025 2 min read

Validate User Input in a Go Web App with Gin

Input validation is one of the first defenses a web application has against malformed, incomplete, or unexpected data. Validation should run before business logic writes data to a database or triggers other side effects. This example uses Gin with go-playground/validator to validate a simple registration request. Project Structure project/ ├── main.go └── utils/ └── validation.go 1. Set Up Gin Create main.go:

Go Updated 02 Sep 2025 2 min read

Implement Validation in a Go Web App with Gin

Input validation is an important part of any web application. It lets the server reject malformed or incomplete data before business logic runs. This tutorial builds a small API with Gin and uses go-playground/validator for declarative validation rules. Project Structure project/ ├── main.go └── utils/ └── validation.go 1. Create the Gin Application Create main.go with a /register endpoint:

Linux Updated 02 Sep 2025 2 min read

Managing Linux Filenames: Replacing Spaces with Underscores

Spaces in filenames are valid on Linux, but they can make shell scripting more cumbersome because paths must be quoted carefully. If a project has a naming convention that prefers underscores, you can rename files in batches with standard shell tools. A Safe Bash Approach The following script recursively finds files whose names contain spaces and replaces those spaces with underscores: find . -type f -name "* *" -print0 | while IFS= read -r -d '' file; do dir=$(dirname -- "$file") base=$(basename -- "$file") new=${base// /_} [ "$base" = "$new" ] || mv -n -- "$file" "$dir/$new" done The important details are:

JavaScript Updated 02 Sep 2025 2 min read

Split a JavaScript Array into Chunks

JavaScript does not have a built-in chunk method for splitting an array into equally sized groups, but the operation is easy to implement with slice. Chunking is useful for UI grids, pagination helpers, batching API operations, and processing large collections in smaller units. A Simple chunk Function function chunk(array, size) { if (!Number.isInteger(size) || size <= 0) { throw new RangeError('size must be a positive integer'); } const result = []; for (let i = 0; i < array.length; i += size) { result.push(array.slice(i, i + size)); } return result; } Use it like this:

Database 29 Sep 2022 2 min read

Configuring Remote MySQL Access on Linux

MySQL installations are commonly configured to listen only on a local interface. If a database must accept connections from another machine, you need to adjust the server’s listening address, create an appropriately scoped account, and make sure the network firewall allows only the required clients. Step 1: Update the MySQL Configuration Edit the MySQL configuration file On Ubuntu and Debian installations, a common file is: sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf Change bind-address

Linux Updated 02 Sep 2025 2 min read

Monitoring Directory Sizes on Linux with `du` and `sort`

When a Linux server starts running low on disk space, one of the fastest ways to investigate is to find which directories consume the most storage. The du and sort commands work well together for this task. 1. du: Measure Disk Usage du reports how much disk space files and directories use. Two useful options are: -s — show one summary total for each argument instead of every nested item. -h — display sizes in a human-readable format such as KB, MB, or GB. For example:

JavaScript Updated 02 Sep 2025 1 min read

Convert Text to Title Case in JavaScript

A simple title-case helper can make labels, headings, and generated display text easier to read. Basic Helper function titleCase(text) { return text .toLowerCase() .split(/\s+/) .filter(Boolean) .map((word) => word.charAt(0).toUpperCase() + word.slice(1)) .join(' '); } Examples:

Web Development Updated 07 Sep 2025 2 min read

Finding the Last Day of a Month in PHP

Finding the number of days in a month is useful for reporting, billing periods, scheduling, and date validation. PHP can do this directly with its date APIs, including support for leap years. A Simple getLastDay Function The following function accepts a month in YYYY-MM format and returns the number of days in that month: function getLastDay(string $month): int { $date = new DateTimeImmutable($month . '-01'); return (int) $date->format('t'); } How the Code Works Create a date for the first day of the month

Web Development Updated 07 Sep 2025 2 min read

Extracting Usernames from Social Media URLs with PHP

Web applications sometimes need to extract a profile identifier from a social-media URL for normalization, imports, or display. PHP’s URL parsing functions are usually easier to maintain than one large regular expression because they let you validate the hostname and path separately. A parseUsername Function The following example supports several common profile URL formats: function parseUsername(string $url): string { $host = strtolower((string) parse_url($url, PHP_URL_HOST)); $path = trim((string) parse_url($url, PHP_URL_PATH), '/'); $supportedHosts = [ 'twitter.com', 'www.twitter.com', 'x.com', 'www.x.com', 'medium.com', 'www.medium.com', 'facebook.com', 'www.facebook.com', 'vimeo.com', 'www.vimeo.com', 'instagram.com', 'www.instagram.com', ]; if (!in_array($host, $supportedHosts, true) || $path === '') { return $url; } return explode('/', $path)[0]; } How It Works Parse the hostname and path

Linux Updated 02 Sep 2025 2 min read

Synchronizing Files with `rsync` over SSH

rsync is a reliable tool for copying and synchronizing files locally or between machines. When the remote side is accessed through SSH, the transfer is encrypted and can use the same authentication model as normal SSH sessions. Basic Remote Synchronization A common command is: rsync -avP /home/user/documents/ user@example.com:/home/user/backup/ The options are: