Programming Tips πŸ’‘
51.6K subscribers
67 photos
10 videos
30 files
354 links
Programming & AI:
Tips πŸ’‘
Articles πŸ“•
Resources πŸ‘Ύ
Design Patterns πŸ’Ž
Software Principles βœ…

πŸ‡³πŸ‡± Contact: @MoienTajik

🎯 Buy ads: https://telega.io/c/ProgrammingTip
Download Telegram
πŸ” Challenge: Create a compact Maze Game in C# under 2KB without .NET Runtime, Small enough to fit in a QR Code πŸ€”

πŸ‘¨β€πŸ’» Process:
β€’ Self-Contained: Includes all necessary components to run on any OS. βœ”οΈ

β€’ Game Type: A graphical maze, utilizing Win32 APIs, avoiding WinForms. ⭐️

β€’ Size Reduction Steps:
1- Initial Size: 64MB (with CoreCLR)
2- Post-Compression: 35.2MB
3- IL Trimming Applied: 10MB
4- Native AOT Compilation: 1.13MB
5- Removing Unused Features: 923KB
6- Using bflat Compiler: 882KB
7- bflat with Zerolib: 9KB
8- Direct PInvoke: 8KB
9- Eliminating Debugging and Relocations: 7KB
10- Targeting x86 Architecture: 6.5KB
11- Final Step with Crinkler Linker: 1,936 Bytes

πŸŽ‰ Outcome: Achieved a C# game small enough to fit in a QR code!


[ Full Article πŸ”— ] : https://migeel.sk/blog/2024/01/02/building-a-self-contained-game-in-csharp-under-2-kilobytes

〰️〰️〰️〰️〰️〰️
#CSharp #DotNet #Optimization #LowLevel
@ProgrammingTip
Please open Telegram to view this post
VIEW IN TELEGRAM
5 Rules for Writing Better and Cleaner DTOs 🧹

Crafting clean and maintainable DTOs is essential for keeping your codebase healthy and scalable. But let's face it, sometimes DTOs can morph into these complex beasts that leave you scratching your head.  ‍

Fear not, fellow developers!

This article (or the accompanying video!) dives into 5 key principles to help you write simpler, more understandable DTOs.

You'll learn about:

β€’ Keeping things clear and concise
β€’ Utilizing properties effectively ✨
β€’ Crafting descriptive names that make sense

And also other tips to transform your DTOs from chaotic to crystal clear! By following these principles, you'll be well on your way to writing cleaner, more maintainable DTOs that make your code easier to understand for you and your team.

Ready to up your DTO game? Check out the full article or watch the video for examples and take your codebase to the next level!

[ Article ] : https://ardalis.com/5-rules-dtos

[ YouTube ] : https://www.youtube.com/watch?v=W4n9x_qGpT4

〰️〰️〰️〰️〰️〰️
#Dto #Dotnet #csharp #programming
@ProgrammingTip
OpenAI .NET πŸ‘Ύ

The OpenAI .NET library provides convenient access to the OpenAI REST API from .NET applications. βœ”οΈ

The full API of this library can be found in the api.md file, and there are many code examples to help. For instance, the following snippet illustrates the basic use of the chat completions API:

ChatClient client = new(model: "gpt-4o", "OPENAI_API_KEY");

ChatCompletion completion = client.CompleteChat("Say 'this is a test.'");

Console.WriteLine($"[ASSISTANT]: {completion}");


The library is organized into several namespaces corresponding to OpenAI feature areas. Each namespace contains a corresponding client class:

β€’ AssistantClient
β€’ AudioClient
β€’ BatchClient
β€’ ChatClient
β€’ EmbeddingClient
β€’ FineTuningClient
β€’ FileClient
β€’ ImageClient
β€’ ModelClient
β€’ ModerationClient
β€’ VectorStoreClient


[ GitHub ] : https://github.com/openai/openai-dotnet

〰️〰️〰️〰️〰️〰️
#AI #OpenAI #DotNet #CSharp
@ProgrammingTip
Please open Telegram to view this post
VIEW IN TELEGRAM
NetPad πŸ”₯

A cross-platform C# editor and playground.

NetPad is a C# playground that lets you run C# code instantly, without the hassle of creating and managing projects. Open NetPad, start coding, hit Run, and see your output immediately. It's that simple. βœ”οΈ

