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

Day: May 28, 2026

C#

C#: Use Native AOT to Compile .NET Apps to Single Executables

- 28.05.26 - ErcanOPAK comment on C#: Use Native AOT to Compile .NET Apps to Single Executables

๐Ÿ“ฆ One .exe, No Runtime Required .NET app needs runtime installed. Native AOT compiles to single native executable. Fast startup, small container size, no .NET on target machine. ๐Ÿ”ง Enable Native AOT <PropertyGroup> <PublishAot>true</PublishAot> </PropertyGroup> <PropertyGroup> <TargetFramework>net8.0</TargetFramework> <PublishAot>true</PublishAot> <JsonSerializerIsReflectionEnabledByDefault>false</JsonSerializerIsReflectionEnabledByDefault> <TrimMode>full</TrimMode> </PropertyGroup> โš™๏ธ Publish Command # Windows (x64) dotnet publish -c Release -r win-x64 –self-contained -p:PublishAot=true […]

Read More
C#

C#: Use Span for High-Performance Memory Access Without Allocation

- 28.05.26 - ErcanOPAK comment on C#: Use Span for High-Performance Memory Access Without Allocation

โšก Zero-Allocation Slicing Span<T> gives a view into memory without copying. No allocations, no GC pressure. Ideal for parsing, string manipulation, and high-performance scenarios. โŒ Allocating Substring // Allocates new string (GC pressure) string data = “123,456,789”; string first = data.Substring(0, 3); // New string allocation string second = data.Substring(4, 3); // Another allocation // […]

Read More
SQL

SQL: Use Partial Indexes to Index Only Relevant Rows

- 28.05.26 - ErcanOPAK comment on SQL: Use Partial Indexes to Index Only Relevant Rows

๐ŸŽฏ Index Only What You Query Full indexes waste space. Partial indexes index only rows matching a WHERE clause. Smaller, faster, more efficient. ๐Ÿ“ Basic Partial Index — Index only active users (not soft-deleted) CREATE INDEX idx_active_users_email ON users(email) WHERE deleted_at IS NULL; — Query uses this index automatically SELECT * FROM users WHERE email […]

Read More
Asp.Net Core

.NET Core: Understanding Middleware Order (It Matters!)

- 28.05.26 - ErcanOPAK comment on .NET Core: Understanding Middleware Order (It Matters!)

๐Ÿ”„ Order of Registration = Order of Execution Wrong middleware order = broken app. Auth before Routing? Exception handling after everything? Order matters dramatically. โœ… Correct Order (Recommended) var app = builder.Build(); // 1. Exception handling (catch errors from everything) if (app.Environment.IsDevelopment()) app.UseDeveloperExceptionPage(); else app.UseExceptionHandler(“/error”); // 2. Security (run early) app.UseHsts(); app.UseHttpsRedirection(); // 3. Static […]

Read More
Git

Git: Use Reflog to Recover Deleted Commits and Branches

- 28.05.26 - ErcanOPAK comment on Git: Use Reflog to Recover Deleted Commits and Branches

๐Ÿ•ฐ๏ธ Git’s Time Machine Accidentally deleted branch? Reset –hard too far? Reflog logs every HEAD change. Rewind time, recover lost work. ๐Ÿ“ View Reflog # View all reflog entries git reflog # Output: # a1b2c3d HEAD@{0}: commit: Add feature # d4e5f6g HEAD@{1}: checkout: moving from main to feature # g7h8i9j HEAD@{2}: reset: moving to HEAD~2 […]

Read More
Ajax

Ajax: Use FormData API for File Uploads Without Libraries

- 28.05.26 - ErcanOPAK comment on Ajax: Use FormData API for File Uploads Without Libraries

