Generate Thumbnail

Wave collapse art

Concept Imagine each image as a collection of small boxes arranged in different positions. Each image has four sides, and our goal is to determine how these images can connect to one another based on the configuration of these sides. Let’s take the example of an image: ...

July 20, 2024 · 6 min · 1130 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

Spot-check: are you ready?

Q1. What is C#? What is the difference between C# and .NET? C# (C-Sharp) is a modern, object-oriented programming language developed by Microsoft. It is part of the .NET framework and is used for developing a wide range of applications, from web and mobile apps to desktop applications. .NET is a framework developed by Microsoft that provides a comprehensive platform for building and running applications. It includes a runtime environment (CLR), a large class library, and support for various programming languages, including C#, VB.NET, and F#. ...

August 3, 2024 · 127 min · 26990 words · PrashantUnity
Cover Logo

Bing IndexNow

Implementation Steps Generate API Key Visit bing Index Now for Generating Host your API key Create a file in Directory of you website will look like this 1 d06c191380a74c08a8ef46d9a32e3eec.txt Update website after adding to root of directory Send Request via C# Requirement VS Code PolyGlot Notebook Extension .Net Sdk Installed if Not Please Follow Installtion step from here will Create Demo for that process. Open VS Code Create New Folder Inside Folder Create two File data.txt bing.ipynb In data.txt File Fill all the URL in Follwing Fasion Code in bing.ipynb Make Sure You Selected .Net Interactive ...

June 24, 2024 · 2 min · 294 words · PrashantUnity
Cover Logo

Google Indexing API

Google Cloud Console Setup Go To Google Console If its you first Time it Will be Similar to This (As of June 2024). If Some Project is Slected then may be this. On Search Bar Search new Project Select Create a new Project (IAM and admin) On New screen Fill Some Detail you can give any name and Click Create In an Moment On Top Right Of Screen will show some thing like below Image Click On Select Project Again Type Service Account On Search Section Choose Service Account (IAM and admin) Then on Following Screen Click Create Service Account Fill The Details With Anything you like and Click Create and Continue The in following Section From Drop Down Choose Currently used owner and click continue Then After Click Done Generate Crediential On Following Screen it will show some thing Like this Copy mailing adress which will be like xxx@xxx.iam.gserviceaccount.com and keep some place it will be need later In action Click on 3 Vertical dot and then Manage Key On Following Screen Click on add Key then create new key A popup will appear select JSON and then Create Download of JSON File ...

June 24, 2024 · 4 min · 738 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
Cover Page

Google Lens OCR in .NET

Harness the Power of Google Lens OCR in .NET Core and .NET Framework Extracting text from images is a handy tool for many tasks, like digitizing documents, automating data entry, and improving accessibility. Google Lens OCR, now available for both .NET Core and .NET Framework, makes this process easy and accurate. Google Lens OCR is derived from the Chrome Lens OCR project , this library is a powerful tool for developers. In this post, I’ll show you how to set it up and use it in your projects. ...

June 15, 2024 · 3 min · 555 words · PrashantUnity
Cover Page

Tesseract OCR

Unlocking the Power of Optical Character Recognition with Tesseract In Optical Character Recognition (OCR), Tesseract OCR stands out as a leading open-source library. Renowned for its extensive language support and ability to handle various image formats, Tesseract is a go-to choice for developers seeking to integrate text recognition capabilities into their applications. Key Features Supported Formats Tesseract is adept at recognizing text from a multitude of image formats, including JPG, PNG, BMP, and more. This flexibility ensures it can be seamlessly integrated into diverse projects with varying image input requirements. ...

June 15, 2024 · 4 min · 689 words · PrashantUnity
Cover Page

Windows Media OCR

Windows Media OCR Windows Media OCR is a powerful tool for extracting text from images, derived from Microsoft’s popular PowerToys repository. This tool leverages Windows’ built-in capabilities, making text recognition efficient and seamless for Windows 10 and above. In this post/Article, I’ll show you how to get started with Windows Media OCR and integrate it into your projects. Getting Started First, you need to clone the repository to your local machine. Use the following command: ...

June 15, 2024 · 2 min · 339 words · PrashantUnity