Git Branching Strategies

In essence, a Git branch is a movable pointer to a specific commit in the repository’s history. When you create a new branch, you’re creating a new line of development that diverges from the main line. This allows you to make changes without directly affecting the stable codebase.

Let’s understand how this works. I assume you have Git installed and have basic working knowledge of Git.

Read more on code site

Natural Language AI-Powered Smart UI

Looking for real-world AI examples is a challenge and part of this challenge comes from Generative AI (GenAI) news dominating the media. It feels like every AI demo involves chatting with GenAI to produce content. The obligatory chat completion demo has started to become the to-do list of AI demo apps, and, to make matters worse, it’s selling AI short. GenAIs rely on large language models (LLMs), which are the brain behind natural language processing tasks. In this article, I’ll explore the opportunities presented by LLMs using a real-world research-and-development experiment. This experiment is part of on-going research into AI-enabled user interface components (aka .NET Smart Components) by Progress Software and Microsoft.

Read more on code site

How to run SonarQube Analysis in Visual Studio Console

To generate a SonarQube token (required for authentication when running analyses from the command line or CI/CD pipelines), follow these steps:


Steps to Generate a SonarQube Token

  1. Log in to your SonarQube server (e.g., http://localhost:9000 for local setups).
  2. Click your profile icon (top-right corner) β†’ “My Account”.
  3. Go to the “Security” tab.
  4. Under “Tokens”, enter a name for your token (e.g., vs-console-token).
  5. Click “Generate”.
  6. Copy the token immediately (it won’t be shown again!).
    Example token format: sqp_1234567890abcdef

How to Use the Token

  • In dotnet-sonarscanner commands, pass the token via:shCopyDownloaddotnet sonarscanner begin /k:”your-project-key” /d:sonar.host.url=”http://localhost:9000″ /d:sonar.login=”sqp_1234567890abcdef”
  • For security, never hardcode the token in scripts. Use:
    • Environment variables (e.g., SONAR_TOKEN).
    • Secret management tools (e.g., Azure Key Vault, GitHub Secrets).

Important Notes

  • πŸ”’ Treat tokens like passwords (they grant access to your SonarQube projects).
  • πŸ”„ Regenerate tokens periodically or revoke old ones (under “Security”).
  • 🚫 No token? You’ll get errors like Not authorized or Authentication failed.

Example Workflow

# Set token as an environment variable (optional)
set SONAR_TOKEN=sqp_1234567890abcdef

# Run analysis (Windows CMD)
dotnet sonarscanner begin /k:"my-project" /d:sonar.host.url="http://localhost:9000" /d:sonar.login="%SONAR_TOKEN%"
dotnet build
dotnet sonarscanner end /d:sonar.login="%SONAR_TOKEN%"

Get the SonarQube Project URL

The project URL is the web address of your project in SonarQube. It typically follows this format:

http://<sonarqube-server-url>/dashboard?id=<project-key>
  • <sonarqube-server-url>: The host where SonarQube is running (e.g., http://localhost:9000 if running locally).
  • <project-key>: The unique key assigned to your project in SonarQube.

How to Find the Project Key?

  1. Log in to your SonarQube server.
  2. Navigate to your project.
  3. Check the URL in the browser’s address bar (e.g., http://localhost:9000/dashboard?id=my-project-key).
  4. Alternatively, go to Project Settings β†’ General Settings β†’ Key.

2. Run SonarQube Analysis in Visual Studio Console

To analyze a .NET project in Visual Studio Developer Command Prompt (or terminal), use the SonarScanner for .NET (dotnet-sonarscanner).

Prerequisites

  • Install Java (required for SonarQube scanner).
  • Install SonarScanner for .NET:shCopyDownloaddotnet tool install –global dotnet-sonarscanner

Steps to Run Analysis

  1. Start the SonarQube Analysis:shCopyDownloaddotnet sonarscanner begin /k:”” /d:sonar.host.url=”” /d:sonar.login=”
    • Replace:
      • <project-key> with your SonarQube project key.
      • <sonarqube-server-url> with your SonarQube server URL (e.g., http://localhost:9000).
      • <token> with a SonarQube user token.
  2. Build Your Project:shCopyDownloaddotnet build
  3. Complete & Publish Results to SonarQube:shCopyDownloaddotnet sonarscanner end /d:sonar.login=”<token>”
  4. Check Results:
    • Open the SonarQube project URL (e.g., http://localhost:9000/dashboard?id=my-project-key) in a browser.

Example

# Start analysis
dotnet sonarscanner begin /k:"my-dotnet-app" /d:sonar.host.url="http://localhost:9000" /d:sonar.login="sqp_1234567890abcdef"

# Build the project
dotnet build

# End analysis & upload results
dotnet sonarscanner end /d:sonar.login="sqp_1234567890abcdef"

After running these commands, your analysis results will appear in the SonarQube dashboard.

Azure AppInsights integration in Blazor WASM

Integrating Azure Application Insights in a Blazor WebAssembly (WASM) app is possible, though it requires special handling since Blazor WASM runs entirely in the browser, and you can’t use the full .NET SDK for Application Insights like you can in server-side apps.

Here’s how you can set it up using JavaScript SDK (since Blazor WASM ultimately runs in the browser):


βœ… Step-by-Step Guide

1. Create Application Insights Resource (if not done)

  • Go to Azure Portal β†’ Create a resource β†’ Application Insights.
  • Choose General β†’ Application Insights, select region, etc.
  • After creation, copy the Instrumentation Key or Connection String.

2. Add the Application Insights JavaScript SDK

In your Blazor WebAssembly project:

Modify wwwroot/index.html (for standalone Blazor WASM)

htmlCopyEdit<!-- Application Insights JavaScript SDK -->
<script type="text/javascript">
  var appInsights = window.appInsights || function (config) {
    function r(config) {
      t[config] = function () {
        var i = arguments;
        t.queue.push(function () { t[config].apply(t, i); })
      }
    }
    var t = { config: config }, u = document, e = window, o = "script", s = u.createElement(o), i, f;
    for (s.src = config.url || "https://az416426.vo.msecnd.net/scripts/a/ai.0.js", u.getElementsByTagName(o)[0].parentNode.appendChild(s), t.cookie = u.cookie, t.queue = [], i = ["Event", "Exception", "Metric", "PageView", "Trace", "Dependency"]; i.length;)
      r("track" + i.pop());
    return r("setAuthenticatedUserContext"), r("clearAuthenticatedUserContext"), r("flush"), config.disableExceptionTracking || (i = "onerror", r("_" + i), f = e[i], e[i] = function (config, r, u, e, o) {
      var s = f && f(config, r, u, e, o);
      return s !== !0 && t["_" + i](config, r, u, e, o), s
    }), t
  }({
    instrumentationKey: "YOUR_INSTRUMENTATION_KEY"
  });

  window.appInsights = appInsights;
  appInsights.trackPageView();
</script>

3. Call App Insights from C# Code

You can invoke JavaScript from your Blazor C# code like this:

Create a service to interact with JS (e.g., AppInsightsService.cs):

csharpCopyEditusing Microsoft.JSInterop;
using System.Threading.Tasks;

public class AppInsightsService
{
    private readonly IJSRuntime _jsRuntime;

    public AppInsightsService(IJSRuntime jsRuntime)
    {
        _jsRuntime = jsRuntime;
    }

    public async Task TrackEventAsync(string eventName)
    {
        await _jsRuntime.InvokeVoidAsync("appInsights.trackEvent", new { name = eventName });
    }

    public async Task TrackExceptionAsync(string errorMessage)
    {
        await _jsRuntime.InvokeVoidAsync("appInsights.trackException", new
        {
            exception = new { message = errorMessage }
        });
    }

    public async Task TrackPageViewAsync(string pageName)
    {
        await _jsRuntime.InvokeVoidAsync("appInsights.trackPageView", new { name = pageName });
    }
}

4. Register the Service

In Program.cs:

csharpCopyEditbuilder.Services.AddScoped<AppInsightsService>();

5. Use in Your Components

razorCopyEdit@inject AppInsightsService AppInsights

<button @onclick="TrackEvent">Track Event</button>

@code {
    private async Task TrackEvent()
    {
        await AppInsights.TrackEventAsync("ButtonClicked");
    }
}

🧠 Notes

  • Only client-side telemetry will be captured (JS-side) β€” no automatic dependency tracking, for example.
  • If you need full telemetry, consider combining it with Blazor WASM hosted model and using Application Insights server SDK in the backend.

Supervised and Unsupervised Learning

Supervised Learning

Definition:
The model learns from labeled data β€” meaning each input has a corresponding correct output.

Goal:
Predict an output (label) from input data.

Examples:

  • Email spam detection (Spam / Not Spam)
  • Predicting house prices (Price in $)
  • Handwriting recognition (0–9 digits)

Types:

  • Classification (output is a category): e.g., cat vs dog
  • Regression (output is a number): e.g., predicting temperature

Requires Labels? βœ… Yes

Example Dataset:

Input FeaturesLabel
“Free offer now” (email text)Spam
3 bedrooms, 2 baths, 1500 sq ft$350,000

πŸ” Unsupervised Learning

Definition:
The model learns patterns from unlabeled data β€” it finds structure or groupings on its own.

Goal:
Explore data and find hidden patterns or groupings.

Examples:

  • Customer segmentation (group customers by behavior)
  • Anomaly detection (detect fraud)
  • Topic modeling (find topics in articles)

Types:

  • Clustering: Group similar data points (e.g., K-Means)
  • Dimensionality Reduction: Simplify data (e.g., PCA)

Requires Labels? ❌ No

Example Dataset:

Input Features
Age: 25, Spent: $200
Age: 40, Spent: $800

(The model might discover two customer groups: low-spenders vs high-spenders)


βœ… Quick Comparison

FeatureSupervised LearningUnsupervised Learning
LabelsRequiredNot required
GoalPredict outputsDiscover patterns
OutputKnownUnknown
ExamplesClassification, RegressionClustering, Dimensionality Reduction
AlgorithmsLinear Regression, SVM, Random ForestK-Means, PCA, DBSCAN

Supervised Learning Use Cases

1. Email Spam Detection

  • βœ… Label: Spam or Not Spam
  • πŸ“ Tech companies like Google use supervised models to filter email inboxes.

2. Fraud Detection in Banking

  • βœ… Label: Fraudulent or Legitimate transaction
  • 🏦 Banks use models trained on historical transactions to flag fraud in real-time.

3. Loan Approval Prediction

  • βœ… Label: Approved / Rejected
  • πŸ“Š Based on income, credit history, and employment data, banks decide whether to approve loans.

4. Disease Diagnosis

  • βœ… Label: Disease present / not present
  • πŸ₯ Healthcare systems train models to detect diseases like cancer using medical images or lab reports.

5. Customer Churn Prediction

  • βœ… Label: Will churn / Won’t churn
  • πŸ“ž Telecom companies predict if a customer is likely to cancel a subscription based on usage data.

πŸ” Unsupervised Learning Use Cases

1. Customer Segmentation

  • ❌ No labels β€” model groups customers by behavior or demographics.
  • πŸ›’ E-commerce platforms use this for targeted marketing (e.g., Amazon, Shopify).

2. Anomaly Detection

  • ❌ No labeled “anomalies” β€” model detects outliers.
  • πŸ›‘οΈ Used in cybersecurity to detect network intrusions or malware.

3. Market Basket Analysis

  • ❌ No prior labels β€” finds item combinations frequently bought together.
  • πŸ›οΈ Supermarkets like Walmart use this to optimize product placement.

4. Topic Modeling in Text Data

  • ❌ No labels β€” model finds topics in documents or articles.
  • πŸ“š News agencies use it to auto-categorize stories or summarize themes.

5. Image Compression (PCA)

  • ❌ No labels β€” model reduces dimensionality.
  • πŸ“· Used in storing or transmitting large image datasets efficiently.

πŸš€ In Summary:

IndustrySupervised ExampleUnsupervised Example
FinanceLoan approvalFraud pattern detection
HealthcareDiagnosing diseases from scansGrouping patient records
E-commercePredicting purchase behaviorCustomer segmentation
CybersecurityPredicting malicious URLsAnomaly detection in traffic logs
RetailForecasting salesMarket basket analysis