β€’ Prototyping and Testing:
Quickly prototype and test code snippets before incorporating them into your projects.

β€’ Data Visualization: Visualize data interactively for better insights and analysis.

β€’ Database Queries: Query databases using LINQ or SQL effortlessly.

β€’ Learn and Experiment: Experiment with new C# features or start learning C# in an intuitive and accessible environment.

β€’ Utility Scripts: Create and save your own utility or administration scripts for repeated use.


[ GitHub ] : https://github.com/tareqimbasher/NetPad

〰️〰️〰️〰️〰️〰️
#NetPad #Linqpad #CSharp #DotNet
@ProgrammingTip
Please open Telegram to view this post
VIEW IN TELEGRAM
I Built a .NET App Using AI (with Cursor) - This Is Amazing βœ…

Discover how Cursor AI can transform your .NET development workflow! πŸš€

In this video, you will see how this AI-powered code editor can help you write better code faster, understand complex codebases, and automate repetitive tasks. Whether you're a seasoned developer or just getting started with .NET, Cursor's AI capabilities will change how you think about coding.


[ YouTube ] : https://youtu.be/5hyRBuW560c

〰️〰️〰️〰️〰️〰️
#AI #Cursor #DotNET #CSharp
@ProgrammingTip
Please open Telegram to view this post
VIEW IN TELEGRAM
Build a Model Context Protocol (MCP) Server in C# 🧠

Learn how to create an MCP server using .NET 8 and ASP.NET Core! ⚑️

This guide walks you through building a server that can interact with AI models via the Model Context Protocol β€” a standard for managing model prompts, memory, and tools. Great for AI agent developers! πŸ€–πŸ§ 


[ Blog ] : https://devblogs.microsoft.com/dotnet/build-a-model-context-protocol-mcp-server-in-csharp

〰️〰️〰️〰️〰️〰️
#AI #MCP #dotnet #csharp
@ProgrammingTip
Please open Telegram to view this post
VIEW IN TELEGRAM
C# 14 - Extension Members πŸš€

C# 14 adds new syntax to define extension members. The new syntax enables you to declare extension properties in addition to extension methods. βœ”οΈ

You can also declare extension members that extend the type, rather than an instance of the type. In other words, these new extension members can appear as static members of the type you extend.

The following code example shows an example of the different kinds of extension members you can declare:
public static class Enumerable
{
// Extension block
extension<TSource>(IEnumerable<TSource> source) // extension members for IEnumerable<TSource>
{
// Extension property:
public bool IsEmpty => !source.Any();
// Extension indexer:
public TSource this[int index] => source.Skip(index).First();

// Extension method:
public IEnumerable<TSource> Where(Func<TSource, bool> predicate) { ... }
}

// extension block, with a receiver type only
extension<TSource>(IEnumerable<TSource>) // static extension members for IEnumerable<Source>
{
// static extension method:
public static IEnumerable<TSource> Combine(IEnumerable<TSource> first, IEnumerable<TSource> second) { ... }

// static extension property:
public static IEnumerable<TSource> Identity => yield return default;
}
}


The members in the first extension block are called as though they're instance members of IEnumerable<TSource>, for example sequence.IsEmpty. The members in the second extension block are called as though they're static members of IEnumerable<TSource>, for example IEnumerable<int>.Identity.


[ Blog ] : https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/extension-methods

〰️〰️〰️〰️〰️〰️
#csharp #dotnet
@ProgrammingTip
Please open Telegram to view this post
VIEW IN TELEGRAM
The Hidden Cost of DateTime.Now in .NET πŸ•°

You're Using DateTime.Nowβ€Šβ€”β€Šand It's Breaking Your Code … ❌

Let's be honest: We've all written this:
if (DateTime.Now > token.Expiry)
{
return Unauthorized();
}


It works… until it doesn't.

In production, this little line can wreck your logic due to clock drift, time zone shifts, or mocking nightmares. 🐞


[ Article ]
: https://freedium.cfd/https://medium.com/@yaseer.arafat/the-hidden-cost-of-datetime-now-and-what-every-net-developer-should-use-instead-8859863257a1

〰️〰️〰️〰️〰️〰️
#dotnet #csharp
@ProgrammingTip
Please open Telegram to view this post
VIEW IN TELEGRAM