๐Ÿ“ Drag & Drop + Progress Bar, Native No more FormData polyfills. FormData API sends forms + files with fetch. Track upload progress, handle multiple files. ๐Ÿ“ Basic File Upload <input type=”file” id=”fileInput” multiple> <button onclick=”uploadFiles()”>Upload</button> <progress id=”progressBar” value=”0″ max=”100″></progress> async function uploadFiles() { const files = document.getElementById(‘fileInput’).files; const formData = new FormData(); for (let […]

Read More
JavaScript

JavaScript: Use Top-Level Await in Modules for Cleaner Async Code

- 28.05.26 | 28.05.26 - ErcanOPAK comment on JavaScript: Use Top-Level Await in Modules for Cleaner Async Code

โฐ Async Without Async Function Wrapper Need await at top level? Used to need IIFE. Top-level await works directly in ES modules. Cleaner initialization code. โŒ Old Way (IIFE) (async () => { const data = await fetch(‘/api/config’); const config = await data.json(); startApp(config); })(); โœ… Top-Level Await // In .mjs or type=”module” script const […]

Read More
HTML

HTML: Use Native Dialog Element for Modals Without JavaScript Libraries

- 28.05.26 - ErcanOPAK comment on HTML: Use Native Dialog Element for Modals Without JavaScript Libraries

๐Ÿ“ฑ Built-in Modal, No Library <dialog> element creates native modals. Accessibility, focus management, backdrop โ€” all built-in. No more 100KB modal libraries. ๐Ÿ“ Basic Dialog <dialog id=”myDialog”> <h2>Confirm Action</h2> <p>Are you sure you want to delete this item?</p> <form method=”dialog”> <button value=”cancel”>Cancel</button> <button value=”confirm”>Confirm</button> </form> </dialog> <button onclick=”myDialog.showModal()”>Open Modal</button> <script> myDialog.addEventListener(‘close’, () => { console.log(‘Closed […]

Read More
CSS

CSS: Use :has() Selector to Style Parent Elements Based on Children

- 28.05.26 - ErcanOPAK comment on CSS: Use :has() Selector to Style Parent Elements Based on Children

๐Ÿ‘จโ€๐Ÿ‘ง Parent Finally Knows About Child CSS couldn’t select parent based on children. Until now. :has() changes everything โ€” style parent when child exists. โŒ Before :has() // JavaScript needed if (card.querySelector(‘.badge’)) { card.classList.add(‘has-badge’); } โœ… With :has() // Pure CSS! .card:has(.badge) { border-left: 4px solid gold; } ๐ŸŽฏ Powerful Examples // Style form that […]

Read More
Windows

Windows 11: Use Focus Sessions to Eliminate Distractions

- 28.05.26 - ErcanOPAK comment on Windows 11: Use Focus Sessions to Eliminate Distractions

๐Ÿง˜ Built-In Pomodoro Timer Notifications, taskbar badges, flashing icons โ€” all distractions. Focus Sessions silence everything, set timers, track productivity. ๐Ÿ”ง Start a Focus Session Method 1: Clock app โ†’ Focus Sessions Method 2: Taskbar clock/calendar โ†’ Focus Method 3: Settings โ†’ System โ†’ Focus Shortcut: Win + N โ†’ Focus โš™๏ธ Configure Do Not […]

Read More
AI

AI Prompt: Analyze Log Files and Identify Error Patterns

- 28.05.26 - ErcanOPAK comment on AI Prompt: Analyze Log Files and Identify Error Patterns

๐Ÿ” AI Reads Your Logs So You Don’t Have To Thousand lines of logs. One needle in haystack. AI log analysis finds patterns, clusters errors, suggests fixes. ๐Ÿ“ Log Analysis Prompt Analyze these application logs and: 1. Identify the most frequent errors (top 5) 2. Find patterns in timestamps (does error spike at specific times?) […]

Read More
Docker

Docker: Add Health Checks to Detect Unhealthy Containers

- 28.05.26 - ErcanOPAK comment on Docker: Add Health Checks to Detect Unhealthy Containers

โค๏ธ Is Your Container Actually Working? Container running but app crashed? Health checks test if app is responsive. Automatically restart unhealthy containers. ๐Ÿ“ Dockerfile Healthcheck # Web app HEALTHCHECK –interval=30s –timeout=3s –start-period=5s –retries=3 \ CMD curl -f http://localhost/ || exit 1 # Database HEALTHCHECK –interval=30s –timeout=10s –retries=5 \ CMD pg_isready -U postgres || exit 1 […]

Read More
Kubernetes

Kubernetes: Use Network Policies to Restrict Pod Communication

- 28.05.26 - ErcanOPAK comment on Kubernetes: Use Network Policies to Restrict Pod Communication

๐Ÿ”’ Zero Trust for Pods By default, all pods can talk to all pods. That’s a security risk. Network policies define who can talk to whom. ๐Ÿ“ Deny All Ingress apiVersion: networking.k8s.io/v1 kind: NetworkPolicy metadata: name: deny-all-ingress spec: podSelector: {} # Applies to all pods policyTypes: – Ingress ingress: [] # Empty = deny all […]

Read More
Wordpress

WordPress: Create Custom URL Structures with Rewrite Rules

- 28.05.26 - ErcanOPAK comment on WordPress: Create Custom URL Structures with Rewrite Rules

๐Ÿ”— Beautiful URLs for Everything Want /events/2024/summer-festival instead of /?post_type=event&event_id=123? Rewrite rules create clean, SEO-friendly URLs. ๐Ÿ“ Basic Rewrite Rule function add_custom_rewrite_rules() { add_rewrite_rule( ‘^events/([0-9]{4})/([^/]+)/?$’, ‘index.php?post_type=event&year=$matches[1]&event_slug=$matches[2]’, ‘top’ ); } add_action(‘init’, ‘add_custom_rewrite_rules’); // Add query vars function add_query_vars($vars) { $vars[] = ‘year’; $vars[] = ‘event_slug’; return $vars; } add_filter(‘query_vars’, ‘add_query_vars’); // Flush rules after adding (visit […]

Read More
Photoshop

Photoshop: Use Adjustment Layers for Non-Destructive Color Correction

- 28.05.26 - ErcanOPAK comment on Photoshop: Use Adjustment Layers for Non-Destructive Color Correction

๐ŸŽจ Edit Colors Without Destroying Pixels Direct color changes = permanent. Adjustment layers sit above your image. Toggle on/off, change settings anytime, never lose original. ๐ŸŒ… Levels Adjust shadows, midtones, highlights. Fix underexposed or washed-out images. ๐ŸŽจ Hue/Saturation Change color cast, boost vibrance, or completely recolor specific ranges. ๐Ÿ“Š Curves Precise tonal control. Professional-grade color […]

Read More
Visual Studio

Visual Studio: Automate Code Formatting with Code Cleanup Profiles

- 28.05.26 - ErcanOPAK comment on Visual Studio: Automate Code Formatting with Code Cleanup Profiles

๐Ÿงน One Click, Whole File Formatted Remove unused usings, sort imports, fix spacing, apply conventions โ€” all automatically. Code Cleanup saves hours of manual formatting. ๐Ÿ”ง Set Up Profile Analyze โ†’ Code Cleanup โ†’ Configure Create profiles: – “Full Cleanup”: Remove/sort usings, format document, apply file header – “Quick Fix”: Only remove usings + format […]

Read More
May 2026
M T W T F S S
 123
45678910
11121314151617
18192021222324
25262728293031
« Mar   Jun »

Most Viewed Posts

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

Recent Posts

  • C#: Use String Interpolation Instead of Concatenation
  • C#: Use Tuples to Return Multiple Values from Methods
  • SQL: Use ISNULL and NULLIF for Smart NULL Handling
  • .NET Core: Use Data Annotations for Model Validation
  • Git: Use Git Clean to Remove Untracked Files
  • Ajax: Add Custom Headers to Fetch Requests
  • JavaScript: Use console.table to Display Arrays as Tables
  • HTML: Use Spellcheck Attribute to Enable Browser Spell Check
  • CSS: Use user-select to Prevent Text Selection
  • Windows 11: Use Snipping Tool for Instant Screenshots

Most Viewed Posts

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

Recent Posts

  • C#: Use String Interpolation Instead of Concatenation
  • C#: Use Tuples to Return Multiple Values from Methods
  • SQL: Use ISNULL and NULLIF for Smart NULL Handling
  • .NET Core: Use Data Annotations for Model Validation
  • Git: Use Git Clean to Remove Untracked Files

Social

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