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

HTML

HTML5: Use
for Accordion Without JavaScript

- 19.03.26 | 19.03.26 - ErcanOPAK comment on HTML5: Use
for Accordion Without JavaScript

Building FAQ accordion? Writing 50 lines of JavaScript? HTML does it natively. What is HTML5?   HTML5 is the latest version of HTML…     Already expanded   Use ‘open’ attribute to start expanded     Features: Click to expand/collapse. Keyboard accessible. SEO-friendly (content readable by search engines). Style: Use CSS to customize summary arrow, […]

Read More
CSS

CSS: Use :has() for Parent Selectors

- 19.03.26 | 19.03.26 - ErcanOPAK comment on CSS: Use :has() for Parent Selectors

Need to style parent based on child? Impossible in CSS. Was. /* Style form if it has an error */ form:has(.error) { border: 2px solid red; } /* Style card if image is loading */ .card:has(img[loading]) { opacity: 0.5; } /* Style container if checkbox is checked */ .container:has(input:checked) { background: green; } Browser Support: […]

Read More
Windows

Windows 11: Use God Mode for All Settings in One Place

- 19.03.26 - ErcanOPAK comment on Windows 11: Use God Mode for All Settings in One Place

Can’t find setting. Buried 5 menus deep. Annoying. God Mode: All 200+ settings in one folder. Enable: 1. Create new folder on desktop 2. Rename to: GodMode.{ED7BA470-8E54-465E-825C-99712043E01C} 3. Icon changes → Open it Result: Every Windows setting alphabetically listed. No hunting. Tip: Pin to Start or Taskbar for quick access.

Read More
Windows

Windows 11: Use Clipboard History for Multiple Copies

- 19.03.26 | 19.03.26 - ErcanOPAK comment on Windows 11: Use Clipboard History for Multiple Copies

Copy text. Copy another. First one lost. Frustrating. Clipboard History: Stores last 25 items. Enable: Settings → System → Clipboard → Turn on Clipboard history Use: Win + V → Shows clipboard history → Click to paste Pin Items: Pin frequently used text (email signatures, code snippets). They stay forever. Sync: Enable sync to access […]

Read More
AI

AI Prompt: Convert Figma Design to Tailwind Classes

- 19.03.26 | 19.03.26 - ErcanOPAK comment on AI Prompt: Convert Figma Design to Tailwind Classes

Designer sends Figma mockup. You need exact Tailwind classes. [Upload Figma screenshot] Convert this design to Tailwind CSS classes: Provide exact classes for: – Spacing (margin, padding) – Colors (bg, text, border) – Typography (font size, weight, line height) – Layout (flex, grid) – Responsive breakpoints Output as ready-to-use className strings. Result: Copy-paste Tailwind classes. […]

Read More
AI

AI Prompt: Explain Git Conflicts in Plain English

- 19.03.26 | 19.03.26 - ErcanOPAK comment on AI Prompt: Explain Git Conflicts in Plain English

Git conflict appears. Cryptic markers. No idea what to keep. Explain this git conflict: [Paste conflict with <<<<<<< ======= >>>>>>>] Explain in plain English: 1. What each version is trying to do 2. Which version to keep (and why) 3. How to merge them properly 4. The safe resolution I’m not a Git expert, make […]

Read More
AI

AI Prompt: Generate API Documentation from Code

- 19.03.26 | 19.03.26 - ErcanOPAK comment on AI Prompt: Generate API Documentation from Code

Wrote API. Need docs. Don’t want to write manually. Takes hours. Generate API documentation: [Paste code: controllers, models, routes] Format as OpenAPI 3.0 spec with: – Endpoint descriptions – Request/response schemas – Example requests/responses – Error codes – Authentication requirements Make it Postman/Swagger ready. Output: Complete OpenAPI YAML. Import to Swagger UI. Done. Bonus: Ask […]

Read More
Docker

Docker: Use docker system prune to Reclaim Disk Space

- 19.03.26 | 19.03.26 - ErcanOPAK comment on Docker: Use docker system prune to Reclaim Disk Space

Docker using 50GB disk space. Old images, stopped containers, unused volumes everywhere. # Remove everything unused (safe) docker system prune -a # Also remove volumes (careful!) docker system prune -a –volumes # See what will be removed first docker system df What Gets Removed: – Stopped containers – Unused images – Dangling build cache – […]

Read More
Kubernetes

Kubernetes: Use kubectl get events to Debug Pod Issues

- 19.03.26 | 19.03.26 - ErcanOPAK comment on Kubernetes: Use kubectl get events to Debug Pod Issues

