Skip to content

Archive / page 94

All articles

Every practical article from the Nalar archive, newest first.

Linux Updated 02 Sep 2025 2 min read

Mastering `curl` on Linux: Downloads and API Requests

curl is one of the most useful command-line tools for transferring data and testing HTTP APIs. It supports HTTP, HTTPS, FTP, and many other protocols, making it useful for downloads, automation, diagnostics, and API development. 1. Check or Install curl Check the installed version: curl --version On Debian or Ubuntu:

Linux Updated 02 Sep 2025 1 min read

List All Group Names on Linux

Linux groups are used to organize users and assign shared permissions. There are several ways to list them, and the best command depends on whether your system uses only local files or also directory services such as LDAP. Use getent getent group getent queries the system’s configured name-service databases, so it can include groups from /etc/group as well as network identity sources.

Linux Updated 02 Sep 2025 2 min read

Find the Most Resource-Intensive Processes on Linux

When a Linux system feels slow, a small number of processes may be consuming most of the CPU, memory, or disk I/O. Several standard tools help identify them quickly. Highest CPU Usage with ps ps aux --sort=-%cpu | head For more rows:

Linux Updated 02 Sep 2025 2 min read

Find Recently Changed Files on Linux

Linux provides several ways to find files that were modified recently or to watch a directory for changes as they happen. Files Modified in the Last Hour find /path/to/directory -type f -mmin -60 -mmin works in minutes.

Linux Updated 02 Sep 2025 1 min read

Display a Directory Tree on Linux

A directory tree makes project and filesystem structure easier to understand than a flat list of paths. The dedicated tree utility is usually the clearest tool for this job. Use tree tree Example output:

Linux Updated 02 Sep 2025 2 min read

Create Cron Jobs on Linux

Cron is a time-based scheduler commonly used on Linux and Unix-like systems. It can run backups, cleanup scripts, reports, maintenance commands, and other recurring tasks automatically. Cron Syntax A user crontab entry has five schedule fields followed by the command: * * * * * /path/to/command - - - - - | | | | | | | | | +----- day of week (0-7, Sunday=0 or 7) | | | +------- month (1-12) | | +--------- day of month (1-31) | +----------- hour (0-23) +------------- minute (0-59) Edit Your User Crontab crontab -e For example, run a backup every day at 02:30:

Linux Updated 02 Sep 2025 2 min read

Create and Manage Symbolic Links on Linux

A symbolic link, or symlink, is a special filesystem entry that stores a path to another file or directory. Symlinks are useful for shortcuts, shared configuration, version switching, and keeping one canonical copy of data. Create a Symlink ln -s TARGET LINK_NAME Link to a file:

Linux Updated 02 Sep 2025 2 min read

Count Files in a Linux Directory Quickly

Counting files is useful in shell scripts, backups, log maintenance, migration checks, and filesystem monitoring. The right command depends on whether you want only regular files, recursive results, hidden files, directories, or symbolic links. Count Regular Files in One Directory With GNU find: find /path/to/directory -maxdepth 1 -type f -printf '.' | wc -c -maxdepth 1 prevents recursion into subdirectories. Hidden files are included automatically.

Linux Updated 02 Sep 2025 2 min read

Compress and Extract Files Quickly on Linux

Linux provides several standard compression tools. Some compress a single file, while tar combines many files into one archive and can apply compression at the same time. gzip gzip filename gunzip filename.gz gzip is widely available and usually a good balance between speed and compression ratio.

Go Updated 02 Sep 2025 2 min read

Working with Time in Go Without the Headaches

Time handling looks simple until time zones, parsing, durations, and scheduling enter the picture. Go’s standard time package covers the common cases without requiring third-party libraries. Current Time currentTime := time.Now() fmt.Println("Now:", currentTime) time.Now() returns the current local time according to the process environment.

Cloud Computing Updated 02 Sep 2025 2 min read

Using Nginx as a Reverse Proxy for a Go Application

A Go web application often listens directly on an application port such as :8080. If you want users to access it through a normal domain on port 80 or 443, you can place Nginx in front of it as a reverse proxy. Using Nginx in front of a Go service provides several benefits: Client requests reach Nginx before being forwarded to the Go application. TLS termination can be handled at the proxy layer. Multiple application instances can be load balanced. Static assets can be served separately when that architecture makes sense. This guide shows a basic setup.

Python Updated 02 Sep 2025 2 min read

Understanding Conditional Expressions in Python

Python does not use the condition ? a : b syntax found in languages such as C or JavaScript. Instead, it provides a conditional expression that reads naturally from left to right. Basic Syntax value_if_true if condition else value_if_false For example:

Python Updated 02 Sep 2025 2 min read

Understanding `@staticmethod` vs `@classmethod` in Python

Python provides @staticmethod and @classmethod for methods that do not operate on one specific instance. They look similar at first, but they receive different context and solve different problems. @staticmethod A static method receives no implicit self or cls argument: class Temperature: @staticmethod def celsius_to_fahrenheit(value): return value * 9 / 5 + 32 print(Temperature.celsius_to_fahrenheit(20)) Use a static method when a function logically belongs in the class namespace but does not need instance or class state.

Python Updated 02 Sep 2025 2 min read

Understanding `__str__` vs `__repr__` in Python

Python provides __str__() and __repr__() so classes can control how their instances appear as text. They serve related but different audiences. __str__: Human-Friendly Output str(obj) and usually print(obj) use __str__(): class Person: def __init__(self, name, age): self.name = name self.age = age def __str__(self): return f"{self.name}, age {self.age}" person = Person("Alice", 30) print(person) Output:

Python Updated 02 Sep 2025 2 min read

Understanding `__init__.py` in Python

