Dev Tunnel Logo

devtunnel CLI

Overview Microsoft devtunnel is a CLI tool that allows you to create secure tunnels to expose your local development services to the internet. This guide provides comprehensive setup instructions for installing and configuring devtunnel on Windows, macOS, and Linux. 1 devtunnel host -p 6001 --protocol https -a Prerequisites Before installing devtunnel, ensure you meet the following requirements: System Requirements Windows: Windows 10 (version 1809 or later) or Windows 11 winget package manager (included in Windows 10/11) or PowerShell 5.1+ Administrator privileges (for some installation methods) macOS: ...

January 22, 2026 · 9 min · 1817 words · PrashantUnity
Download Logo

Seed SQLite

Required NuGet Packages Create .ipynb file 1 2 3 #r "nuget: Faker.Net, 2.0.163" #r "nuget:SkiaSharp, 3.116.1" #r "nuget: System.Data.SQLite.Core, 1.0.119" Importing namespace 1 2 3 4 5 6 7 using Faker; using System.IO; using SkiaSharp; using System; using System.Collections.Generic; using System.Reflection; using System.Data.SQLite; Create Class 1 2 3 4 5 6 7 8 9 10 11 public class Book { public int Id { get; set; } public string Title { get; set; } public string Author { get; set; } public byte[] Image { get; set; } public decimal Price { get; set; } public string Description { get; set; } public DateTime PublishDate { get; set; } public string Category { get; set; } } Bunch of Color for random background color 1 2 3 4 5 6 7 8 9 10 11 12 var listOfColor = new List<SKColor> { SKColor.Parse("#86B6F6"), SKColor.Parse("#176B87"), SKColor.Parse("#00A9FF"), SKColor.Parse("#FF90BC"), SKColor.Parse("#8ACDD7"), SKColor.Parse("#F2AFEF"), SKColor.Parse("#C499F3"), SKColor.Parse("#33186B"), }; Sqlite Database File Location 1 var connectionString = @"Data Source=C:\Users\91746\source\repos\Shopping\Shopping\BookStore.db"; This will Generate Data for Cover Image Dynamically 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 byte[] Generate<T>(T book) { int width = 480; int height = 540; int marginY = -10; int marginX = -10; string mainText =Faker.Name.First(); //book.Title; string subText = Faker.Name.Last(); string backGroundColor =listOfColor[Faker.RandomNumber.Next(0,listOfColor.Count()-1)].ToString(); string textColor = "#ffffff"; string boderColor = "#ffffff"; SKBitmap bmp = new(width, height); SKCanvas canvas = new(bmp); canvas.Clear(SKColor.Parse(backGroundColor)); using (var paint = new SKPaint()) { paint.TextSize = width/ 10.0f; paint.IsAntialias = true; paint.Color = SKColor.Parse(textColor); paint.IsStroke = false; paint.StrokeWidth = 3; paint.TextAlign = SKTextAlign.Center; canvas.DrawText(mainText, width / 2f, height / 2f, paint); paint.TextSize = width/ 25.0f; paint.TextAlign = SKTextAlign.Right; canvas.DrawText(subText, width+marginX, height+marginY, paint); paint.TextSize = width/ 20.0f; paint.IsStroke = true; paint.TextAlign = SKTextAlign.Center; paint.Color = SKColor.Parse(textColor); } //SKFileWStream fs = new($"Images/{book.Title}.jpg"); //bmp.Encode(fs, SKEncodedImageFormat.Jpeg, quality: 50); bmp.Encode(SKEncodedImageFormat.Jpeg,100); using (MemoryStream ms = new MemoryStream()) { bmp.Encode(ms, SKEncodedImageFormat.Jpeg, 100); return ms.ToArray(); } return bmp.Bytes; } Using Reflection For Auto filling Data To Proprties 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 T GetObjectOf<T>() { Type objectType = typeof(T); object objectObject = Activator.CreateInstance(objectType); // Get the properties of the Book class PropertyInfo[] properties = objectType.GetProperties(); // Use Faker.NET to populate the properties dynamically foreach (var property in properties) { // Skip the 'Id' property as it's usually auto-generated if (property.Name == "Id") continue; // Create fake data based on the property type if (property.PropertyType == typeof(string)) { property.SetValue(objectObject, Faker.Name.FullName()); } else if (property.PropertyType == typeof(int)) { // Assign a random integer property.SetValue(objectObject, Faker.RandomNumber.Next()); } else if (property.PropertyType == typeof(decimal)) { // Assign a random decimal value property.SetValue(objectObject, (decimal)(Faker.RandomNumber.Next(01,1000) )); } else if (property.PropertyType == typeof(DateTime)) { // Assign a random past date property.SetValue(objectObject, DateTime.Now.AddMonths(Faker.RandomNumber.Next(1,100))); } else if (property.PropertyType == typeof(byte[])) { // Assign a random byte array (representing an image or file) property.SetValue(objectObject, Generate((T)objectObject)); } else if (property.PropertyType == typeof(System.Enum)) { // For enum types, assign a random enum value if the property is of enum type Array enumValues = property.PropertyType.GetEnumValues(); var randomEnumValue = enumValues.GetValue(Faker.RandomNumber.Next(0, enumValues.Length)); property.SetValue(objectObject, randomEnumValue); } } return (T)objectObject; } Generate Bunch Of Book Will bw used to insert to database 1 2 3 4 5 6 7 8 9 10 List<T> GeBook<T>() { var ls = new List<T>(); for(var i=0;i<50;i++) { var newBook = GetObjectOf<T>(); ls.Add(newBook); } return ls; } Dynamically Creating SqlQuery string Using Reflection 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 public void InsertBook<T>(T entity, string queryString) { string insertQuery = queryString; try { using (SQLiteConnection conn = new SQLiteConnection(connectionString)) { try { conn.Open(); using (SQLiteCommand cmd = new SQLiteCommand(insertQuery, conn)) { Type type = typeof(T); // Get all properties of the Book class using Reflection PropertyInfo[] properties = type.GetProperties(); foreach (var property in properties) { // Get the name of the property string propertyName = property.Name; object propertyValue = property.GetValue(entity); cmd.Parameters.AddWithValue($"@{propertyName}", propertyValue); } var num = cmd.ExecuteNonQuery(); } } catch(Exception ex) { Console.WriteLine(ex.Message); } } } catch(Exception ex) { Console.WriteLine(ex.Message); } } Here data is inserted to database 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 string InsertCommandStringGenerator<T>() { Type bookType = typeof(T); // Get all the properties of the Book class PropertyInfo[] properties = bookType.GetProperties(); // Initialize StringBuilder to construct the SQL query StringBuilder insertQuery = new StringBuilder(); // Start building the SQL query insertQuery.AppendLine("INSERT INTO Books ("); // Loop through the properties to add column names for (int i = 0; i < properties.Length; i++) { if(properties[i].Name.ToLower()=="id") continue; insertQuery.Append(properties[i].Name); if (i < properties.Length - 1) { insertQuery.Append(", "); } } insertQuery.AppendLine(") VALUES ("); // Loop through the properties again to add parameter placeholders for (int i = 0; i < properties.Length; i++) { if(properties[i].Name.ToLower()=="id") continue; insertQuery.Append("@"); insertQuery.Append(properties[i].Name); if (i < properties.Length - 1) { insertQuery.Append(", "); } } insertQuery.AppendLine(");"); return insertQuery.ToString(); } Final Command To populate all above 1 2 3 4 5 var queryString = InsertCommandStringGenerator<Book>(); foreach(var item in GeBook<Book>()) { InsertBook(item,queryString); }

