Skip to content

Archive / page 92

All articles

Every practical article from the Nalar archive, newest first.

JavaScript Updated 02 Sep 2025 3 min read

State Management in Vue 3 with Pinia

Effective state management becomes increasingly important as a Vue application grows. Pinia is the recommended state-management library for Vue and provides a compact API, strong TypeScript support, and good integration with the Composition API. This guide covers the basic setup and the core concepts of state, getters, and actions. 1. What Is Pinia? Pinia is a state-management library designed for Vue applications. Compared with older Vuex patterns, it generally offers:

JavaScript Updated 02 Sep 2025 3 min read

Sending Data from a Child Component to Its Parent in Vue 3

Component communication is a fundamental part of Vue 3 applications. Parents usually pass data down through props, while children send information upward by emitting events. For values that represent a two-way component model, Vue also provides the v-model component contract. 1. Why Child-to-Parent Communication Matters Common examples include: A form field component informing its parent that a value changed. A list item notifying its parent that the user selected or removed it. A reusable control reporting an action such as submit, close, or confirm. Keeping this communication explicit helps components remain reusable and easier to test.

Rust Updated 02 Sep 2025 4 min read

Rust Ownership, Moves, and Borrowing

Ownership is one of Rust’s defining features. It lets Rust manage memory safely without a garbage collector by enforcing rules about who owns a value, when ownership moves, and when values are dropped. Ownership affects variable scope, function calls, references, borrowing, and many compiler errors in Rust. What ownership means Ownership is Rust’s model for managing resources. A value has an owner, and Rust can determine at compile time when that value is no longer needed. This design helps prevent problems such as use-after-free bugs, double frees, dangling references, and data races.

Artificial Intelligence Updated 02 Sep 2025 2 min read

Running LLMs on Your Local Computer

Have you ever wanted to run a large language model (LLM) directly on your own computer without depending on a cloud service? Tools such as Ollama make it possible to manage and run language models locally from a laptop or desktop. This article walks through the basic setup and shows how to run a model on Linux and macOS. Installing Ollama on Linux For Linux, the installation process is straightforward:

JavaScript Updated 02 Sep 2025 3 min read

Making API Requests in Vue 3 with Axios

HTTP APIs are a core part of modern web applications. In Vue 3, Axios is a popular HTTP client that provides a convenient API for making requests, configuring defaults, and handling responses and errors. This tutorial demonstrates common CRUD-style requests against the public DummyJSON example API. 1. Install and Configure Axios Install Axios: npm install axios You can configure a reusable Axios instance instead of modifying global defaults:

Python Updated 02 Sep 2025 2 min read

Understanding Polymorphism in Python

Polymorphism means that different objects can respond to the same operation in their own way. In Python, this often appears through inheritance, method overriding, protocols, and duck typing. Method Overriding with Inheritance class Animal: def sound(self): return "unknown sound" class Dog(Animal): def sound(self): return "bark" class Cat(Animal): def sound(self): return "meow" Code can treat each object through the shared sound() interface:

Python Updated 02 Sep 2025 2 min read

Understanding Iterators in Python

Iterators are a core Python concept behind for loops, generators, file objects, and many standard-library APIs. They provide one item at a time instead of requiring every result to be materialized in memory at once. Iterable vs Iterator An iterable is an object you can pass to iter(), such as a list, tuple, dictionary, set, or string. An iterator is an object that produces successive values through next(). numbers = [1, 2, 3] iterator = iter(numbers) print(next(iterator)) # 1 print(next(iterator)) # 2 print(next(iterator)) # 3 Calling next() again raises StopIteration because the iterator is exhausted.

Python Updated 02 Sep 2025 2 min read

Understanding Classes and Objects in Python

Python supports object-oriented programming through classes and objects. A class defines behavior and data structure, while an object is a concrete instance of that class. Define a Class class Car: def __init__(self, make, model): self.make = make self.model = model def display_info(self): print(f"Car Make: {self.make}, Model: {self.model}") __init__() initializes a new instance after it is created. The first parameter, conventionally named self, refers to the instance receiving the method call.

Python Updated 02 Sep 2025 3 min read

Python String Formatting: A Practical Guide

String formatting lets Python programs combine values with readable text while controlling alignment, precision, numeric separators, dates, and other presentation details. Modern Python generally favors f-strings for application code. 1. F-Strings Available since Python 3.6, f-strings embed expressions directly: name = "Alice" age = 30 message = f"{name} is {age} years old." print(message) Expressions can be evaluated inside the braces:

Python Updated 02 Sep 2025 3 min read

Python RegEx: A Practical Guide to Regular Expressions

Regular expressions describe text patterns for searching, validating, extracting, splitting, and replacing strings. Python provides regular-expression support through the standard-library re module. Start with Raw Strings Regex patterns often contain backslashes. Raw string literals keep them readable: import re pattern = r"\d+" Without the r prefix, Python string escaping and regex escaping can interact in confusing ways.

Python Updated 02 Sep 2025 2 min read

Python Modules: Organizing Code Effectively

A Python module is a .py file that groups related functions, classes, constants, and other definitions. Splitting a growing program into modules makes code easier to navigate, test, reuse, and maintain. Create a Module Create my_module.py: def greet(name): return f"Hello, {name}!" def add(a, b): return a + b Then import it from another file in the same importable project location:

Python Updated 02 Sep 2025 2 min read

Python Math: Essential Functions and Operations for Beginners

Python’s standard math module provides functions and constants for floating-point mathematics, including square roots, logarithms, trigonometry, rounding helpers, and combinatorics. Import the Module import math Square Roots and Powers print(math.sqrt(16)) # 4.0 print(math.pow(2, 3)) # 8.0 print(2 ** 3) # 8 For ordinary exponentiation, the ** operator is usually simpler. math.pow() converts its arguments to floating point and returns a float.

