Thursday, February 27, 2025

Troubleshooting Disk Quota Exceeded Error While Installing Triton from Source

 If you've encountered the [Errno 122] Disk quota exceeded error while installing the Triton Python package from source, you're not alone. This error typically indicates that your home directory has run out of disk space. In this post, we'll walk through the root cause of this issue and how to resolve it.

Understanding the Error

The error message [Errno 122] Disk quota exceeded is a clear indication that the disk space allocated to your home directory is insufficient. This can happen during the installation process of Triton, especially when it tries to extract LLVM into the ~/.triton directory.

Root Cause

The Triton build process uses the ~/.triton directory to extract LLVM, which can consume a significant amount of disk space. If your home directory has limited space, this can lead to the disk quota being exceeded.

Steps to Resolve

  1. Check Disk Usage: First, check the current disk usage of your home directory to confirm that it is indeed full.

    du -sh ~
    
  2. Free Up Space: If your home directory is full, you can free up space by deleting unnecessary files or moving them to another location.

    rm -rf ~/unnecessary-file-or-directory
    
    #Another way is you can create symlink to tmp if you homedirectory does not have enough diskspace
    mkdir /tmp/triton_tmp
    ln -s /tmp/triton_tmp ~/.triton
  3. Change Extraction Directory: You can change the directory where Triton extracts LLVM to a location with more available space. Set the TRITON_CACHE_DIR environment variable to a directory with sufficient space.

    export TRITON_CACHE_DIR=/path/to/large/directory
    
  4. Re-run Installation: After freeing up space or changing the extraction directory, try running the installation process again.

    pip install -e .
    
    # URL: https://github.com/triton-lang/triton/blob/main/docs/getting-started/installation.rst

Thursday, February 20, 2025

Bash emacs Readline Reference Guide

 

Enabling emacs Mode

To enable emacs mode in Bash, add the following line to your .bashrc file:

set -o emacs

Then, reload your .bashrc file:

source ~/.bashrc

Basic Navigation

  • Ctrl-a: Move to the beginning of the line.
  • Ctrl-e: Move to the end of the line.
  • Ctrl-b: Move backward one character.
  • Ctrl-f: Move forward one character.
  • Meta-b: Move backward one word.
  • Meta-f: Move forward one word.

Editing

  • Ctrl-d: Delete the character under the cursor.
  • Ctrl-k: Delete from the cursor to the end of the line.
  • Ctrl-u: Delete from the cursor to the beginning of the line.
  • Ctrl-w: Delete the word before the cursor.
  • Meta-d: Delete the word after the cursor.
  • Ctrl-y: Yank (paste) the last killed text.
  • Ctrl-_ or Ctrl-x Ctrl-u: Undo the last change.

Inserting Text

  • Ctrl-t: Transpose the character before the cursor with the character under the cursor.
  • Meta-t: Transpose the word before the cursor with the word under the cursor.

Searching

  • Ctrl-r: Search backward incrementally.
  • Ctrl-s: Search forward incrementally.

Miscellaneous

  • Ctrl-l: Clear the screen and redisplay the current line at the top.
  • Ctrl-x Ctrl-e: Open the current command in the default editor (usually emacs).

Key Modifiers

  • Ctrl (Control): Often abbreviated as C-.
  • Meta (usually Alt or Esc): Often abbreviated as M-.

Bash vi Readline Reference Guide

 

Enabling vi Mode

To enable vi mode in Bash, add the following line to your .bashrc file:

set -o vi

Then, reload your .bashrc file:

source ~/.bashrc

Basic Modes

  • Command Mode: This is the default mode. You can navigate and edit the command line.
  • Insert Mode: Enter this mode to insert text. Press i to switch to Insert mode from Command mode.

Navigation

  • hjkl: Move left, down, up, and right respectively.
  • 0: Move to the beginning of the line.
  • $: Move to the end of the line.
  • w: Move to the beginning of the next word.
  • b: Move to the beginning of the previous word.

