Validation throwing generic ‘Value cannot be null’ messages? CallerArgumentExpression shows which argument failed. Old Generic Message: public void ProcessUser(User user) { if (user == null) throw new ArgumentNullException(nameof(user)); // Error: “user cannot be null” – not very helpful in complex code } With CallerArgumentExpression: public void ThrowIfNull(T value, [CallerArgumentExpression(“value”)] string? paramName = null) { if […]
Day: February 14, 2026
C#: Use Tuple Deconstruction in foreach for Dictionary Iteration
Dictionary foreach with KeyValuePair is verbose. Tuple deconstruction makes it clean. Old Verbose Way: var scores = new Dictionary { [“Alice”] = 95, [“Bob”] = 87, [“Charlie”] = 92 }; foreach (KeyValuePair kvp in scores) { Console.WriteLine($”{kvp.Key}: {kvp.Value}”); } Clean Deconstruction: foreach (var (name, score) in scores) { Console.WriteLine($”{name}: {score}”); } // Or with types: […]
C#: Use var Pattern in Switch Expressions for Type Matching
Checking object types with multiple if-else is messy. Switch expressions with type patterns are cleaner. Old If-Else Chain: object obj = GetData(); if (obj is string s) { Console.WriteLine($”String: {s.Length} chars”); } else if (obj is int i) { Console.WriteLine($”Number: {i * 2}”); } else if (obj is List list) { Console.WriteLine($”List: {list.Count} items”); } […]
SQL: Use TRY_CAST Instead of CAST to Avoid Conversion Errors
CAST throws error on invalid data. TRY_CAST returns NULL instead – safer for user input. CAST – Throws Error: SELECT CAST(‘123’ AS INT); — Works: 123 SELECT CAST(‘abc’ AS INT); — Error: Conversion failed! — Query crashes, returns nothing TRY_CAST – Returns NULL: SELECT TRY_CAST(‘123’ AS INT); — Returns: 123 SELECT TRY_CAST(‘abc’ AS INT); — […]
SQL: Use ISNULL vs COALESCE Correctly for Best Performance
Both replace NULL values but work differently. ISNULL is faster, COALESCE is more flexible. ISNULL – SQL Server Specific: — Takes exactly 2 arguments, returns first if not null SELECT ISNULL(MiddleName, ”) AS MiddleName FROM Users; — Faster – compiled inline — Data type from first argument COALESCE – ANSI Standard: — Takes 2+ arguments, […]
.NET Core: Use BackgroundService for Long-Running Tasks
Need background job in your ASP.NET app? BackgroundService is built-in – no Hangfire or Quartz needed. Create Background Service: public class EmailCleanupService : BackgroundService { protected override async Task ExecuteAsync(CancellationToken stoppingToken) { while (!stoppingToken.IsCancellationRequested) { // Do work await CleanupOldEmails(); // Wait 1 hour await Task.Delay(TimeSpan.FromHours(1), stoppingToken); } } private async Task CleanupOldEmails() { // […]
.NET Core: Use IConfiguration.GetValue for Type-Safe Config Reading
Parsing config strings manually is error-prone. GetValue handles conversion automatically. Manual Parsing (Error-Prone): // appsettings.json: “MaxRetries”: “3” var maxRetries = int.Parse(_config[“MaxRetries”]); // NullReferenceException if key missing! // FormatException if value is not a number! Type-Safe GetValue: var maxRetries = _config.GetValue(“MaxRetries”, defaultValue: 5); // Returns 3 if exists // Returns 5 if missing or invalid // […]
Git: Use git blame -L to See Who Changed Specific Lines
Whole file blame is overwhelming. See only who changed specific lines you care about. Blame Specific Line Range: # See who changed lines 50-60 git blame -L 50,60 file.js # See who changed from line 100 to end git blame -L 100,+1000 file.js Ignore Whitespace Changes: # Ignore commits that only changed indentation git blame […]
Git: Use git commit –fixup to Easily Amend Older Commits
Found a typo in commit from 5 commits ago? –fixup marks it for automatic squashing later. Create Fixup Commit: # Find commit hash to fix git log –oneline # abc1234 Add user authentication # def5678 Add email validation ← Want to fix this # Make your fix, then: git add . git commit –fixup def5678 […]
AJAX: Use URLSearchParams to Build Query Strings Cleanly
Manually concatenating query strings is error-prone. URLSearchParams handles encoding and formatting automatically. Messy Manual Way: const query = ‘?name=’ + encodeURIComponent(name) + ‘&email=’ + encodeURIComponent(email) + ‘&age=’ + age; fetch(‘/api/users’ + query); // Easy to forget encoding, messy to read Clean URLSearchParams Way: const params = new URLSearchParams({ name: ‘John Doe’, email: ‘john@example.com’, age: 30 […]
JavaScript: Use replaceAll() Instead of regex.replace() for Simple Text Replacement
Replacing all occurrences with regex is overkill. replaceAll() is simpler and more readable. Old Regex Way: const text = “Hello World, Hello Universe”; const result = text.replace(/Hello/g, “Hi”); // “Hi World, Hi Universe” // Easy to mess up – forget ‘g’ flag and only first is replaced! New replaceAll() Way: const text = “Hello World, […]
HTML5: Use dialog Element for Native Modals Without JavaScript Libraries
Bootstrap modals require heavy JavaScript. HTML5 dialog element is native, lightweight, and fully accessible. HTML: <dialog id=”myDialog”> <h2>Modal Title</h2> <p>Modal content here</p> <button onclick=”closeDialog()”>Close</button> </dialog> <button onclick=”openDialog()”>Open Modal</button> JavaScript: function openDialog() { document.getElementById(‘myDialog’).showModal(); } function closeDialog() { document.getElementById(‘myDialog’).close(); } // Close on backdrop click myDialog.addEventListener(‘click’, (e) => { if (e.target === myDialog) myDialog.close(); }); Features: […]
CSS: Use clamp() for Responsive Font Sizes Without Media Queries
Setting font sizes for mobile, tablet, desktop with media queries is tedious. clamp() does it automatically. Old Way – Multiple Media Queries: h1 { font-size: 24px; } @media (min-width: 768px) { h1 { font-size: 32px; } } @media (min-width: 1200px) { h1 { font-size: 48px; } } New Way – One Line: h1 { font-size: […]
Windows 11: Use Quick Settings to Toggle Wi-Fi, Bluetooth Without Opening Settings
Opening Settings app to toggle Wi-Fi is slow. Quick Settings panel gives instant access to common toggles. Open Quick Settings: Click Wi-Fi/Sound/Battery icons in system tray Or press Win + A Quick Toggles Available: Wi-Fi on/off Bluetooth on/off Airplane mode Battery saver Night light Focus assist Screen brightness slider Volume slider Customize: Click pencil icon […]
Windows 11: Use God Mode to Access All Settings in One Folder
Tired of hunting through Settings app? God Mode creates folder with every Windows setting in one place. Enable God Mode: 1. Right-click Desktop → New → Folder 2. Name it exactly: GodMode.{ED7BA470-8E54-465E-825C-99712043E01C} 3. Press Enter Folder icon changes and opens to show 300+ settings organized by category! What’s Inside: Administrative Tools Backup and Restore Color […]
AI Prompt: Create Excel Formulas from Description of What You Want to Calculate
Excel formulas syntax confusing? Describe what you want in plain English, get working formula. The Prompt: Create Excel formula for: I have: – Column A: Product names – Column B: Prices – Column C: Quantities sold I want in Column D: Total revenue (price × quantity), but only for products starting with “Pro-” If quantity […]
AI Prompt: Generate SQL Queries from Plain English Descriptions
Know what data you need but struggling with SQL syntax? AI writes the query for you. The Prompt: Write SQL query for this: Database: Ecommerce Tables: Users (id, name, email), Orders (id, user_id, total, created_at) I need: Top 10 customers by total order value in last 30 days Also explain what each part does. AI […]
Docker: UseHealthCheck to Auto-Restart Unhealthy Containers
Container running but app inside crashed? Add HEALTHCHECK to auto-detect and restart failed containers. Add to Dockerfile: FROM node:18 WORKDIR /app COPY . . # Check if app responds on port 3000 HEALTHCHECK –interval=30s –timeout=3s –retries=3 \ CMD curl -f http://localhost:3000/health || exit 1 CMD [“node”, “server.js”] What Happens: Every 30 seconds, Docker runs health […]
Kubernetes: Use kubectl top to Monitor Real-Time Resource Usage
Want to see CPU/Memory usage without installing monitoring tools? kubectl top shows real-time stats. Node Resource Usage: kubectl top nodes # Output: # NAME CPU MEMORY # node-1 45% 2.5Gi # node-2 23% 1.8Gi Pod Resource Usage: kubectl top pods # Or specific namespace: kubectl top pods -n production # Sort by CPU: kubectl top […]
WordPress: Show Different Menus to Logged-In vs Logged-Out Users
Want different navigation for members vs visitors? WordPress has built-in conditional menu display. Create Two Menus: Appearance → Menus 1. “Public Menu” (for visitors) 2. “Member Menu” (for logged-in users) Add to functions.php: function conditional_menu() { if (is_user_logged_in()) { wp_nav_menu(array(‘theme_location’ => ‘member-menu’)); } else { wp_nav_menu(array(‘theme_location’ => ‘public-menu’)); } } In header.php, replace: <?php wp_nav_menu(); […]
WordPress: Add Custom Login Logo Without Plugin Using functions.php
Want branded login page? Add custom logo with a few lines of code – no plugin needed. Add to functions.php: function custom_login_logo() { echo ‘<style type=”text/css”> #login h1 a { background-image: url(‘ . get_stylesheet_directory_uri() . ‘/images/logo.png); background-size: contain; width: 300px; height: 100px; } </style>’; } add_action(‘login_enqueue_scripts’, ‘custom_login_logo’); Change Logo URL: function custom_login_url() { return home_url(); […]
Photoshop: Use Blend If to Remove White/Black Backgrounds Without Selecting
Magic wand selection leaving halos? Blend If removes backgrounds based on brightness – no selection needed. Remove White Background: 1. Double-click layer to open Layer Style 2. Find “Blend If” section at bottom 3. Drag This Layer white slider left 4. White pixels become transparent! For Smoother Transition: Hold Alt while dragging to split slider […]
Photoshop: Use Layer Comps to Save Multiple Design Variations in One File
Creating multiple mockup versions in separate files? Layer Comps saves different layer visibility/position states in one PSD. Create Layer Comp: Window → Layer Comps → Click ‘Create New Layer Comp’ icon Choose What to Save: Visibility (which layers are on/off) Position (where layers are located) Appearance (layer styles) Use Case Example: Designing website header with […]
Visual Studio: Use Multi-Caret Editing to Change Multiple Lines at Once
Editing same text on multiple lines one by one is tedious. Multi-caret lets you edit all simultaneously. Add Carets: Hold Alt + Click where you want additional cursors Or Select Multiple: 1. Select text 2. Press Ctrl+D repeatedly to select next occurrence 3. Type to change all at once Example: // Change all ‘firstName’ to […]
