Pod won’t start. kubectl describe pod shows nothing useful. What happened? Events: Kubernetes event log shows everything. # All events in namespace kubectl get events –sort-by=’.lastTimestamp’ # Filter by pod kubectl get events –field-selector involvedObject.name=my-pod # Watch live events kubectl get events –watch Common Issues Revealed: – Image pull failures – OOMKilled (out of memory) […]

Read More
Wordpress

WordPress: Use Autoptimize to Minify CSS/JS Without Coding

- 19.03.26 | 19.03.26 - ErcanOPAK comment on WordPress: Use Autoptimize to Minify CSS/JS Without Coding

PageSpeed says ‘Minify CSS/JS’. You don’t know how. Hire developer? $500. Autoptimize Plugin: Free, automatic minification. Install: Plugins → Add New → Autoptimize → Install Settings: ✓ Optimize JavaScript ✓ Optimize CSS ✓ Optimize HTML ✓ Aggregate inline JS/CSS Result: CSS/JS files combined & minified. PageSpeed score +20 points. Advanced: Enable Critical CSS for above-fold […]

Read More
Wordpress

WordPress: Disable Pingbacks to Stop Comment Spam

- 19.03.26 | 19.03.26 - ErcanOPAK comment on WordPress: Disable Pingbacks to Stop Comment Spam

Getting 500 spam comments daily? Most are pingback spam from scrapers. Disable Pingbacks: // functions.php add_filter(‘wp_headers’, function($headers) { unset($headers[‘X-Pingback’]); return $headers; }); add_filter(‘xmlrpc_enabled’, ‘__return_false’); add_filter(‘wp_xmlrpc_server_class’, ‘__return_false’); Settings: Settings → Discussion → Uncheck ‘Allow link notifications from other blogs’ Result: 90% less spam. No legitimate functionality lost.

Read More
Photoshop

Photoshop: Use Smart Objects to Keep Effects Editable

- 19.03.26 | 19.03.26 - ErcanOPAK comment on Photoshop: Use Smart Objects to Keep Effects Editable

Applied filters to layer. Client wants changes. Filters are baked in. Start over. Smart Objects – Non-destructive everything. Convert: Right-click layer → Convert to Smart Object Benefits: – Filters stay editable (Smart Filters) – Resize without quality loss – Edit once, updates everywhere – Preserve original Example: Logo in 10 places. Make logo Smart Object. […]

Read More
Photoshop

Photoshop: Use Layer Comps to Save Multiple Design Variations

- 19.03.26 | 19.03.26 - ErcanOPAK comment on Photoshop: Use Layer Comps to Save Multiple Design Variations

Client wants to see 5 different logo variations. You duplicate the file 5 times. Now edits mean updating 5 files. Layer Comps – Save layer visibility/position states in one file. How: Window → Layer Comps → Create New Layer Comp (saves current layer state) Workflow: 1. Design variation 1 → Save Layer Comp ‘Red Logo’ […]

Read More
Visual Studio

Visual Studio: Use Solution Filters to Load Only What You Need

- 19.03.26 | 19.03.26 - ErcanOPAK comment on Visual Studio: Use Solution Filters to Load Only What You Need

Huge solution with 100 projects? Loading takes 5 minutes. Your PC fans scream. You only need 3 projects. Solution Filters (.slnf) – Load subset of projects. Right-click solution → Create Solution Filter Select only projects you need → Save as MyWork.slnf Open MyWork.slnf instead of full .sln Result: 5 minute load → 20 seconds Use […]

Read More
C#

C#: Use Span for Zero-Allocation String Operations

- 19.03.26 | 19.03.26 - ErcanOPAK comment on C#: Use Span for Zero-Allocation String Operations

🚀 Zero-Copy Strings Substring creates new string (allocation). Span slices without copying. // ❌ Allocates memory string text = “Hello, World!”; string hello = text.Substring(0, 5); // New string // ✅ Zero allocation ReadOnlySpan span = text.AsSpan(); ReadOnlySpan hello = span.Slice(0, 5); // No copy! // Parsing without allocation ReadOnlySpan numbers = “123,456,789”.AsSpan(); var parts […]

Read More
C#

C#: Use required Modifier to Enforce Property Initialization

- 19.03.26 | 19.03.26 - ErcanOPAK comment on C#: Use required Modifier to Enforce Property Initialization

✅ Compile-Time Validation Forget to set a property? Null reference exception at runtime. Required modifier catches at compile time. // C# 11+ public class User { public required string Name { get; init; } public required string Email { get; init; } public string? Phone { get; init; } // Optional } // ✅ Valid […]

Read More
C#

