Skip to main content

Posts

How to reduce token used by AI agents and improve output quality!

I would like to share some useful tricks I have learned today.  1. Manage well context window. The context window is the current chat session with Copilot agents. It includes your prompts, system instructions, and historical conversations. The longer the conversation is, the more tokens it costs because the agent will retrieve past context, which may no longer be relevant. 2. Choose right model for right task High reasoning model like Opus, Codex are great for planning, architecture, handling complex bug. Second tier models like Sonnet is great for implementation based on the plan from previous steps. And lower tier model like Haiku for small refactoring. --> An important thing to note is that because agents load historical conversation, so low level of accuracy from beginning can compound the inaccuracy. That's why in the beginning stage like researching, planning, the strongest models are able to produce the best quality. 3.  Prompt skill Prompt skill also plays an import...
Recent posts

What is Playwright testing and some of its key features?

Playwright is a modern end‑to‑end testing framework developed by Microsoft. It supports multiple programming languages, including TypeScript, JavaScript, C#, and Java, and can run tests across all major modern browsers. Its flexibility and developer‑friendly features make it a compelling choice for UI automation. Here is some core features that I find very useful when working with e2e test with Playwright: 1. Automatic test generation Using the VS Code extension, you can start a recording session where a browser window opens and captures your interactions. As you click, type, and navigate, Playwright automatically writes the corresponding test code for you. After recording, all you need to do is refine the assertions.  This feature dramatically speeds up test creation, especially for complex user flows. 2. Pick locator When running your test in the browser, you can activate Pick Locator to visually select any element on the page. Playwright will instantly generate the correct locat...

Date and Time in .NET: DateTime, DateTimeOffset, TimeZoneInfo, DateOnly, TimeOnly, and TimeSpan

What is UTC UTC (Coordinated Universal Time) is the world’s primary time standard used to regulate clocks and time zones. It serves as the reference point for civil time worldwide, ensuring that all local times are defined by their offset from UTC. DateTime The DateTime class provides a way to work with dates and times without including an offset. This approach can reduce a certain level of accuracy when dealing with time zones. For example, calling DateTime.Now returns the current date and time based on your computer’s local time zone. DateTime.Now gives you the local time, while DateTime.UtcNow returns the universal coordinated time (UTC). You typically use DateTime when you only need to track the date and time itself, without worrying about time zones. This is suitable for scenarios such as birthdays, deadlines, or local schedules, especially when your application is used primarily within a single time zone. The DateTime class also includes a Kind property, which provides limited in...

Understanding Asynchronous Programming

Asynchronous programming allows threads or workers to handle multiple tasks concurrently. A  Task represents a unit of work, and the await keyword lets you pause execution without blocking the thread—freeing it to handle other operations while waiting for the task to complete. 🍳  Real-Life Analogy: Making Breakfast Imagine you're preparing breakfast. The tasks might include: Brewing coffee Heating the pan Frying eggs and bacon Toasting bread Spreading jam Pouring juice If you perform these tasks synchronously,  completing one before starting the next, it would take significantly longer. But with an asynchronous approach, you can heat the pan and, while waiting, brew coffee, toast bread, and pour juice. By overlapping tasks, you reduce idle time and improve overall efficiency. This mirrors how asynchronous code works: it enables your application to stay responsive and efficient by not waiting idly for each operation to finish. 🧪 Using Async-Await Properly In C#, marki...

What is Cryptography and how to secure sensitive data in .NET app with encryption

What is Cryptography?  Cryptography is the process of securing data through encryption, hashing, digital signatures. It helps protect communication messages transmitted over non-secure networks, ensuring that only authorized parties can read the information. Encryption and Decryption Encryption is the process of converting  plaintext data  into  ciphertext , which appears random and meaningless to anyone who does not have the key. Decryption is the reverse process — converting ciphertext back into readable plaintext. The  strength of encryption  depends on several factors, including the algorithm used and the length of the encryption key. Generally, the  longer the key , the harder it is to decrypt the ciphertext without authorization. When choosing an encryption algorithm, it’s best to select one that has been  thoroughly tested and widely used over time , as new or unproven algorithms may have hidden weaknesses. Cryptographic Keys At the he...

Declarative Programming in Angular with Async Pipe and shareReplay

A declarative approach is a way that focuses on writing code that specifies what the application should do, rather than detailing how it should be done. For example, with the async pipe in Angular, we don’t need to write code to manually subscribe to an Observable, handle its data, and update the view. Instead, we simply specify in the template that we want the data from the Observable using the async pipe. Angular handles all the underlying processes to retrieve and display the data It's often used in reactive programming with RxJS and Angular's built-in features, such as the async pipe. export class ProductComponent { product$ = this.productService.getProduct(); constructor(private productService: ProductService) {} } The product observable will hold the product data and the async pipe in the template will automatically subscribe and unsubscribe observable <div *ngIf="product$ | async as product"> <h1>{{ product.name }}</h1> <p>{{...

LINQ - Deferred Execution

Deferred Execution means that queries are not executed immediately at the time it's being created. The benefit of this is to improve performance by avoiding unnecessary executions. It also allows the query to be extendable when needed such as sorting, filtering. In the example below, the queries to retrieve courses are not being executed yet var context = new DbContext(); var courses = context.Courses      .Where(c => c.Level == 1)      .OrderBy(c => c.Name); The query is only executed when one of the following scenarios occurs: Iterating over query variable Calling ToList, ToArray, ToDictionary Calling First, Last, Single, Count, Max, Min, Average For example when we loop through the course or turn the result to a list: foreach ( var c in courses) Console.WriteLine(c.Name); OR context.Courses      .Where(c => c.Level == 1)      .OrderBy(c => c.Name).ToList();