Editing

  • x: Delete the character under the cursor.
  • dw: Delete from the cursor to the end of the word.
  • dd: Delete the entire line.
  • u: Undo the last change.
  • Ctrl-r: Redo the last undone change.

Inserting Text

  • i: Insert text before the cursor.
  • a: Insert text after the cursor.
  • I: Insert text at the beginning of the line.
  • A: Insert text at the end of the line.
  • o: Open a new line below the current line and enter Insert mode.

Searching

  • /pattern: Search forward for pattern.
  • ?pattern: Search backward for pattern.
  • n: Repeat the last search in the same direction.
  • N: Repeat the last search in the opposite direction.

Miscellaneous

  • .: Repeat the last command.
  • Ctrl-[: Exit Insert mode and return to Command mode.
  • v: Open the current command in the vi editor.

Tuesday, February 4, 2025

Mastering tput Commands for Color Printing and Terminal Control

 `tput` is a command-line utility in Linux systems that allows you to control terminal settings, such as changing colors or setting font attributes. It provides a range of options for customizing your output and enhancing the user experience.

In this guide, we'll explore the various features of `tput`, including color printing, font styles, cursor positioning, and more. Whether you're a developer looking to create visually

appealing command-line interfaces (CLI) or a system administrator seeking to improve terminal usability, this article will equip you with the knowledge necessary to harness the full potential of `tput`.

Color Printing with tput

To print colored output using `tput`, you need to specify color codes in the format recommended by the terminal being used. Most terminals support ANSI escape sequences, which allow for text formatting and changing colors among other things.

Color Codes

*   Foreground colors: 30-37 (red through white), 90-97 (bright red through bright white)

*   Background colors: 40-47 (red through white), 100-107 (bright red through bright white)

Example Code for Color Printing

tput setaf 1 # red
echo "Hello"

tput setab 4 # blue background
echo "World"

Resetting Colors with tput

To reset the colors after printing, use `tput sgr0` or `tput reset`. This command resets all attributes back to default (color, font style, etc.).

Example Code for Resetting Colors

tput setaf 1; echo "Hello"; tput sgr0 # resets color after printing

Additional Features of tput


In addition to color printing and resetting colors, `tput` offers various other features that can be used to enhance the user experience.

Setting Bold Text


`tput bold`: Makes text appear in a bold font.


tput bold; echo "Bold text"; tput sgr0 # sets text to bold and resets later


Setting Italic Text (Supported by Some Terminals)


`tput sitm` or `tput rmso`: Not all terminals support italic formatting, so use with caution. To reset the font style back to normal, use `tput rmso`.


Setting Underline Text (Supported by Some Terminals)

`tput smul` or `tput rmul`: Not all terminals support underlining, so use with caution. To reset the font style back to normal, use `tput rmul`.

Clearing Screen


`tput clear`: Clears the entire screen of any output.

tput clear
echo "New content here"


Cursor Control with tput


`tput civis` or `tput cvvis`: Hides or shows the cursor from view.

tput civis; echo "Hidden"; tput cvvis # hides and shows the cursor

Monday, February 3, 2025

ANSI escape sequences to print colored text(linux terminal)


ANSI escape sequences are a standardized way to add color and formatting to text in the terminal. Here are some common ANSI escape sequences for printing colored text:

Color Codes(Foreground)

Color

Code

Reset

\033[0m

Black

\033[30m

Red

\033[31m

Green

\033[32m

Yellow

\033[33m

Blue

\033[34m

Magenta

\033[35m

Cyan

\033[36m

White

\033[37m

Background Color Codes

Color

Code

Black Background

\033[40m

Red Background

\033[41m

Green Background

\033[42m

Yellow Background

\033[43m

Blue Background

\033[44m

Magenta Background

\033[45m

Cyan Background

\033[46m

White Background

\033[47m



Example Usage in Python

print("\033[31m" + "This text is red" + "\033[0m")

print("\033[32m" + "This text is green" + "\033[0m")

print("\033[34m" + "This text is blue" + "\033[0m")

print("\033[41m" + "This text has a red background" + "\033[0m")

print("\033[42m" + "This text has a green background" + "\033[0m")

Note

  • ANSI escape sequences may not work on all systems or terminals.
  • The \033[ code is the ESCAPE sequence that starts the ANSI command.
  • The m at the end of each code is what actually applies the change.

Other useful escape sequences:

To clear the whole line in a bash script when using \r to print on the same line, you can use the following methods:

Method 1: Using ANSI Escape Sequences

Bash

echo -ne "\r\033[K"

  • \r moves the cursor to the beginning of the line.
  • \033[K clears the line from the cursor position to the end.
Using printf command:

printf "\r%s \x1b[32m%s\x1b[0m\033[K\n" "$test_name" "Passed."

Method 2: Using tput

Bash

echo -ne "\r$(tput el)"

  • \r moves the cursor to the beginning of the line.
  • tput el clears the line from the cursor position to the end.

Example Usage

Bash

for i in {1..10}; do
    echo -ne "\rProgress: $i%"
    sleep 0.5
done
echo -ne "\r\033[K"
echo "Done!"

In this example, the progress is printed on the same line, and after the loop finishes, the line is cleared, and "Done!" is printed.

 

 

Why the name BFD linker?

 The Linux linker got its name "BFD Linker" because of a fascinating piece of history.

What's BFD?

BFD stands for Binary File Descriptor. It's a library and set of tools created in 1996 by Adam Beneschan, originally at Red Hat. The primary goal was to provide a unified interface for working with various file formats, including binary executables, object files, libraries, and archives.

Why the BFD linker?

The first implementation of the Linux linker (link editor) was called `ld` (short for link editor). In 1997, David S. Miller, a key figure in the development of the Linux kernel, started working on a new version of the linker that would utilize the BFD library.

This new version, also named `ld`, used BFD as its backend to manage and manipulate binary files. As a result, the linker became known as the BFD Linker or BFD ld, in honor of its BFD foundation.

Why is it the default linker?

Today, the BFD linker (or simply `ld`) remains the default linker on Linux because:

1. Maturity and stability: The BFD linker has been around for a long time (over 25 years now) and has been extensively tested and refined.

2. Feature set: It supports an impressive range of formats, including ELF (Executable and Linkable Format), a.out, COFF, and more.

3. Portability: The BFD linker is designed to be highly portable across various architectures, making it an ideal choice for Linux's diverse hardware ecosystem.

4. Industry adoption: As the default linker on many Linux distributions, including Red Hat Enterprise Linux (RHEL), CentOS, and Fedora, the BFD linker has become a de facto standard.

Other linkers

While `ld` (BFD Linker) is the default linker on most Linux systems, there are other linkers available for specific use cases or architectures:

* gold: A fast and modular linker developed by Red Hat.

* lld: The LLVM Linker, which offers a different approach to linking using the LLVM infrastructure.

These alternatives often coexist alongside `ld` (BFD Linker) in Linux distributions.

Sunday, February 2, 2025

Using ImageMagick AppImage on Windows with WSL

As a developer, you might have encountered situations where you need to manipulate images programmatically. ImageMagick is a powerful command-line tool that provides a wide range of image processing capabilities. However, installing it on Windows can be a bit tricky due to compatibility issues and dependencies. In this blog post, we'll explore how to use ImageMagick AppImage on Windows with WSL (Windows Subsystem for Linux).

What is AppImage?

AppImage is a format that packages an application in a single file, making it easy to distribute and run on various platforms. It's essentially a self-contained bundle of the application, libraries, and dependencies.

Prerequisites

To follow along with this tutorial, you'll need:

1. Windows 10 (or later)

2. WSL (available in Windows 10 Fall Creators Update or later)

3. ImageMagick AppImage file (download from https://www.imagemagick.org/script/download.php)

Step-by-Step Installation and Usage


Step 1: Enable WSL

If you haven't already, enable the WSL feature in Windows:

* Go to `Settings` > `Apps & features`

* Click on `Programs and Features`

* Check the box next to `Windows Subsystem for Linux`


Step 2: Install AppImage Launcher (optional)

While not required, installing the AppImage launcher can make it easier to run your AppImages:

1. Open a new WSL terminal

2. Run `sudo apt-get update && sudo apt-get install appimage-runner`

3. Close the WSL terminal

Step 3: Download and Launch ImageMagick AppImage

Download the ImageMagick AppImage file from https://www.imagemagick.org/script/download.php.

1. Move the downloaded AppImage file to a convenient location, such as your desktop.

2. Open a new WSL terminal

3. Navigate to the directory where you saved the AppImage file (e.g., `cd ~/Desktop`)

4. Run `./Magick-Studio-Q16HD-Q8-x86_64.appimage` (replace with the actual filename and path)

This will launch the ImageMagick application inside WSL.

Step 4: Basic Usage

To verify that ImageMagick is working, try some basic operations:

1. Create a new image:

        * `magic convert -size 800x600 xc:white output.png`

        * This will create an image called `output.png` in the current directory

2. Display an existing image:

        * `magic display input.jpg`

        * This will display the `input.jpg` file using your default image viewer

3. Resize an image:

        * `magic convert input.jpg -resize 50% output-resized.jpg`

These commands demonstrate some basic usage of ImageMagick inside WSL.

Reference links: https://usage.imagemagick.org/basics

Saturday, February 1, 2025

Efficient Photo Compression with ImageMagick AppImage on Ubuntu

 

As a photographer who frequently deals with large batches of high-resolution photos, I've found ImageMagick's AppImage to be an invaluable tool for image compression. Today, I'll show you how to use this powerful utility to compress JPEG files without installing anything system-wide.

Why AppImage?

AppImage is a format for distributing portable software on Linux. Unlike traditional installation methods, AppImage provides a single, self-contained executable that includes all dependencies. This makes ImageMagick incredibly easy to use - just download and run!

Getting Started

  1. First, download the ImageMagick AppImage from the official release page.
    https://imagemagick.org/script/download.php
  2. Make it executable:
    chmod +x ~/Downloads/magick

The Magic Command

Here's the bash script I use for batch compression:

[BASH]
for f in *.JPG ; do echo "compressing $f..." ~/Downloads/magick "$f" -quality 60 "../../magick_output/$f-comp".JPG done

Let's break down what this command does:

  • for f in *.JPG - Loops through all files ending in .JPG in the current directory
  • echo "compressing $f..." - Provides feedback about which file is being processed
  • ~/Downloads/magick - Path to our ImageMagick AppImage
  • -quality 60 - Sets JPEG quality to 60% (adjust this value based on your needs)
  • "../../magick_output/$f-comp".JPG - Saves the compressed file in a separate directory with "-comp" suffix

Choosing the Right Quality Setting

The -quality parameter accepts values from 1 to 100:

  • 100: Maximum quality, minimal compression
  • 80-90: High quality, good compression
  • 60-70: Balanced quality/size ratio
  • Below 50: Noticeable quality loss, maximum compression

I've found that 60 provides an excellent balance between file size reduction and visual quality for most photographs. However, you might want to adjust this based on your specific needs.

Pro Tips

  1. Create Output Directory First: Make sure your output directory exists before running the command:
    mkdir -p ../../magick_output
  2. Preview Before Batch Processing: Test your settings on a single image first:
    ~/Downloads/magick test.JPG -quality 60 test-compressed.JPG
  3. Check File Sizes: Use ls -lh to compare original and compressed file sizes:
    ls -lh original.JPG compressed.JPG

Resource Usage

One of the benefits of using ImageMagick's AppImage is its efficient resource usage. Unlike web-based compression tools, it processes files locally and quickly. On my system, it typically processes a 20MB JPEG file in under a second.


Final thoughts: Remember to always keep backups of your original files before performing batch operations. Happy compressing!