The __init__.py file is commonly used to define a regular Python package and control what happens when that package is imported. It can be empty, expose a package-level API, define metadata, or run lightweight initialization code. 1. A Basic Package Consider this structure: my_package/ ├── __init__.py ├── module1.py └── module2.py With __init__.py present, my_package is a regular package and its modules can be imported normally:

Go Updated 02 Sep 2025 2 min read

Structs in Go: A Practical Guide with Examples

A struct groups related fields into a single Go type. Structs are the standard way to model domain entities, configuration, request data, records, and many other compound values. Define a Struct type Person struct { Name string Age int Address string } p := Person{Name: "Alice", Age: 30, Address: "123 Main St"} fmt.Println(p.Name, p.Age, p.Address) Using field names in composite literals is usually clearer and more resilient than relying on field order.

Go Updated 02 Sep 2025 3 min read

Several Ways to Handle Optional Parameters in Go

Go deliberately does not support optional or default function parameters like some other languages. Function signatures are explicit, which keeps call sites and APIs predictable. When an API genuinely needs optional configuration, Go developers usually choose one of a few established patterns. 1. Variadic Parameters A variadic parameter (...) is useful when the optional part is simply zero or more values of the same type: func greet(message string, names ...string) { for _, name := range names { fmt.Printf("%s, %s!\n", message, name) } } func main() { greet("Hello") greet("Hello", "Alice", "Bob", "Charlie") } message is required, while names may contain zero, one, or many values.

Go Updated 02 Sep 2025 3 min read

Pretty-Printing JSON in Go with MarshalIndent

Compact JSON is efficient for transport, but long documents can be difficult to inspect when everything appears on one line. Go’s standard encoding/json package includes json.MarshalIndent for producing human-readable JSON with line breaks and indentation. Pretty-printed JSON is useful for debugging, generated configuration, logs intended for people, and command-line output. 1. Use json.MarshalIndent package main import ( "encoding/json" "fmt" ) func main() { data := map[string]any{ "name": "Alice", "age": 30, "address": map[string]string{ "street": "123 Main St", "city": "Wonderland", }, "hobbies": []string{"reading", "hiking", "coding"}, } prettyJSON, err := json.MarshalIndent(data, "", " ") if err != nil { fmt.Println("Error:", err) return } fmt.Println(string(prettyJSON)) } MarshalIndent accepts three arguments:

Go Updated 02 Sep 2025 2 min read

Practical Ways to Combine Slices in Go

Combining slices is common when data comes from several sources or processing stages. In Go, the standard approach is append, optionally with preallocated capacity when the final size is known. 1. Combine Slices with append package main import "fmt" func main() { slice1 := []int{1, 2, 3} slice2 := []int{4, 5, 6} slice3 := []int{7, 8, 9} combined := append(slice1, slice2...) combined = append(combined, slice3...) fmt.Println(combined) } Output:

Python Updated 02 Sep 2025 2 min read

Merging Multiple Dictionaries in Python

Combining dictionaries is common when assembling configuration, request data, defaults, or results from multiple sources. Python provides several approaches, and the right one depends on the Python version and whether you want to mutate an existing dictionary. 1. Dictionary Union with | (Python 3.9+) Modern Python supports the dictionary union operator: dict1 = {"a": 1, "b": 2} dict2 = {"b": 3, "c": 4} dict3 = {"d": 5} merged = dict1 | dict2 | dict3 print(merged) Output:

Go Updated 02 Sep 2025 2 min read

Maps in Go: A Practical Guide with Examples

A Go map stores key-value pairs and gives you fast lookup by key. It is similar to a dictionary or hash map in other languages and is one of Go’s most useful built-in data structures. Creating a Map Using make: personAge := make(map[string]int) personAge["Alice"] = 30 personAge["Bob"] = 25 fmt.Println(personAge) Using a map literal:

Go Updated 02 Sep 2025 3 min read

Manage Goroutine Work Queues Efficiently in Go

Goroutines are one of Go’s defining features. They make concurrent work inexpensive to start, but creating an uncontrolled number of goroutines can still overwhelm memory, downstream services, file descriptors, or database connections. A common solution is a bounded worker pool: tasks are placed on a channel and a fixed number of goroutines consume them. Why Use a Queue? A controlled work queue helps you: limit the number of active workers; apply backpressure when work arrives faster than it can be processed; centralize task scheduling; shut down cleanly after queued work finishes. 1. A Basic Channel-Based Queue type Task struct { ID int } func worker(id int, tasks <-chan Task) { for task := range tasks { fmt.Printf("Worker %d processing task %d\n", id, task.ID) time.Sleep(time.Second) } } A channel can hold pending tasks while several workers read from it.

Go Updated 02 Sep 2025 2 min read

Loops in Go: A Practical Guide with Examples

Go has only one looping keyword: for. That can look unusual if you come from a language with separate for, while, and do-while constructs, but Go’s for is flexible enough to cover the common looping patterns. 1. Basic for Loop for i := 0; i < 5; i++ { fmt.Println(i) } This is similar to a traditional loop in C, Java, or JavaScript: initialize a counter, continue while the condition is true, and run the post statement after each iteration.

Go Updated 02 Sep 2025 4 min read

Learning Interfaces in Go: Concepts, Examples, and Best Practices

Interfaces are one of Go’s most important abstraction tools. An interface describes behavior as a set of method signatures. A concrete type satisfies an interface implicitly simply by implementing the required methods—there is no separate implements declaration. What Is an Interface? An interface is a set of methods. For example: type Speaker interface { Speak() string } type Person struct { Name string } func (p Person) Speak() string { return "Hello, my name is " + p.Name } Because Person has the required Speak() string method, it satisfies Speaker: