Category Archives: Snippets

Git Pull

git pull fetches commits from a remote repository and merges them into your current local branch. It’s actually two commands in one — git fetch followed by a merge (or rebase, depending on configuration) — which is exactly why modern Git insists you tell it which reconciliation strategy you want. This is the tenth post in this site’s Git command guide, following Git Push.

Continue reading Git Pull

Git Add

git add is the command that stages changes from your working directory into Git’s index, marking them to be included in the next commit. Staging is an intermediate step that gives you precise control — you can add one file at a time, leaving other modified files unstaged until a later commit. This is the third post in this site’s Git command guide, following Git Clone.

Continue reading Git Add

Git Init

git init is the command that turns an ordinary folder into a Git repository. It creates a hidden .git subdirectory containing the object database, refs, and config that Git needs to start tracking history. You only run it once per project — after that, every git add and git commit writes into that same .git directory. This is the first post in this site’s Git command guide, so if you’re setting up a brand-new project, this is where you start.

Continue reading Git Init

Implementing JPEG Algorithm in Java

The JPEG (Joint Photographic Experts Group) compression standard is the most widely used format for digital photographs on the web. Unlike lossless codecs, JPEG achieves very high compression ratios by discarding perceptually insignificant information from the image. At its core, the algorithm transforms pixel data into the frequency domain, aggressively quantises the high-frequency components (which the human eye is less sensitive to), and then encodes the result efficiently.

This Java program demonstrates the key computational stages of JPEG compression applied to a single 8×8 pixel block: the Discrete Cosine Transform (DCT), quantisation, zigzag scan, and a simplified entropy encoding step.

This example provides an educational look at the key stages of JPEG compression.

JPEG Compression Pipeline

A real JPEG encoder processes an image in the following sequence. This program implements all four stages for one 8×8 luminance block:

  1. Input block — An 8×8 grid of pixel intensity values.
  2. DCT — Converts spatial pixel data into frequency-domain coefficients.
  3. Quantisation — Divides each DCT coefficient by a value from the standard luminance quantisation table and rounds to the nearest integer, discarding fine detail.
  4. Zigzag scan — Reorders the 8×8 quantised coefficients into a 1D array, placing the most significant low-frequency coefficients first.
  5. Entropy encoding — Encodes the 1D array using a simplified run-length + binary scheme similar to the actual JPEG Huffman coding step.
Continue reading Implementing JPEG Algorithm in Java

Implementing Run Length Encoding in Java

Run-Length Encoding (RLE) is one of the simplest lossless data compression techniques. Instead of storing every character individually, it replaces consecutive runs of the same character with a single instance of that character preceded by a count. For example, the string AAABBC becomes 3A2B1C. RLE works best on data with long repeated runs, such as bitmap images or binary sequences, and is often used as a preprocessing step in more sophisticated codecs like JPEG and fax compression standards.

This Java program reads a string from the user, applies RLE compression using hexadecimal run-length counts, and reports the encoded output along with the original length, encoded length, and the resulting compression ratio.

Continue reading Implementing Run Length Encoding in Java