[] Instead of new List { } Python has [1,2,3]. C# finally gets collection expressions! Same syntax for arrays, lists, spans. More readable, less typing. โ Old Way (Verbose) int[] arr = new int[] { 1, 2, 3 }; List list = new List { “a”, “b”, “c” }; Span span = new int[] { […]
Day: May 30, 2026
C#: Use Primary Constructors to Reduce Boilerplate (.NET 8)
๐ฏ Dependency Injection Just Got Cleaner private readonly ILogger _logger; + constructor = 4 lines. Primary constructors do it in 1 line. C# 12 changes everything. โ Old Way (12 lines) public class OrderService { private readonly IOrderRepository _repository; private readonly ILogger _logger; private readonly IEmailService _emailService; public OrderService( IOrderRepository repository, ILogger logger, IEmailService emailService) […]
SQL: Use UPSERT (INSERT ON CONFLICT) for Insert or Update
๐ One Query: Insert or Update Check if exists โ Update or Insert = 2 queries. UPSERT does it in one. Faster, atomic, race-condition free. ๐ PostgreSQL (ON CONFLICT) — Basic UPSERT (update if conflict) INSERT INTO users (id, name, email, last_login) VALUES (1, ‘Alice’, ‘alice@example.com’, NOW()) ON CONFLICT (id) DO UPDATE SET name = […]
.NET Core: Implement API Versioning Without Breaking Clients
๐ V1, V2, V3 โ All Running Simultaneously Change API = break clients. API versioning lets you run multiple versions. Old clients stay on V1, new clients use V2. No downtime. ๐ Setup Versioning dotnet add package Asp.Versioning.Mvc dotnet add package Asp.Versioning.Mvc.ApiExplorer // Program.cs builder.Services.AddApiVersioning(options => { options.DefaultApiVersion = new ApiVersion(1, 0); options.AssumeDefaultVersionWhenUnspecified = true; […]
Git: Create Custom Aliases for Frequently Used Commands
โก git st โ git status Typing ‘git status –short –branch’ every time? Git aliases create shortcuts. Save keystrokes, create powerful composite commands. ๐ Create Aliases # Basic aliases git config –global alias.st status git config –global alias.co checkout git config –global alias.br branch git config –global alias.ci commit git config –global alias.df diff git […]
Ajax: Use EventSource for Real-Time Server Push (Simpler than WebSockets)
๐ก One-Way Real-Time Updates Need live updates but not bidirectional? EventSource (SSE) is simpler than WebSockets. Auto-reconnects. Built-in retry. Perfect for dashboards, notifications. ๐ Client-Side const eventSource = new EventSource(‘/api/events’); // Listen for messages eventSource.onmessage = (event) => { const data = JSON.parse(event.data); console.log(‘Update:’, data); updateUI(data); }; // Listen for specific event type eventSource.addEventListener(‘notification’, (event) […]
JavaScript: Use Object.groupBy() to Group Arrays Without Lodash
๐ Native GroupBy Finally Arrived _.groupBy() required Lodash. Object.groupBy() is now native. Group arrays by any criteria. No more manual reduce hacks. ๐ Basic Usage const users = [ { name: ‘Alice’, role: ‘admin’ }, { name: ‘Bob’, role: ‘user’ }, { name: ‘Charlie’, role: ‘admin’ }, { name: ‘Diana’, role: ‘user’ } ]; // […]
HTML: Use Input Pattern Attribute for Client-Side Validation
โ๏ธ Validate Without JavaScript pattern attribute validates input with regex. Built-in error messages, no JS needed. Works on mobile keyboards too. ๐ Common Patterns <!– US Phone Number –> <input type=”tel” pattern=”[0-9]{3}-[0-9]{3}-[0-9]{4}” placeholder=”123-456-7890″> <!– Zip Code (US) –> <input type=”text” pattern=”[0-9]{5}(-[0-9]{4})?” placeholder=”12345″> <!– Username (letters, numbers, underscore) –> <input type=”text” pattern=”[A-Za-z0-9_]{3,20}” title=”3-20 characters: letters, numbers, […]
CSS: Use Aspect Ratio for Perfectly Sized Boxes
๐ No More Padding Hack Remember padding-bottom: 56.25% for 16:9? aspect-ratio property does it natively. Videos, images, cards โ perfect proportions. ๐ Basic Usage /* Square */ .square { aspect-ratio: 1 / 1; background: blue; width: 200px; } /* 16:9 video container */ .video-container { aspect-ratio: 16 / 9; background: black; width: 100%; } /* […]
Windows 11: Use Focus Assist to Block Notifications While Working
๐ Silence the Distractions Every Slack ping breaks flow. Focus Assist hides all notifications during focus time. Only priority contacts get through. ๐ง Enable Focus Assist Settings โ System โ Focus Assist Three modes: – Off: All notifications (default) – Priority only: Only from specified contacts/apps – Alarms only: No notifications except alarms Quick toggle: […]
AI Prompt: Generate Unit Tests from Function Signatures
๐งช AI Writes Your Tests Writing tests is tedious. AI generates unit tests from function signatures. Edge cases, error handling, happy paths โ all covered. ๐ The Prompt Generate comprehensive unit tests for this function: [Paste function code here] Testing framework: [Jest / pytest / NUnit / xUnit] Language: [JavaScript / Python / C# / […]
Docker: Use Prune Commands to Reclaim Gigabytes of Disk Space
๐๏ธ Your Disk is Full of Dead Containers Stopped containers, unused images, unused volumes โ they eat disk space. docker system prune cleans everything in one command. ๐ Prune Commands # Clean everything (containers, images, networks, build cache) docker system prune -a –volumes # Stop and remove all stopped containers docker container prune # Remove […]
Kubernetes: Use Resource Quotas to Prevent One Namespace from Draining Cluster
๐ Don’t Let One Team Hog All Resources One namespace uses all CPU? Others starve. Resource quotas limit total CPU, memory, storage per namespace. Fair sharing for multi-tenant clusters. ๐ Basic Quota apiVersion: v1 kind: ResourceQuota metadata: name: namespace-quota namespace: development spec: hard: requests.cpu: “4” requests.memory: “8Gi” limits.cpu: “8” limits.memory: “16Gi” persistentvolumeclaims: “10” pods: “20” […]
WordPress: Create Custom Widget Areas with register_sidebar()
๐ฆ Drag-and-Drop Everywhere Widgets only in sidebar? Not anymore. register_sidebar() creates widget areas anywhere: header, footer, after content, before comments. ๐ Register Sidebars // functions.php function custom_widget_areas() { // Footer widget area register_sidebar(array( ‘name’ => ‘Footer Widget Area’, ‘id’ => ‘footer-widgets’, ‘description’ => ‘Appears at the bottom of every page’, ‘before_widget’ => ”, ‘after_widget’ => […]
Photoshop: Use Layer Groups to Organize Complex Designs
๐ 100 Layers? Collapse Them! Scrolling through endless layers is a nightmare. Layer Groups organize related layers. Collapse, rename, color-code, apply effects to entire group. ๐ Create Layer Group Method 1: Layer โ New โ Group (Ctrl + G) Method 2: Select multiple layers โ Ctrl + G Method 3: Drag layers onto folder icon […]
Visual Studio: Navigate Backward (Ctrl + -) Like a Time Machine
โช Ctrl + – Takes You Back to Where You Were Jumped to definition? Scrolled away? Navigate Backward (Ctrl + -) returns to your previous cursor position. Like a browser back button for your code. โจ๏ธ Shortcuts Ctrl + – โ Navigate Backward (go to previous cursor location) Ctrl + Shift + – โ Navigate […]
C#: Use Interpolated String Handler for High-Performance Logging
โก Zero Allocation Until You Log Logging with string interpolation allocates memory even when log level is off. Interpolated string handlers defer formatting until needed. โ Regular Interpolation (Always Allocates) // Even if log level is Error and this is Debug // string is still allocated! _logger.LogDebug($”User {userId} logged in at {DateTime.Now}”); // 2 allocations: […]
C#: Use Throw Helpers for Concise Null Checks (.NET 6+)
๐ฏ One Line Null Check if (arg == null) throw new ArgumentNullException(nameof(arg)); is so 2019. Throw helpers do it in one line. Less code, fewer bugs. โ Old Way (4 lines) public void Process(string name, int? age) { if (name == null) throw new ArgumentNullException(nameof(name)); if (age == null) throw new ArgumentNullException(nameof(age)); // Logic here […]
SQL: Use Window Frame Clauses for Running Totals and Moving Averages
๐ ROWS BETWEEN Is the Secret Sauce Running total? Moving average? Cumulative sum? Window frame clauses define exactly which rows to include. Powerful analytics in pure SQL. ๐ Running Total (Cumulative Sum) SELECT order_date, amount, SUM(amount) OVER ( ORDER BY order_date ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW ) AS running_total FROM orders; — UNBOUNDED […]
.NET Core: Use Output Caching to Cache Entire API Responses
โก 1000x Faster with One Attribute Same endpoint called repeatedly? Database query every time? Output caching stores HTTP responses. One line of code, huge performance. ๐ง Setup (.NET 7+) // Program.cs builder.Services.AddOutputCache(); app.UseOutputCache(); // Controller [ApiController] [Route(“api/[controller]”)] public class ProductsController : ControllerBase { [HttpGet] [OutputCache(Duration = 60)] // Cache for 60 seconds public async Task […]
Git: Use Git Grep to Search History Faster Than grep
๐ Search Only Tracked Files, Faster grep searches everything, including .git folder. git grep searches only tracked files. Respects .gitignore. Much faster. ๐ Basic Search # Search for word in tracked files git grep “functionName” # Search with line numbers git grep -n “TODO” # Search with context (2 lines before/after) git grep -B 2 […]
Ajax: Use Web Workers for CPU-Intensive Tasks Without Freezing UI
โ๏ธ Heavy Math? Don’t Block UI! JavaScript runs on main thread. Long loops freeze the page. Web Workers run in background threads. UI stays responsive. ๐ Basic Worker // main.js const worker = new Worker(‘worker.js’); worker.postMessage({ data: largeArray, operation: ‘process’ }); worker.onmessage = (event) => { console.log(‘Result:’, event.data); updateUI(event.data); }; worker.onerror = (error) => { […]
JavaScript: Use Intl API for Native Date, Number, and String Localization
๐ No More Moment.js Dates, numbers, currencies, plurals โ all have different formats per locale. Intl API is built-in. No libraries needed. ๐ Date Formatting const date = new Date(); // US English new Intl.DateTimeFormat(‘en-US’).format(date); // “12/31/2024” // UK English new Intl.DateTimeFormat(‘en-GB’).format(date); // “31/12/2024” // German new Intl.DateTimeFormat(‘de-DE’).format(date); // “31.12.2024” // Japanese new Intl.DateTimeFormat(‘ja-JP’).format(date); // […]
HTML: Use Contenteditable to Make Any Element Editable
โ๏ธ Edit Any Element Like a Text Editor Need inline editing? contenteditable makes any element editable. divs, spans, whole pages. Like a text editor on the web. ๐ Basic Usage <div contenteditable=”true”> Click me and edit this text directly! </div> <h1 contenteditable=”true”>Editable Title</h1> <p contenteditable=”true”> This paragraph can be edited by users. Great for notes, […]
CSS: Use Logical Properties for International Layouts
๐ margin-left breaks in RTL languages Arabic, Hebrew read right-to-left. CSS Logical Properties use ‘inline’ and ‘block’ instead of ‘left’ and ‘right’. Works for any language. โ Physical Properties .sidebar { margin-left: 20px; padding-right: 10px; text-align: left; border-left: 1px solid; } // In RTL, all these are wrong! โ Logical Properties .sidebar { margin-inline-start: 20px; […]
Windows 11: Use Storage Spaces to Combine Multiple Drives
๐พ JBOD โ RAID Without Hardware Multiple external drives? Different sizes? Storage Spaces pools them together. Add mirroring, parity, or just combine capacity. ๐ Create Storage Pool Control Panel โ Storage Spaces โ Create a new pool Or PowerShell: # List available disks Get-PhysicalDisk | Where-Object CanPool -eq $True # Create pool New-StoragePool -FriendlyName “MediaPool” […]
Docker: Build Images for Multiple Architectures (AMD64 + ARM64)
๐ณ One Build, All Architectures Intel Mac, Apple Silicon, ARM servers, AMD servers โ different architectures. Docker Buildx builds for all from a single machine. ๐ง Setup Buildx # Create new builder instance (supports multiple platforms) docker buildx create –name multiarch –use # Bootstrap builder docker buildx inspect –bootstrap # Verify platforms docker buildx ls […]
Kubernetes: Use Taints and Tolerations to Control Pod Placement
๐ซ Dedicated Nodes for Special Workloads Some nodes have GPUs. Some are spot instances. Taints repel pods. Tolerations allow them. Control exactly where workloads run. ๐ Add Taint to Node # Taint effects: # NoSchedule: Pods without toleration won’t be scheduled # PreferNoSchedule: Avoid if possible # NoExecute: Evict existing pods without toleration # Add […]
WordPress: Control Autoloaded Options to Speed Up Admin
โก 80% of Options Load on Every Page WordPress loads all ‘autoload’ options on every request. Many are never used. Clean your autoloaded options for faster admin. ๐ Check Autoloaded Options — SQL Query to see autoloaded options SELECT COUNT(*), SUM(LENGTH(option_value)) as total_size FROM wp_options WHERE autoload = ‘yes’; — List largest autoloaded options SELECT […]