January 1, 2025 · 5 min · 937 words · PrashantUnity
Download Logo

HTML strings in Polyglot

Display HTML Content in Polyglot Notebook Requirements Visual Studio Code (VS Code) Polyglot Notebook Extension Basic Setup Knowledge If you’re new to Polyglot Notebooks, check out the initial setup instructions here. .NET SDK If not installed, download and install it from the official website. An Image File Setting Up Your Files Install Visual Studio Code If you haven’t already, download and install VS Code. Open Your Image Folder Open Folder and Copy the image Path. Open Terminal in the Folder ...

June 23, 2024 · 3 min · 432 words · PrashantUnity
Download Logo

Download files in C#

File Downloader Using C# Requirements Valid File URL/List of URLs IDE: Visual Studio or Visual Studio Code (preferred) Latest .NET SDK Installed: Download Here Steps 1. Open Visual Studio or Visual Studio Code 2. Paste the below snippet 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 using var httpClient = new HttpClient(); // Replace the URL with the actual File URL string fileUrl = "https://drive.usercontent.google.com/download?id=11PIu2A0ICZHh46phJMFZ3Y547gQDEI7T&export=download&authuser=0"; try { // Send GET request to fetch the File using HttpResponseMessage response = await httpClient.GetAsync(fileUrl); // Check if request was successful if (response.IsSuccessStatusCode) { // Get the File stream using (Stream fileStream = await response.Content.ReadAsStreamAsync()) { // Save the file with appropriate extension name var fileName=$"image.png" using FileStream fileStream = File.Create(fileName); await fileStream.CopyToAsync(fileStream); } Console.WriteLine("File downloaded successfully."); } else { Console.WriteLine($"Failed to download file. Status code: {response.StatusCode}"); } } catch (Exception ex) { Console.WriteLine($"An error occurred: {ex.Message}"); } 3. Customize the Code Replace fileUrl with the URL of the file you want to download. Replace fileName with the desired name and extension for the downloaded file. 4. Run the Program For List of String you may use 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 var ls = new List<string>() { "https://picsum.photos/200/300", "https://picsum.photos/200/300" }; foreach (var item in ls) { try { // Send GET request to fetch the File using HttpResponseMessage response = await httpClient.GetAsync(fileUrl); // Check if request was successful /* rest code */ } catch (Exception ex) { Console.WriteLine($"An error occurred: {ex.Message}"); } }

