Skip to content

Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy

Author: ErcanOPAK

Git

Git: Use git blame -L to Find Who Wrote Specific Lines

- 19.03.26 - ErcanOPAK comment on Git: Use git blame -L to Find Who Wrote Specific Lines

๐Ÿ” Who Wrote This Code? Bug in production. Need to know who wrote line 247. git blame tells you author, date, commit. Basic Usage # Entire file git blame filename.js # Specific line range git blame -L 100,150 filename.js # Show line 247 only git blame -L 247,247 filename.js # Output: # abc12345 (John Doe […]

Read More
Git

Git: Use Interactive Rebase to Clean Up Commit History

- 19.03.26 - ErcanOPAK comment on Git: Use Interactive Rebase to Clean Up Commit History

โœจ Rewrite Git History Like a Pro 10 messy commits saying ‘fix’, ‘oops’, ‘wtf’. Interactive rebase turns them into one clean, professional commit. Start Interactive Rebase # Rebase last 5 commits git rebase -i HEAD~5 # Or from specific commit git rebase -i abc1234 # Editor opens with commit list: pick abc1234 Add login feature […]

Read More
Ajax

AJAX: Implement Exponential Backoff for Failed Requests

- 19.03.26 - ErcanOPAK comment on AJAX: Implement Exponential Backoff for Failed Requests

