~/calcsnippets _

Dev / Geek / Code

A collection of technical snippets, algorithms, and developer resources. Optimized for copy-paste efficiency.

ls -la ./featured
Algorithms 1024 bytes

Binary Search: The Algorithm You Must Know

Binary search is the cornerstone of efficient searching. Understand O(log n) complexity and how to implement it correctly without bugs.

rw-r--r-- 2025-12-12
CSS 1024 bytes

CSS Grid vs Flexbox: When to Use Which?

Confused about whether to use Grid or Flexbox? Here is a simple rule of thumb: Flexbox for one dimension, Grid for two dimensions.

rw-r--r-- 2025-12-10
cat ./featured/snippet.py
binary_search.py
def binary_search(arr, target):
    left, right = 0, len(arr) - 1
    
    while left <= right:
        mid = (left + right) // 2
        if arr[mid] == target:
            return mid
        elif arr[mid] < target:
            left = mid + 1
        else:
            right = mid - 1
            
    return -1