Posts

Showing posts from 2025

Deploy Azure Verified Modules using Azure CLI (Bicep)

Step 1.  First lets create a simple parameters file that will hold the main parameters we need for our infrastructure. Resouce group Name Location {     "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",     "contentVersion": "1.0.0.0",     "parameters": {       "resourceGroupName": {         "value": "ResourceGroupName"       },       "location": {         "value": "westus2"       }     }   }  Step 2. Next lets define some resources in main.bicep Resource Group Azure Keyvault Storage Account Azure Static App Server Farm (for function app) Function App targetScope = 'subscription' param location string param resourceGroupName string param deploySecrets bool = true // Condition to deploy secrets param deployKeys bool = true // Condition to deploy keys @description('Optional String to append ...

Managing Secrets in .NET Applications: From Development to Production

Handling secrets securely is a critical part of building .NET applications. Whether it’s database credentials, API keys, or SSL certificate passwords, secrets should never be hardcoded in source code. Instead, they should be stored securely and retrieved at runtime. This blog post covers: Why secrets management is important What types of secrets should be stored securely Setting secrets in development Setting secrets in production (Azure Key Vault) Reading secrets in `Program.cs` How secrets work in CI/CD pipelines (Azure/GitHub) Caveats and best practices Why Secrets Management Matters Hardcoding secrets in your codebase introduces security risks, such as: Exposure in version control: If credentials are committed to Git, anyone with repository access can see them. Harder to rotate credentials: Updating a secret would require modifying and redeploying the application. Environment inconsistencies: Different environments (dev, staging, production) require different secrets. A secure appr...

Creating a service principal using the Azure CLI

Step 1. First log into the Azure CLI  az login --use-device-code Next lets get our < subscriptionId>  guid: az account show --query id --output tsv Result:  EG: 929133e1-d1d4-4af3-a15d-f935b119ded9 Step 2. We need to create a service principal that will do the deployments as we test in VS code. az ad sp create-for-rbac --name  <displayName>  --skip-assignment Result: {   "appId":  <appId> ,   "displayName": <displayName>,   "password": <password>,   "tenant":  <tenantId> } Step 3. Lets assign some roles using the  <appId>  and the < subscriptionId> retrieved in the previous command. # Assign the Contributor role az role assignment create --assignee <appId> --role "Contributor" --scope "/subscriptions/ < subscriptionId> " # Assign another role, e.g., Reader az role assignment create --assignee <appId> --role "Reader" --scope "/subscriptions/ < ...

Named algorithms in computer science

There are dozens of named algorithms in computer science, each addressing specific problems efficiently. Below are some of the most famous ones, categorized by their application: 📌 Famous Named Algorithms in Computer Science 1️⃣ Array & Sequence Processing Kadane’s Algorithm → Finds the maximum subarray sum in O(n). Dutch National Flag Algorithm → Sorts an array of three distinct values in O(n) (Used in quicksort 3-way partitioning). Floyd’s Tortoise and Hare Algorithm → Detects cycles in linked lists or sequences in O(n) with O(1) space. 2️⃣ Sorting Algorithms Merge Sort → Divide & Conquer-based sorting algorithm in O(n log n). QuickSort → Efficient sorting using partitioning (O(n log n) on average). Heap Sort → Uses a heap to sort in O(n log n). Counting Sort → Fast sorting in O(n + k) for small integer ranges. Radix Sort → Non-comparative sorting in O(nk). 3️⃣ Searching Algorithms Binary Search → Efficiently searches in O(log n). Interpolation Search → Improved binary searc...

