Posts

Showing posts from February, 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...