June 19, 2024 · 2 min · 278 words · PrashantUnity
Google Drive Logo

Drive folder IDs

Overview Suppose you want to extract the ID of all items that reside in a folder of Google Drive. There are many ways to do this, like manually copying from each file or programmatically. I will guide you on how to do this using a program in C# Requirements Shared Google Drive Folder id /URL 1 https://drive.google.com/drive/u/4/folders/1759s8Jule46RCPypiQ5y3wLh5aCPlrK6 IDE like VS Code or Visual Studio preferred. Latest .NET SDK installed. You can get it from here Steps 1 Open IDE or code editor. Create a new console app using IDE or through this command in terminal ...

June 13, 2024 · 4 min · 707 words · PrashantUnity
Download Logo

Interview framework

Define Input and Output Requirements How is the input stored? What kind of values are there? Are there any negative values? Will there be any empty data? Can I assume there is always valid input? Will the size/number of data be greater than integer max value? Are we returning indexes/data? What if there are multiple answers? Analyze Data Size, Range, and Scale How big is the size of input? Do we take into account integer overflow? Size of array or N or Length What should we do if the size of data count is greater than Integer range? Suggest we can use linked list own custom data type Consider the Runtime Environment What type of environment will the algorithm be running in? Can I modify the original data? Can I use the latest language features? Walk Through Your Solution Approach Start writing comments in the editor. ...

July 12, 2024 · 2 min · 230 words · PrashantUnity
Generate Thumbnail

Trig tables in SkiaSharp

Trigonometry Table Generation Trignonometry Table Code used to Generate Above Table 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 int width = 1500; int height = 750; int step = 60; SKBitmap bmp = new(width, height); SKCanvas canvas = new(bmp); canvas.Clear(SKColor.Parse("#fff")); SKPaint paint = new() { IsAntialias = true, StrokeWidth = 4, Color = SKColor.Parse("#003366"), Style = SKPaintStyle.Stroke }; paint.TextSize = 48f; string backGroundColor ="#fff"; canvas.Clear(SKColor.Parse(backGroundColor)); paint.Style = SKPaintStyle.Fill; string trignometricTable = "Trigonometry Table"; string root = "\u221A"; string theta ="\u03B8"; string degree ="\u00B0"; string inf ="\u221E"; var ls = new List<List<string>>(); ls.Add(["",$"0{degree}",$"30{degree}",$"45{degree}",$"60{degree}",$"90{degree}"]); ls.Add([$"Sin{theta}",$"0",$"1/2",$"1/{root}2",$"({root}3)/2",$"1",]); ls.Add([$"Cos{theta}",$"1",$"({root}3)/2",$"1/{root}2",$"1/2",$"0",]); ls.Add([$"Tan{theta}",$"0",$"1/{root}3",$"1",$"{root}3",$"{inf}",]); ls.Add([$"Cosec{theta}",$"{inf}",$"2",$"{root}2",$"2/{root}3",$"1",]); ls.Add([$"Sec{theta}",$"1",$"2/{root}3",$"{root}2",$"2",$"{inf}",]); ls.Add([$"Cot{theta}",$"{inf}",$"{root}3",$"1",$"1/{root}3",$"0",]); float shifx =150; float shify =120; float verticalMax = 600 + shify; float horizontalMax = 1200 + shifx; for(var i=shify; i<height; i+=100) { canvas.DrawLine(shifx,i,horizontalMax,i,paint); } for(var i=shifx; i<width; i+=200) { canvas.DrawLine(i,shify,i,verticalMax,paint); } paint.TextAlign = SKTextAlign.Center; canvas.DrawText(trignometricTable,width/2,100,paint); float y =200; foreach(var i in ls) { float x =shifx+100; foreach(var j in i) { canvas.DrawText(j,x,y,paint); x+=200; } y+=100; } bmp.Display(); 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 int width = 1500; int height = 750; int step = 60; SKBitmap bmp = new(width, height); SKCanvas canvas = new(bmp); canvas.Clear(SKColor.Parse("#fff")); SKPaint paint = new() { IsAntialias = true, StrokeWidth = 4, Color = SKColor.Parse("#003366"), Style = SKPaintStyle.Stroke }; paint.TextSize = 48f; string backGroundColor ="#fff"; canvas.Clear(SKColor.Parse(backGroundColor)); paint.Style = SKPaintStyle.Stroke; var skPath = new SKPath(); float diagonal = 600; float rX = 150; float rXX = rX + diagonal*MathF.Sqrt(3)/2; float rY = 150; float rYY = rY +diagonal/2; SKPoint[] rt = [new SKPoint(rX,rY),new SKPoint(rX,rYY),new SKPoint(rXX,rYY)]; float aX = width/2; float aY = 300; canvas.DrawText("1",rX-30,(rY+rYY)/2 ,paint); canvas.DrawText("2",(rX+rXX)/2,(rY+rYY)/2 -10 ,paint); canvas.DrawText("\u221A3",(rX+rXX)*1/2.5f,rYY +50 ,paint); var skpath = new SKPath(); skpath.AddPoly(rt); canvas.DrawPath(skpath,paint); bmp.Display();