Universal Helper Functions for Interviews (C#)

namespace Logic {     public class Traversal     {         public void MoveForward<T>(T[] arr, Action<T, int> callback)         {             for (int i = 0; i < arr.Length; i++) callback(arr[i], i);         }         public void MoveBackward<T>(T[] arr, Action<T, int> callback)         {             for (int i = arr.Length - 1; i >= 0; i--) callback(arr[i], i);         }     }     public class Expansion     {         public string ExpandFromCenter(string s, int left, int right)         {             while (left >= 0 && right < s.Length && s[left] == s[right])             {           ...

Universal Helper Functions for Interviews (TypeScript)

These functions will help solve arrays, strings, graphs, trees, and DP problems with minimal effort. 1️⃣ Forward & Backward Traversal Used for prefix sums, sliding window, and DP problems. function moveForward<T>(arr: T[], callback: (val: T, i: number) => void): void {     for (let i = 0; i < arr.length; i++) callback(arr[i], i); } function moveBackward<T>(arr: T[], callback: (val: T, i: number) => void): void {     for (let i = arr.length - 1; i >= 0; i--) callback(arr[i], i); } ✔ Usage: Trapping Rain Water (prefix/suffix max) Kadane’s Algorithm (max subarray sum) Stock Buy/Sell Problem 2️⃣ Two-Pointer Expansion (Palindromes, Intervals) Used for finding palindromes, expanding subarrays, and binary search-like problems. function expandFromCenter(s: string, left: number, right: number): string {     while (left >= 0 && right < s.length && s[left] === s[right]) {         left--;   ...

Step-by-step guide to set up Node.js with TypeScript and enable execution and debugging in VS Code.

Here’s a step-by-step guide to set up Node.js with TypeScript and enable execution and debugging in VS Code. Step Action 1 Install Node.js & NPM 2 Install TypeScript globally 3 Create a new project (npm init -y) 4 Install typescript and @types/node 5 Generate tsconfig.json (npx tsc --init) 6 Write TypeScript code (src/index.ts) 7 Compile TypeScript (npx tsc) 8 Run JavaScript with Node.js (node dist/index.js) 9 Set up VS Code Debugging 10 Use ts-node for instant TypeScript execution 11 Use nodemon for automatic compilation Step 1: Install Node.js and NPM Download & Install Node.js Download from Node.js Official Website Install the LTS (Long-Term Support) version. Verify installation: node -v   # Check Node.js version npm -v   # Check npm version Step 2: Install TypeScript Install TypeScript globally: npm install -g typescript Verify installation: tsc -v  # Check TypeScript compiler version Step 3: Set Up a New Node.js TypeScript Proje...

Understand .NET 9.0 Blazor Hosting Models

Blazor comes in three hosting models: Blazor Server , Blazor WebAssembly (WASM) , and Blazor Hybrid . Each model has unique requirements for setup in the Program.cs file and routing. Let's break down what is needed for each. 1. Blazor Server Blazor Server runs the app on the server, with the UI updates sent to the client over a real-time SignalR connection. Key Setup in Program.cs csharp var builder = WebApplication.CreateBuilder(args); // Add Blazor Server services builder.Services.AddServerSideBlazor() .AddCircuitOptions(options => options.DetailedErrors = true ); // Optional: Enable detailed errors var app = builder.Build(); // Map the Blazor Server app app.MapBlazorHub(); // Maps SignalR hub for real-time communication app.MapFallbackToPage( "/_Host" ); // Fallback route to load the app app.Run(); Router The _Host.cshtml file serves as the entry point. Routes are managed server-side. Example: razor <Router AppAssembly="typeof(Program).Ass...

Understanding Multistage builds in Docker

A multi-stage build in Docker allows you to use multiple FROM statements in a single Dockerfile to create separate stages for building and running an application. For example, in the first stage, you can use a large image with the SDK (e.g., mcr.microsoft.com/dotnet/sdk ) to compile and publish the application. In the second stage, you copy the build output to a lightweight runtime-only image (e.g., mcr.microsoft.com/dotnet/aspnet ) to create the final container. This approach significantly reduces the size of the final image because only the application and its dependencies are included, while the build tools and intermediate files are discarded. This results in smaller, more secure, and more efficient images. Each image used in a multi-stage Docker build can have a specific tag that identifies the exact version or variant of the image. For example, in the build stage, you might use a tagged SDK image like mcr.microsoft.com/dotnet/sdk:9.0 to ensure the application is compiled with...

Enable Docker Support in .NET 9.0 Projects

  When you select "Add Docker Support" in Visual Studio, it integrates Docker into your .NET project to enable containerization. This involves making several changes to your project and its configuration files to facilitate running and debugging the application in a Docker container. Here’s what "Add Docker Support" does in detail: 1. Adds a Dockerfile Visual Studio generates a Dockerfile tailored to your project's type (e.g., Web API, Console App). This file contains the instructions for building and running your application in a Docker container. Example Dockerfile for a Web API: dockerfile FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS base WORKDIR /app EXPOSE 80 EXPOSE 443 FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build WORKDIR /src COPY ["MyWebAPI/MyWebAPI.csproj", "./"] RUN dotnet restore "MyWebAPI.csproj" COPY . . WORKDIR "/src/MyWebAPI" RUN dotnet build "MyWebAPI.csproj" -c Release -o /app/build FROM bui...