Python Updated 02 Sep 2025 2 min read

Python Inheritance

Inheritance lets one Python class reuse and specialize behavior defined by another class. It can be useful when classes have a genuine “is-a” relationship and share a stable interface. Basic Inheritance class Animal: def sound(self): return "unknown" class Dog(Animal): def sound(self): return "bark" print(Dog().sound()) Dog inherits from Animal and overrides sound() with behavior specific to dogs.

Python Updated 02 Sep 2025 3 min read

Python `try-except`: A Practical Error-Handling Guide

Exceptions let Python programs report failures without encoding every error as a special return value. try and except provide structured recovery when an operation has expected failure modes. Basic try-except try: number = int("not-a-number") except ValueError: print("The value is not a valid integer.") When int() raises ValueError, Python skips the remaining code in the try block and runs the matching handler.

Python Updated 02 Sep 2025 2 min read

JSON in Python: Working with JSON Data

JSON (JavaScript Object Notation) is a text format for structured data exchange. Python includes the json module in the standard library, so common JSON operations require no third-party dependency. Python Objects to JSON Strings Use json.dumps() to serialize a Python object: import json data = { "name": "Alice", "age": 25, "city": "New York", } json_string = json.dumps(data) print(json_string) For readable output:

JavaScript Updated 07 Sep 2025 2 min read

Use Optional Chaining (`?.`) Safely in JavaScript

Optional chaining (?.) lets JavaScript stop a property-access chain when the value immediately before ?. is null or undefined. Instead of throwing, the expression evaluates to undefined. Nested Properties const user = { profile: { name: 'Alice', address: { city: 'Wonderland' }, }, }; const city = user.profile?.address?.city; const postalCode = user.profile?.address?.postalCode; postalCode is undefined rather than causing an error.

JavaScript Updated 02 Sep 2025 1 min read

Use `Promise.any()` for the First Successful Result

Promise.any() fulfills as soon as one input promise fulfills. Rejections are ignored until either a promise succeeds or every input promise has rejected. const first = Promise.reject(new Error('first failed')); const second = new Promise((resolve) => setTimeout(resolve, 100, 'second succeeded')); const third = new Promise((resolve) => setTimeout(resolve, 200, 'third succeeded')); console.log(await Promise.any([first, second, third])); // second succeeded When Everything Fails If every promise rejects, Promise.any() rejects with an AggregateError:

JavaScript Updated 02 Sep 2025 1 min read

Replace Every Match with JavaScript `String.replaceAll()`

String.prototype.replaceAll() replaces every occurrence of a substring or every match of a global regular expression and returns a new string. Replace a Literal Substring const text = 'Hello World! Welcome to the World of JavaScript.'; const result = text.replaceAll('World', 'Universe'); Use a Regular Expression When searchValue is a RegExp, it must use the g flag:

JavaScript Updated 02 Sep 2025 2 min read

Private Fields and Methods in JavaScript Classes

JavaScript classes support truly private fields and methods using names that begin with #. They can be accessed only from code inside the class body that declares them. Private Fields class Person { #name; constructor(name) { this.#name = name; } getName() { return this.#name; } } Trying to access person.#name outside the class is a syntax error.

JavaScript Updated 02 Sep 2025 1 min read

JavaScript RegExp `d` Flag: Get Match Indices

The JavaScript regular-expression d flag enables match indices. It does not collect repeated captures; instead, it adds an indices property that tells you the start and end offsets of the overall match and each capturing group. Basic Example const regex = /(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})/d; const match = regex.exec('Date: 2024-08-30'); console.log(match[0]); // 2024-08-30 console.log(match.indices[0]); // [6, 16] console.log(match.indices.groups.year); // [6, 10] console.log(match.indices.groups.month); // [11, 13] console.log(match.indices.groups.day); // [14, 16] The end index is exclusive, matching the behavior of String.prototype.slice().

JavaScript Updated 07 Sep 2025 1 min read

JavaScript Numeric Separators (`_`)

JavaScript numeric separators let you place underscores inside numeric literals to improve readability. They do not change the numeric value. const million = 1_000_000; console.log(million); // 1000000 Decimal Fractions const pi = 3.141_592_653; Binary, Octal, and Hexadecimal const binary = 0b1010_1011; const octal = 0o123_456; const hex = 0xFF_FF_FF; Separators can also be used in BigInt literals:

JavaScript Updated 07 Sep 2025 1 min read

JavaScript Nullish Coalescing Operator (`??`)

The nullish coalescing operator, ??, provides a fallback only when the left-hand value is null or undefined. const username = null; const name = username ?? 'Guest'; console.log(name); // Guest ?? vs. || || falls back for every falsy value. ?? preserves valid falsy data such as 0, false, and '':

JavaScript Updated 07 Sep 2025 2 min read

JavaScript BigInt: Handling Large Integers

JavaScript Number can represent integers exactly only up to Number.MAX_SAFE_INTEGER (2^53 - 1). When you need larger integer values without losing precision, use BigInt. Create a BigInt const a = 123456789012345678901234567890n; const b = BigInt('123456789012345678901234567890'); The n suffix creates a BigInt literal. BigInt() is useful when converting a string or an integer-valued Number.

JavaScript Updated 02 Sep 2025 1 min read

JavaScript `||=`: Logical OR Assignment

The logical OR assignment operator, ||=, assigns a new value only when the current left-hand value is falsy. let name = ''; name ||= 'Guest'; console.log(name); // 'Guest' Falsy values include false, 0, -0, 0n, '', null, undefined, and NaN.