๐Ÿ”„ Handle Network Failures Gracefully Request fails. You retry immediately. Fails again. Server overwhelmed. Exponential backoff fixes this. The Pattern async function fetchWithRetry(url, options = {}, maxRetries = 3) { for (let i = 0; i = 500 || response.status === 429) { if (i === maxRetries) throw new Error(‘Max retries reached’); // Exponential backoff: […]

Read More
JavaScript

JavaScript: Use Optional Chaining (?.) to Avoid Nested If Checks

- 19.03.26 - ErcanOPAK comment on JavaScript: Use Optional Chaining (?.) to Avoid Nested If Checks

๐Ÿ”— Access Deep Properties Safely Tired of user && user.address && user.address.city? Optional chaining makes it user?.address?.city The Old Nightmare // โŒ Verbose null checking const city = user && user.address && user.address.city; // โŒ Even worse with functions const result = obj && obj.method && obj.method(); // โŒ Nested ternaries const name = data […]

Read More
HTML

HTML5: Use for Art Direction and Responsive Images

- 19.03.26 - ErcanOPAK comment on HTML5: Use for Art Direction and Responsive Images

๐Ÿ–ผ๏ธ Serve Perfect Image for Every Device Desktop gets landscape. Mobile gets portrait. WebP for modern browsers, JPEG fallback. <picture> handles it all. Basic Responsive Images Art Direction (Different Crops) ๐ŸŽฏ Advanced: Resolution + Format ๐Ÿ’ก Why Use <picture>? Performance: Serve WebP (30% smaller) to supporting browsers Art Direction: Show different crops on different screens […]

Read More
CSS

CSS: Use clamp() for Responsive Typography Without Media Queries

- 19.03.26 - ErcanOPAK comment on CSS: Use clamp() for Responsive Typography Without Media Queries

๐Ÿ“ Fluid Typography That Just Works Writing 5 media queries for font sizes? clamp() does it in one line. Responsive typography perfected. The Old Way (Painful) h1 { font-size: 24px; } @media (min-width: 640px) { h1 { font-size: 32px; } } @media (min-width: 768px) { h1 { font-size: 40px; } } @media (min-width: 1024px) { […]

Read More
Windows

Windows 11: Use Quick Settings for One-Click System Controls

- 19.03.26 - ErcanOPAK comment on Windows 11: Use Quick Settings for One-Click System Controls

โšก Control Panel Reinvented WiFi, Bluetooth, volume, brightness – all in one swipe. Quick Settings is your new command center. Access: Win + A (or click WiFi/Volume/Battery icons in taskbar) ๐ŸŽ›๏ธ Quick Toggles WiFi on/off + network selector Bluetooth + device pairing Volume slider + output device Brightness slider Focus Assist (DND) Night Light Airplane […]

Read More
Windows

Windows 11: Use Snap Layouts for Instant Window Organization

- 19.03.26 - ErcanOPAK comment on Windows 11: Use Snap Layouts for Instant Window Organization

๐Ÿ“ Organize Windows in One Click Dragging windows to resize them? Slow. Snap Layouts give you 6 pre-made layouts instantly. How to Use: Hover over maximize button โ†’ Choose layout โ†’ Click zone for each window ๐Ÿ“ฑ Available Layouts 2 columns: 50/50 split (classic side-by-side) 3 columns: Equal thirds or 50/25/25 4 corners: Each window […]

Read More
AI

AI Prompt: Generate Complex Regex Patterns in Plain English

- 19.03.26 - ErcanOPAK comment on AI Prompt: Generate Complex Regex Patterns in Plain English

๐Ÿ”ค Regex Without the Pain Need to validate email? Extract phone numbers? Parse log files? Describe it in English, AI writes the regex. The Regex Prompt Create a regex pattern that matches: [Describe what you want to match] Requirements: – Provide the regex pattern – Explain each part of the pattern – Give 5 examples […]

Read More
AI

AI Prompt: Generate Unit Tests with 90% Coverage Instantly

- 19.03.26 - ErcanOPAK comment on AI Prompt: Generate Unit Tests with 90% Coverage Instantly

๐Ÿงช Write Tests 100x Faster Writing tests is tedious. AI generates comprehensive test suites in seconds. Edge cases included. The Test Generation Prompt Generate comprehensive unit tests for this code: [Paste your function/class] Requirements: – Use [Testing Framework: Jest/xUnit/pytest/etc] – Test happy path – Test edge cases (null, empty, invalid input) – Test error conditions […]

Read More
AI

AI Prompt: Get Senior-Level Code Reviews Instantly

- 19.03.26 - ErcanOPAK comment on AI Prompt: Get Senior-Level Code Reviews Instantly

๐Ÿ‘จโ€๐Ÿ’ป Your Personal Senior Developer No senior dev on team? AI reviews your code like one. Security holes, performance issues, best practices – all caught instantly. The Ultimate Code Review Prompt Review this code as a senior developer: [Paste your code] Check for: 1. Security vulnerabilities (SQL injection, XSS, secrets in code) 2. Performance issues […]

Read More
Docker

Docker: Use .dockerignore to Speed Up Builds 10x

- 19.03.26 - ErcanOPAK comment on Docker: Use .dockerignore to Speed Up Builds 10x

๐Ÿš€ Stop Copying Unnecessary Files Docker copying 2GB node_modules to build context? .dockerignore file fixes this. Without .dockerignore: Docker copies ENTIRE directory to build context. With .dockerignore: Copies only what you need. Essential .dockerignore # .dockerignore file node_modules npm-debug.log dist build .git .env .DS_Store *.md .vscode .idea coverage __pycache__ *.pyc .pytest_cache โšก Impact Before Build […]

Read More
Kubernetes

Kubernetes: Use kubectl port-forward to Debug Services Locally

- 19.03.26 - ErcanOPAK comment on Kubernetes: Use kubectl port-forward to Debug Services Locally

๐Ÿ”Œ Access K8s Services Like They’re Local Service running in cluster. Need to test it. Don’t want to expose it publicly. Port-forward to localhost. Basic Port Forward # Forward pod port to localhost kubectl port-forward pod/my-pod 8080:80 # Now access: http://localhost:8080 # Traffic goes to pod’s port 80 # Forward service instead kubectl port-forward svc/my-service […]

Read More
Wordpress

WordPress Transients: Cache Data Without a Plugin

- 19.03.26 - ErcanOPAK comment on WordPress Transients: Cache Data Without a Plugin

โšก Built-in Caching System API call taking 2 seconds? Database query slow? Cache it with Transients API. No plugin needed. Basic Usage // Get from cache $data = get_transient(‘my_cached_data’); // Not in cache? Get fresh data if (false === $data) { $data = expensive_api_call(); // Store for 1 hour (3600 seconds) set_transient(‘my_cached_data’, $data, HOUR_IN_SECONDS); } […]

Read More
Wordpress

WordPress Query Monitor: Debug Performance Issues in Real Time

- 19.03.26 - ErcanOPAK comment on WordPress Query Monitor: Debug Performance Issues in Real Time

๐Ÿ” X-Ray Vision for WordPress Site slow? Don’t know why? Query Monitor shows every database query, hook, HTTP request in real time. Install: Plugins โ†’ Add New โ†’ Query Monitor โ†’ Free, 100K+ active installs What It Shows โœ… Database Queries: Slow queries highlighted, execution time, duplicate queries โœ… PHP Errors: Notices, warnings, fatal errors […]

Read More
Photoshop

Photoshop Liquify: Reshape Anything Without Destroying Pixels

- 19.03.26 - ErcanOPAK comment on Photoshop Liquify: Reshape Anything Without Destroying Pixels

๐ŸŒ€ Warp Reality with Liquify Push, pull, twist, pinch any part of image. Non-destructive. Undo anytime. Liquify is Photoshop’s secret weapon. Access: Filter โ†’ Liquify (or Shift+Ctrl+X) Essential Tools ๐Ÿ–Œ๏ธ Forward Warp Push pixels in any direction. Main tool for reshaping. ๐Ÿ”„ Twirl Clockwise Create spiral effects. Hold for continuous twist. ๐Ÿ“ Pucker Pinch pixels […]

Read More
Photoshop

Photoshop Content-Aware Fill: Remove Anything From Photos Like Magic

- 19.03.26 - ErcanOPAK comment on Photoshop Content-Aware Fill: Remove Anything From Photos Like Magic

โœจ Photoshop’s AI-Powered Eraser Tourist photobombing your perfect shot? Unwanted object ruining composition? Content-Aware Fill removes it seamlessly. Traditional method: Clone Stamp tool for 30 minutes, still looks fake. Content-Aware: Select object, fill, done in 10 seconds. How It Works 3-Step Process Select unwanted object: Use Lasso Tool (L) to outline Edit โ†’ Fill: Choose […]

Read More
Visual Studio

Visual Studio 2022: Hot Reload – The Feature That Changes Everything

- 19.03.26 - ErcanOPAK comment on Visual Studio 2022: Hot Reload – The Feature That Changes Everything

๐Ÿ”ฅ Edit Running Code Without Restarting Change code while debugging. See results instantly. No stop. No rebuild. No restart. This is Hot Reload. What Is Hot Reload? Traditional workflow: Edit code โ†’ Stop debugger โ†’ Rebuild โ†’ Restart โ†’ Navigate back to same screen. 2-5 minutes lost per change. Hot Reload workflow: Edit code โ†’ […]

Read More
C#

C#: Use CallerArgumentExpression for Better Error Messages

- 19.03.26 | 19.03.26 - ErcanOPAK comment on C#: Use CallerArgumentExpression for Better Error Messages

ArgumentNullException says ‘parameter is null’. Which parameter? // Old way – manual parameter name public void Process(User user) { if (user == null) throw new ArgumentNullException(nameof(user)); } // New way – automatic! (C# 10+) public void Process(User user) { ArgumentNullException.ThrowIfNull(user); // Error message includes actual expression: ‘user’ } // Custom validation public void ValidatePositive( int […]

Read More
C#

C#: Use Target-Typed new for Cleaner Code

- 19.03.26 | 19.03.26 - ErcanOPAK comment on C#: Use Target-Typed new for Cleaner Code

Type name repeated on both sides. Redundant. // โŒ Verbose Dictionary<string, List> dict = new Dictionary<string, List>(); // โœ… Target-typed new (C# 9+) Dictionary<string, List> dict = new(); // Works everywhere List users = new(); var service = new UserService(); return new User { Name = “John” }; // Field initialization private readonly HttpClient _client […]

Read More
C#

C#: Use global using to Import Namespaces Once

- 19.03.26 | 19.03.26 - ErcanOPAK comment on C#: Use global using to Import Namespaces Once

Every file: using System.Linq; using System.Collections.Generic; Global Usings: Import once, available everywhere. // Create Usings.cs global using System; global using System.Linq; global using System.Collections.Generic; global using Microsoft.EntityFrameworkCore; // Now all files in project have these // No need to repeat in every file Implicit Global Usings: Enable in .csproj: enable Common namespaces auto-imported.

Read More
C#

C#: Use File-Scoped Namespaces to Reduce Indentation

- 19.03.26 | 19.03.26 - ErcanOPAK comment on C#: Use File-Scoped Namespaces to Reduce Indentation

Entire file indented one level for namespace. Wasted space. // โŒ Old way (extra indentation) namespace MyApp.Services { public class UserService { public void DoSomething() { // Code here } } } // โœ… File-scoped namespace (C# 10+) namespace MyApp.Services; public class UserService { public void DoSomething() { // Code here – one less indent […]

Read More
SQL

SQL: Use OFFSET FETCH for Pagination

- 19.03.26 | 19.03.26 - ErcanOPAK comment on SQL: Use OFFSET FETCH for Pagination

Building pagination? OFFSET FETCH is standard SQL way. — Page 1 (rows 1-10) SELECT * FROM Products ORDER BY ProductId OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY; — Page 2 (rows 11-20) SELECT * FROM Products ORDER BY ProductId OFFSET 10 ROWS FETCH NEXT 10 ROWS ONLY; — Dynamic pagination DECLARE @PageNumber INT = […]

Read More
SQL

SQL: Use COALESCE to Handle NULL Values

- 19.03.26 | 19.03.26 - ErcanOPAK comment on SQL: Use COALESCE to Handle NULL Values

NULL values breaking calculations? Use COALESCE for fallback. — Returns first non-NULL value SELECT COALESCE(Phone, Email, ‘No contact’) AS Contact FROM Users; — Default values in calculations SELECT Name, Price * COALESCE(Quantity, 0) AS Total FROM Orders; — Multiple fallbacks SELECT COALESCE(PreferredName, FirstName, ‘Unknown’) AS DisplayName FROM Users; vs ISNULL: COALESCE is ANSI standard (works […]

Read More
Asp.Net Core

.NET Core: Use Health Checks for Monitoring

- 19.03.26 | 19.03.26 - ErcanOPAK comment on .NET Core: Use Health Checks for Monitoring

How do you know if your API is healthy? Database connected? Redis alive? // Program.cs builder.Services.AddHealthChecks() .AddDbContextCheck() .AddRedis(“localhost:6379”); app.MapHealthChecks(“/health”); // Visit /health // Response: Healthy or Unhealthy + details Custom Check: public class ApiHealthCheck : IHealthCheck { public async Task CheckHealthAsync(…) { var isHealthy = await CheckExternalApiAsync(); return isHealthy ? HealthCheckResult.Healthy() : HealthCheckResult.Unhealthy(“API down”); } […]

Read More
Asp.Net Core

.NET Core: Use Response Caching Middleware for Static APIs

- 19.03.26 | 19.03.26 - ErcanOPAK comment on .NET Core: Use Response Caching Middleware for Static APIs

API returns same data for 10 minutes. Still hitting database every request. // Program.cs builder.Services.AddResponseCaching(); var app = builder.Build(); app.UseResponseCaching(); // Controller [ResponseCache(Duration = 600)] // 10 minutes public IActionResult GetProducts() { return Ok(_db.Products.ToList()); } Headers: Sets Cache-Control headers automatically. Browser + server cache. Vary: Cache different responses per user: VaryByHeader = “Authorization” Disable: [ResponseCache(NoStore […]

Read More
Git

Git: Use git cherry-pick to Copy Commits Between Branches

- 19.03.26 | 19.03.26 - ErcanOPAK comment on Git: Use git cherry-pick to Copy Commits Between Branches

Fixed bug in wrong branch. Need same fix in another branch. Don’t want to merge entire branch. # Switch to target branch git checkout main # Cherry-pick specific commit from other branch git cherry-pick abc1234 # Cherry-pick multiple commits git cherry-pick abc1234 def5678 ghi9012 # Cherry-pick range git cherry-pick abc1234..def5678 Conflicts: If conflict occurs, resolve […]

Read More
Git

Git: Use git stash -p to Stash Specific Changes

- 19.03.26 | 19.03.26 - ErcanOPAK comment on Git: Use git stash -p to Stash Specific Changes

Made 10 changes. Want to stash only 3. git stash takes everything. # Interactive stash (choose what to stash) git stash -p # Git asks for each change: # Stash this hunk? y/n/q/a/d/e y = yes, stash this n = no, keep this q = quit a = stash all remaining d = don’t stash […]

Read More
Ajax

AJAX: Use fetch() timeout with AbortController

- 19.03.26 | 19.03.26 - ErcanOPAK comment on AJAX: Use fetch() timeout with AbortController

Request hangs forever. No timeout in fetch API. Need manual solution. const controller = new AbortController(); const timeoutId = setTimeout(() => controller.abort(), 5000); try { const response = await fetch(url, { signal: controller.signal }); clearTimeout(timeoutId); return await response.json(); } catch (error) { if (error.name === ‘AbortError’) { console.log(‘Request timeout’); } } Reusable Function: async function […]

Read More
JavaScript

JavaScript: Use structuredClone for Deep Object Copy

- 19.03.26 | 19.03.26 - ErcanOPAK comment on JavaScript: Use structuredClone for Deep Object Copy

Deep cloning objects? JSON.parse(JSON.stringify()) fails on dates, functions, undefined. // โŒ Old way (loses dates, functions) const copy = JSON.parse(JSON.stringify(original)); // โœ… New way (preserves everything) const copy = structuredClone(original); // Works with: // – Nested objects // – Arrays // – Dates // – Maps, Sets // – RegExp // – ArrayBuffer Performance: Faster […]

Read More
Page 3 of 69
ยซ Previous 1 2 3 4 5 6 7 8 … 69 Next ยป

Posts pagination

« Previous 1 2 3 4 5 … 69 Next »
April 2026
M T W T F S S
 12345
6789101112
13141516171819
20212223242526
27282930  
« Mar    

Most Viewed Posts

  • Get the User Name and Domain Name from an Email Address in SQL (951)
  • How to add default value for Entity Framework migrations for DateTime and Bool (868)
  • Get the First and Last Word from a String or Sentence in SQL (837)
  • How to select distinct rows in a datatable in C# (806)
  • How to make theater mode the default for Youtube (757)
  • Add Constraint to SQL Table to ensure email contains @ (578)
  • How to enable, disable and check if Service Broker is enabled on a database in SQL Server (564)
  • Average of all values in a column that are not zero in SQL (535)
  • How to use Map Mode for Vertical Scroll Mode in Visual Studio (491)
  • Find numbers with more than two decimal places in SQL (449)

Recent Posts

  • C#: Use Init-Only Setters for Immutable Objects After Construction
  • C#: Use Expression-Bodied Members for Concise Single-Line Methods
  • C#: Enable Nullable Reference Types to Eliminate Null Reference Exceptions
  • C#: Use Record Types for Immutable Data Objects
  • SQL: Use CTEs for Readable Complex Queries
  • SQL: Use Window Functions for Advanced Analytical Queries
  • .NET Core: Use Background Services for Long-Running Tasks
  • .NET Core: Use Minimal APIs for Lightweight HTTP Services
  • Git: Use Cherry-Pick to Apply Specific Commits Across Branches
  • Git: Use Interactive Rebase to Clean Up Commit History Before Merge

Most Viewed Posts

  • Get the User Name and Domain Name from an Email Address in SQL (951)
  • How to add default value for Entity Framework migrations for DateTime and Bool (868)
  • Get the First and Last Word from a String or Sentence in SQL (837)
  • How to select distinct rows in a datatable in C# (806)
  • How to make theater mode the default for Youtube (757)

Recent Posts

  • C#: Use Init-Only Setters for Immutable Objects After Construction
  • C#: Use Expression-Bodied Members for Concise Single-Line Methods
  • C#: Enable Nullable Reference Types to Eliminate Null Reference Exceptions
  • C#: Use Record Types for Immutable Data Objects
  • SQL: Use CTEs for Readable Complex Queries

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter
© 2026 Bits of .NET | Built with Xblog Plus free WordPress theme by wpthemespace.com