C#: Use Pattern Matching with switch Expressions

- 19.03.26 | 19.03.26 - ErcanOPAK comment on C#: Use Pattern Matching with switch Expressions

🎯 Modern Switch Old switch statements verbose. Switch expressions compact, powerful. // Old way string result; switch (value) { case 1: result = “One”; break; case 2: result = “Two”; break; default: result = “Other”; break; } // Modern way var result = value switch { 1 => “One”, 2 => “Two”, _ => “Other” […]

Read More
C#

C#: Use init Accessors for Immutable Objects with Object Initializers

- 19.03.26 | 19.03.26 - ErcanOPAK comment on C#: Use init Accessors for Immutable Objects with Object Initializers

🔒 Immutable + Flexible Readonly properties need constructor parameters. Init accessors let you use object initializers. // C# 9+ public class User { public int Id { get; init; } public string Name { get; init; } public string Email { get; init; } } // Can set during initialization var user = new User […]

Read More
SQL

SQL: Use CROSS APPLY for Correlated Subqueries Performance

- 19.03.26 | 19.03.26 - ErcanOPAK comment on SQL: Use CROSS APPLY for Correlated Subqueries Performance

⚡ Faster Correlated Queries Correlated subqueries in SELECT run for every row. CROSS APPLY runs once. — ❌ SLOW (subquery runs per row) SELECT c.Name, (SELECT TOP 1 OrderDate FROM Orders WHERE CustomerId = c.CustomerId ORDER BY OrderDate DESC) AS LastOrder FROM Customers c; — ✅ FAST (CROSS APPLY optimized) SELECT c.Name, o.OrderDate FROM Customers […]

Read More
SQL

SQL: Use CTEs for Readable Complex Queries

- 19.03.26 | 19.03.26 - ErcanOPAK comment on SQL: Use CTEs for Readable Complex Queries

📖 Readable SQL Nested subqueries hurt readability. CTEs (Common Table Expressions) make complex queries clear. — Clear, readable, step-by-step WITH ActiveUsers AS ( SELECT * FROM Users WHERE IsActive = 1 ), RecentOrders AS ( SELECT * FROM Orders WHERE CreatedAt > DATEADD(month, -1, GETDATE()) ) SELECT u.Name, COUNT(o.OrderId) AS OrderCount FROM ActiveUsers u LEFT […]

Read More
Asp.Net Core

.NET Core: Use IHostedService for Startup/Shutdown Logic

- 19.03.26 | 19.03.26 - ErcanOPAK comment on .NET Core: Use IHostedService for Startup/Shutdown Logic