August 3, 2024 · 2 min · 370 words · PrashantUnity
PostgreSQL database

Postgres 16 in Docker

Overview This guide shows how to run PostgreSQL 16 locally using the official Docker image and Docker Compose. You get a default database user and database, port 5432 on your machine mapped into the container, and a named volume so data survives container restarts. Prerequisites Docker Engine installed (Get Docker). Docker Compose v2 (bundled with Docker Desktop; on Linux you may use the docker compose plugin). The version: key at the top of a Compose file is optional in modern Compose; including version: '3.8' is still fine for compatibility. ...

March 24, 2026 · 3 min · 560 words · PrashantUnity
Google Drive Logo

GitHub Actions data jobs

Create a New Console Project I am going to create a dotnet project to demonstrate this, but it is applicable for all other programming languages as well Open any folder, then open Terminal In Terminal, create a new dotnet console project using the below command 1 2 3 4 5 6 7 8 dotnet new console -n GitCiCd cd .\GitCiCd\ code . mkdir .github cd .\.github\ mkdir workflows cd .\workflows\ echo "" > "dotnet.yaml" In dotnet.yaml file Paste Below Code 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 name: workflows on: push: branches: [ "master" ] jobs: scrape_videos: runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v2 - name: Set up .NET uses: actions/setup-dotnet@v2 with: dotnet-version: '8.0.x' # Use the latest .NET version - name: Restore dependencies run: dotnet restore - name: Build the project run: dotnet build --configuration Release - name: Run the scraping script run: dotnet run --project GetYoutubeVideo.csproj - name: Commit and Push Changes run: | git config --local user.email "action@github.com" git config --local user.name "GitHub Action" git add Text.txt git commit -m "Update Text.txt list" git push Inside Program.cs file paste below code for. 1 2 3 4 5 6 7 8 9 10 11 var ls = Enumerable.Range(1,8).Select(i => i.ToString() + DateTime.Now).ToList(); SaveToFile(ls, "Text.txt"); static void SaveToFile(List<string> videos, string filePath) { using StreamWriter file = new(filePath); foreach (var video in videos) { file.WriteLine(video); } } The code Responsible for operation is below code 1 2 3 4 5 6 7 - name: Commit and Push Changes run: | git config --local user.email "action@github.com" git config --local user.name "GitHub Action" git add Text.txt git commit -m "Update Text.txt list" git push Push to github Now Go to Repository Setting Tab ...

July 28, 2024 · 2 min · 356 words · PrashantUnity
Download Logo

YouTube API updates

YouTube Data API Sample in .NET Interactive Notebooks This sample demonstrates how to use the YouTube Data API to update video metadata (title, description, tags, etc.) in bulk using .NET Interactive Notebooks. It covers OAuth2 authentication, fetching uploaded videos, generating new metadata using an AI model, and updating the videos via the API. Get Gemini API Key Google Cloud Console for creating secret credentials 1 2 #r "nuget: Google.Apis.YouTube.v3" #r "nuget: Google.Apis.Auth" This cell loads the NuGet package references required to use the YouTube Data API and Google authentication in a polyglot/.NET Interactive notebook. ...

December 23, 2025 · 5 min · 978 words · PrashantUnity