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

JavaScript

JavaScript: Eliminating ‘Cannot read property of undefined’ Errors

- 28.02.26 - ErcanOPAK comment on JavaScript: Eliminating ‘Cannot read property of undefined’ Errors

Deeply nested API responses are dangerous. One missing key crashes your app. Use Optional Chaining. // Old Way const city = user && user.address && user.address.city; // The Pro Way (ES2020) const city = user?.address?.city ?? ‘Unknown’; Why? It’s cleaner, safer, and allows you to provide a default value (Nullish Coalescing) in a single line.

Read More
HTML

HTML5: Building Native Modals with the Element

- 28.02.26 - ErcanOPAK comment on HTML5: Building Native Modals with the Element

Forget heavy JavaScript modal libraries. HTML5 now has a native <dialog> element with a built-in backdrop. This is a native modal! Close Open Pro Advantage: It automatically handles focus management and ‘Escape’ key closing, which is vital for accessibility (A11y).

Read More
CSS

CSS: Solving the ‘Jumping Content’ Problem with aspect-ratio

- 28.02.26 - ErcanOPAK comment on CSS: Solving the ‘Jumping Content’ Problem with aspect-ratio

Before an image loads, the browser doesn’t know its height, causing the layout to ‘jump’ (Cumulative Layout Shift – CLS). This is bad for SEO. .video-container { width: 100%; aspect-ratio: 16 / 9; background: #eee; /* Placeholder */ } The Result: The browser reserves the space before the content arrives, resulting in a smooth, professional […]

Read More
Windows

Windows 11: Enhancing Security with Windows Sandbox

- 28.02.26 - ErcanOPAK comment on Windows 11: Enhancing Security with Windows Sandbox

Want to run a suspicious .exe file without risking your whole system? Use the built-in Windows Sandbox. It creates a lightweight, isolated desktop environment that is completely wiped when you close it. Enable it via Turn Windows features on or off -> Windows Sandbox.

Read More
Windows

Windows 11: Unlocking the Secret ‘God Mode’ Folder

- 28.02.26 - ErcanOPAK comment on Windows 11: Unlocking the Secret ‘God Mode’ Folder

Tired of searching through the new Settings app for old Control Panel items? Enable God Mode. The Fix: Create a new folder on your desktop and name it exactly this: GodMode.{ED7BA470-8E54-465E-825C-99712043E01C} This folder will now contain 200+ settings in one single, searchable list. From disk management to advanced user accounts, everything is at your fingertips.

Read More
AI

AI Prompt: The ‘Hidden Gem’ Travel Concierge

- 28.02.26 - ErcanOPAK comment on AI Prompt: The ‘Hidden Gem’ Travel Concierge

Stop following the same TripAdvisor lists. Get a local’s perspective with AI. The Prompt: “Act as a local travel expert in [City/Country]. I am visiting for [X] days. My interests are [e.g., Brutalist architecture, street food, hidden jazz bars]. 1. Create an itinerary that avoids tourist traps. 2. List 3 ‘hidden gems’ only locals know. […]

Read More
AI

AI Prompt: Architecting Complex Relational Databases

- 28.02.26 - ErcanOPAK comment on AI Prompt: Architecting Complex Relational Databases

Designing a schema is hard. Let AI handle the normalization (1NF, 2NF, 3NF). “Act as a Lead Database Architect. I need a schema for [App Description – e.g., Multi-vendor Marketplace]. 1. Provide the SQL DDL commands. 2. Explain the relationships (One-to-Many, Many-to-Many). 3. Suggest indexes for high-read performance. 4. Create a sample complex JOIN query […]

Read More
AI

AI Prompt: The ‘Rubber Duck’ Debugging Master Class

- 28.02.26 - ErcanOPAK comment on AI Prompt: The ‘Rubber Duck’ Debugging Master Class

When you have a bug that makes no sense, use this prompt to force AI into a deep analytical mode. The Prompt: “I have a bug in my [Language] code: [Paste Code]. It produces [Error/Behavior]. Act as a Senior Debugger. 1. Walk through the code line-by-line and explain the state of variables. 2. Identify potential […]

Read More
Docker

Docker: Reducing Image Size from 1GB to 100MB with Multi-Stage Builds

- 28.02.26 - ErcanOPAK comment on Docker: Reducing Image Size from 1GB to 100MB with Multi-Stage Builds

Why ship the SDK and build tools to production? You only need the compiled binaries. FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build WORKDIR /app COPY . . RUN dotnet publish -c Release -o out FROM mcr.microsoft.com/dotnet/aspnet:8.0 WORKDIR /app COPY –from=build /app/out . ENTRYPOINT [“dotnet”, “MyApp.dll”] The Result: Faster deployments, smaller attack surface, and lower storage costs.

Read More
Kubernetes

Kubernetes: The Critical Difference Between Liveness and Readiness Probes

- 28.02.26 - ErcanOPAK comment on Kubernetes: The Critical Difference Between Liveness and Readiness Probes

Misconfiguring these two can cause your app to go into a restart loop or serve 500 errors to users. Readiness Probe: Tells K8s when the app is ready to receive traffic (e.g., after DB migrations). Liveness Probe: Tells K8s if the app is alive. If this fails, K8s kills and restarts the container. Pro Tip: […]

Read More
Wordpress

WordPress: Creating Professional Custom Post Types Without Plugins

- 28.02.26 - ErcanOPAK comment on WordPress: Creating Professional Custom Post Types Without Plugins

Plugins like CPT UI are great, but adding code to functions.php is cleaner and faster. It prevents unnecessary database queries. register_post_type(‘portfolio’, array( ‘labels’ => array(‘name’ => ‘Portfolios’), ‘public’ => true, ‘has_archive’ => true, ‘supports’ => array(‘title’, ‘editor’, ‘thumbnail’), ‘menu_icon’ => ‘dashicons-portfolio’ )); Why? Native code is easier to version control and doesn’t break during plugin […]

Read More
Wordpress

WordPress: Controlling the Heartbeat API to Save Server CPU

- 28.02.26 - ErcanOPAK comment on WordPress: Controlling the Heartbeat API to Save Server CPU

The WordPress Heartbeat API sends AJAX requests every 15-60 seconds to sync data between the browser and server. While useful, it can consume massive CPU on shared hosting. // Reduce Heartbeat frequency add_action( ‘init’, ‘stop_heartbeat’, 1 ); function stop_heartbeat() { wp_deregister_script(‘heartbeat’); } Recommendation: Instead of disabling it entirely, use a plugin like ‘Heartbeat Control’ to […]

Read More
Photoshop

Photoshop: The Secret to Realistic Texture Cloning with Pattern Stamp

- 28.02.26 - ErcanOPAK comment on Photoshop: The Secret to Realistic Texture Cloning with Pattern Stamp

Stop using the standard Clone Stamp for repetitive textures like grass or brick walls. It looks fake. Instead, define a seamless pattern. Step: Select an area -> Edit -> Define Pattern. Then use the Pattern Stamp Tool with ‘Impressionist’ checked. This creates a natural, non-repetitive organic texture that looks much more professional.

Read More
Photoshop

Photoshop: Using Hollywood Color LUTs for Instant Professional Grading

- 28.02.26 - ErcanOPAK comment on Photoshop: Using Hollywood Color LUTs for Instant Professional Grading

Ever wonder how movies get that consistent ‘teal and orange’ look? They use LUTs (Look-Up Tables). You can use these same files in Photoshop. The Workflow: Add a ‘Color Lookup’ adjustment layer. From the ‘3DLUT File’ dropdown, select ‘Crisp_Warm’ or ‘LateSunset’. Pro Tip: You can export your own color grades as .CUBE files to use […]

Read More
Visual Studio

Visual Studio: Stop the ‘Out of Memory’ Crashes in Large Solutions

- 28.02.26 - ErcanOPAK comment on Visual Studio: Stop the ‘Out of Memory’ Crashes in Large Solutions

If you are working on a solution with 50+ projects, Visual Studio might feel sluggish. The culprit is often the Diagnostic Tools and IntelliCode cache. Pro Hack: Disable ‘Enable Diagnostic Tools while debugging’ in Tools -> Options -> Debugging -> General. This reduces RAM usage by up to 1.5GB during active sessions. For even better […]

Read More
C#

C#: Why You Should Use ‘Records’ for DTOs and API Responses

- 28.02.26 - ErcanOPAK comment on C#: Why You Should Use ‘Records’ for DTOs and API Responses

Standard classes require boilerplate for equality checks. Records provide built-in value-based equality and immutability. public record UserDto(int Id, string Name, string Email); The Result: You get a thread-safe, memory-efficient data carrier in just one line of code. Ideal for modern API development.

Read More
C#

C#: Simplifying Initialization with ??= Operator

- 28.02.26 - ErcanOPAK comment on C#: Simplifying Initialization with ??= Operator

How many times have you written if (x == null) x = new Y();? Modern C# makes this one line. // The shorthand _myList ??= new List(); _myList.Add(“Perfect”); Why? It’s expressive, reduces boilerplate, and makes your intent crystal clear to other developers.

Read More
C#

C#: Reducing Nested Braces with the ‘Using Declaration’

- 28.02.26 - ErcanOPAK comment on C#: Reducing Nested Braces with the ‘Using Declaration’

Stop nesting your code with multiple `using` blocks. Modern C# allows a much cleaner syntax. // Old Way: 2 levels of nesting using (var stream = new FileStream(…)) { using (var reader = new StreamReader(stream)) { … } } // Pro Way: No nesting! using var stream = new FileStream(…); using var reader = new […]

Read More
SQL

SQL: Fixing Slow Queries with Index Rebuilding

- 28.02.26 - ErcanOPAK comment on SQL: Fixing Slow Queries with Index Rebuilding

Even with indexes, your DB can slow down due to Fragmentation. This happens after many Inserts/Deletes. The Pro Check: Run this to rebuild all indexes on a table and reclaim performance: ALTER INDEX ALL ON MyTableName REBUILD;

Read More
SQL

SQL: Making Complex Queries Readable with Common Table Expressions (CTE)

- 28.02.26 - ErcanOPAK comment on SQL: Making Complex Queries Readable with Common Table Expressions (CTE)

Subqueries are hard to read and debug. CTEs allow you to create ‘Virtual Results’ that you can reference easily. WITH HighValueSales AS ( SELECT * FROM Sales WHERE Amount > 1000 ) SELECT p.ProductName, hvs.Amount FROM HighValueSales hvs JOIN Products p ON hvs.ProductId = p.Id;

Read More
Asp.Net Core

.NET Core: Implementing a Global Exception Handler for Clean Controllers

- 28.02.26 - ErcanOPAK comment on .NET Core: Implementing a Global Exception Handler for Clean Controllers

Stop putting try-catch blocks in every controller action. Use the built-in UseExceptionHandler middleware. app.UseExceptionHandler(errorApp => { errorApp.Run(async context => { context.Response.StatusCode = 500; await context.Response.WriteAsJsonAsync(new { Message = “Server Error” }); }); });

Read More
Asp.Net Core

.NET Core: Preventing ‘Captive Dependency’ Memory Leaks

- 28.02.26 - ErcanOPAK comment on .NET Core: Preventing ‘Captive Dependency’ Memory Leaks

A captive dependency occurs when a Singleton service depends on a Scoped service. The Risk: The Scoped service will stay in memory as long as the Singleton lives, causing potential memory leaks or stale data. Pro Tip: Always use IServiceScopeFactory inside singletons to resolve scoped services manually when needed.

Read More
Git

Git: Switching Branches Without Committing Half-Done Work

- 28.02.26 - ErcanOPAK comment on Git: Switching Branches Without Committing Half-Done Work

Your boss wants a quick fix on ‘Main’, but your ‘Feature’ branch is a mess. Use Stash. git stash # Save work to a temporary pile git checkout main # Switch and do the fix git checkout dev # Switch back git stash pop # Bring work back

Read More
Git

Git: How to Fix a Typo in Your Last Commit Message

- 28.02.26 - ErcanOPAK comment on Git: How to Fix a Typo in Your Last Commit Message

Made a typo in your commit? Don’t delete and start over. Use Amend. git commit –amend -m “Your corrected message” Warning: Only use this for commits that haven’t been pushed to a shared repository yet!

Read More
Ajax

Ajax: Handling Network Failures Gracefully with Async/Await

- 28.02.26 - ErcanOPAK comment on Ajax: Handling Network Failures Gracefully with Async/Await

The biggest mistake in Ajax is not catching ‘Silent Failures’ like a 404 or 500 status code. async function fetchData(url) { try { const response = await fetch(url); if (!response.ok) throw new Error(`HTTP Error: ${response.status}`); return await response.json(); } catch (error) { console.error(“Safety Net caught this:”, error); } }

Read More
JavaScript

JavaScript: Cleaner API Consumption with Object Destructuring

- 28.02.26 - ErcanOPAK comment on JavaScript: Cleaner API Consumption with Object Destructuring

Stop checking for null or undefined manually when receiving data from an API. // The Pro Way const { name, role = ‘User’, status = ‘Active’ } = apiResponse; console.log(`${name} is a ${role}`); Why? It makes your code more resilient and readable by providing fallback values directly in the declaration.

Read More
HTML

HTML5: Speed Up Your LCP with Native loading=’lazy’

- 28.02.26 - ErcanOPAK comment on HTML5: Speed Up Your LCP with Native loading=’lazy’

Don’t rely on JavaScript libraries for lazy loading. HTML5 now does it natively. The Result: The browser only downloads these assets when the user is about to scroll to them, saving 60%+ in initial page weight.

Read More
CSS

CSS: Creating a Maintenance-Free Theme with CSS Variables

- 28.02.26 - ErcanOPAK comment on CSS: Creating a Maintenance-Free Theme with CSS Variables

Stop hunting and replacing hex codes. Use :root variables for professional scalability. :root { –primary-color: #3498db; –spacing-unit: 1rem; } .card { padding: var(–spacing-unit); border: 2px solid var(–primary-color); } Result: To change your entire site’s branding, you only edit one line of code.

Read More
Windows

Windows 11: Use ‘Awake’ to Prevent Sleep During Long Tasks

- 28.02.26 - ErcanOPAK comment on Windows 11: Use ‘Awake’ to Prevent Sleep During Long Tasks

Downloading a 100GB file or compiling a giant project? Don’t let Windows sleep. The Fix: Install Microsoft PowerToys and enable ‘Awake’. It adds a small coffee cup icon to your tray that keeps your PC running without changing your global power plan settings.

Read More
Windows

Windows 11: Bringing Back the Classic Right-Click Menu

- 28.02.26 - ErcanOPAK comment on Windows 11: Bringing Back the Classic Right-Click Menu

Many pros hate the ‘Show more options’ click in Windows 11. You can fix it with one registry command. reg add “HKCU\Software\Classes\CLSID\{86ca1aa0-34aa-4e8b-a509-50c905bae2a2}\InprocServer32” /f /ve Restart Explorer, and your productive classic menu is back. No more extra clicks!

Read More
Page 9 of 69
« Previous 1 … 4 5 6 7 8 9 10 11 12 13 14 … 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 (754)
  • 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 (754)

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