🎬 Lifecycle Hooks Run code on app start/stop. Warm cache, close connections cleanly. public class StartupService : IHostedService { public async Task StartAsync(CancellationToken cancellationToken) { // Runs when app starts await WarmCacheAsync(); await CheckDatabaseConnectionAsync(); } public async Task StopAsync(CancellationToken cancellationToken) { // Runs when app stops (graceful shutdown) await FlushLogsAsync(); await CloseConnectionsAsync(); } } // […]

Read More
Asp.Net Core

.NET Core: Use IMemoryCache for In-Memory Caching Without Redis

- 19.03.26 | 19.03.26 - ErcanOPAK comment on .NET Core: Use IMemoryCache for In-Memory Caching Without Redis

⚡ Built-in Cache Redis overkill for small apps. IMemoryCache built into .NET. Zero config. // Startup services.AddMemoryCache(); // Usage public class UserService { private readonly IMemoryCache _cache; public async Task GetUserAsync(int id) { return await _cache.GetOrCreateAsync( $”user-{id}”, async entry => { entry.AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(5); return await _db.Users.FindAsync(id); } ); } } When It’s Enough: Single […]

Read More
Git

Git: Use git reflog to Recover Deleted Commits

- 19.03.26 | 19.03.26 - ErcanOPAK comment on Git: Use git reflog to Recover Deleted Commits

💾 Git’s Time Machine Accidentally deleted branch? Reset to wrong commit? Reflog saves you. # View all HEAD movements (last 90 days) git reflog # Output shows: # abc1234 HEAD@{0}: reset: moving to HEAD~1 # def5678 HEAD@{1}: commit: Important work ← You want this! # Restore that commit git checkout def5678 git checkout -b recovery-branch […]

Read More
Git

Git: Use git bisect to Find Bug-Introducing Commit in Minutes

- 19.03.26 | 19.03.26 - ErcanOPAK comment on Git: Use git bisect to Find Bug-Introducing Commit in Minutes

🔍 Binary Search for Bugs Bug appeared somewhere in last 100 commits. Which one? Bisect finds it in 7 tries (log₂ 100). git bisect start git bisect bad # Current commit has bug git bisect good abc1234 # This old commit was fine # Git checks out middle commit # You test: does bug exist? […]

Read More
Ajax

AJAX: Use FormData to Upload Files with Progress

- 19.03.26 | 19.03.26 - ErcanOPAK comment on AJAX: Use FormData to Upload Files with Progress

📤 File Upload with Progress Bar Upload files + show progress. Native browser API. No libraries. const formData = new FormData(); formData.append(‘file’, fileInput.files[0]); formData.append(‘userId’, ‘123’); const xhr = new XMLHttpRequest(); // Progress tracking xhr.upload.addEventListener(‘progress’, (e) => { const percent = (e.loaded / e.total) * 100; progressBar.style.width = percent + ‘%’; }); xhr.open(‘POST’, ‘/upload’); xhr.send(formData); With […]

Read More
JavaScript

JavaScript: Use AbortController to Cancel Fetch Requests

- 19.03.26 | 19.03.26 - ErcanOPAK comment on JavaScript: Use AbortController to Cancel Fetch Requests

🛑 Cancel In-Flight Requests User navigates away mid-request. Old request completes, updates wrong page. Prevent this. const controller = new AbortController(); fetch(‘/api/data’, { signal: controller.signal }) .then(res => res.json()) .catch(err => { if (err.name === ‘AbortError’) { console.log(‘Request cancelled’); } }); // User navigates away controller.abort(); // Cancels request React Hook: Use in useEffect cleanup. […]

Read More
HTML

HTML5: Use for Autocomplete Without JavaScript

- 19.03.26 | 19.03.26 - ErcanOPAK comment on HTML5: Use for Autocomplete Without JavaScript

📝 Native Autocomplete Building autocomplete dropdown? No React Select needed. HTML does it natively. Dynamic Options: Populate datalist with JavaScript/API. Still native rendering. Browser Support: 97% (all modern browsers). Benefit: Zero bytes JavaScript, accessible by default, mobile keyboard optimized.

Read More
CSS

CSS: Use @layer to Control Cascade Order Without !important

- 19.03.26 - ErcanOPAK comment on CSS: Use @layer to Control Cascade Order Without !important

🎯 Cascade Control !important is tech debt. @layer organizes CSS priority cleanly. @layer reset, base, components, utilities; @layer reset { * { margin: 0; padding: 0; } } @layer base { body { font-family: sans-serif; } } @layer components { .button { background: blue; } } @layer utilities { .mt-4 { margin-top: 1rem; } } […]

Read More
Windows

Windows 11: Use Focus Sessions with Spotify Integration

- 19.03.26 - ErcanOPAK comment on Windows 11: Use Focus Sessions with Spotify Integration

⏱️ Built-in Pomodoro Timer Clock app now has focus timer + Spotify playlists. Free productivity app built into Windows. Use: Clock app → Focus Sessions Features: 25-minute timer, break reminders, daily goal tracking, Spotify integration (auto-plays focus playlists). DND Mode: Turns on Do Not Disturb automatically during session. Track Progress: Daily/weekly stats show total focus […]

Read More
Windows

Windows 11: Use Virtual Desktops for Context-Separated Workflows

- 19.03.26 - ErcanOPAK comment on Windows 11: Use Virtual Desktops for Context-Separated Workflows

🖥️ Multiple Workspaces One desktop for work, one for personal, one for each project. Switch instantly. Create: Win + Tab → New Desktop Switch: Ctrl + Win + Left/Right Arrow Move Window: Win + Tab → Drag window to desktop My Setup: Desktop 1: Code (VS Code + terminals) Desktop 2: Design (Figma + Photoshop) […]

Read More
Page 4 of 69
« Previous 1 2 3 4 5 6 7 8 9 … 69 Next »

Posts navigation

Older posts
Newer posts
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 (950)
  • How to add default value for Entity Framework migrations for DateTime and Bool (858)
  • Get the First and Last Word from a String or Sentence in SQL (836)
  • How to select distinct rows in a datatable in C# (805)
  • How to make theater mode the default for Youtube (752)
  • 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 (531)
  • How to use Map Mode for Vertical Scroll Mode in Visual Studio (489)
  • Find numbers with more than two decimal places in SQL (447)

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 (950)
  • How to add default value for Entity Framework migrations for DateTime and Bool (858)
  • Get the First and Last Word from a String or Sentence in SQL (836)
  • How to select distinct rows in a datatable in C# (805)
  • How to make theater mode the default for Youtube (752)

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