tag:blogger.com,1999:blog-110010742024-03-07T09:24:57.916+05:30Artificial Intelligence, coding and much moreLudmal de silvahttp://www.blogger.com/profile/08871386763862827832noreply@blogger.comBlogger177125tag:blogger.com,1999:blog-11001074.post-10409503061638141142023-12-28T10:25:00.000+05:302023-12-28T10:25:06.396+05:30Ahead of Time Compilation (AOT) in .NET 8<p>Ahead of Time Compilation (AOT) is a technology that has been gaining momentum in the world of software development, and .NET 8 brings exciting advancements in this area. AOT offers significant advantages in terms of performance and security, making it an essential feature for modern .NET applications. Let's explore AOT in .NET 8 and its benefits.</p><p>What is Ahead of Time Compilation (AOT)?</p><p>AOT is a compilation technique that converts high-level code, such as C# or F#, into native machine code before the application is run. Unlike Just-In-Time (JIT) compilation, which compiles code at runtime, AOT compiles code ahead of time, resulting in several advantages: </p><p><b>Performance Boost:</b> AOT-compiled code runs faster since it doesn't require runtime compilation. This leads to reduced startup times and improved overall application performance.</p><p><b>Predictable Behavior: </b>AOT eliminates the JIT warm-up time, ensuring consistent and predictable application behavior across different executions.</p><p><b>Improved Security:</b> AOT reduces the attack surface by removing the need for a JIT compiler at runtime, making it harder for attackers to exploit vulnerabilities.</p><p>.NET 8 introduces enhanced AOT support, making it easier than ever to leverage this technology in your applications. Here are some key improvements:</p><p><b>Single-File AOT: </b>.NET 8 allows you to create single-file AOT-compiled applications, simplifying deployment and distribution.</p><p><b>Cross-Platform AOT: </b>AOT is no longer limited to Windows. .NET 8 brings cross-platform AOT support, enabling AOT-compiled apps to run on various operating systems.</p><p><b>Improved Interoperability:</b> .NET 8 enhances the interoperability between AOT-compiled code and JIT-compiled code, ensuring smooth integration of AOT into existing projects.</p><p>In .NET 8, AOT makes your software faster, safer, and works on different devices. I Love it since it makes the Minimal Apis even faster. </p>Ludmal de silvahttp://www.blogger.com/profile/08871386763862827832noreply@blogger.com0tag:blogger.com,1999:blog-11001074.post-6281393216464256602023-12-17T02:41:00.006+05:302023-12-17T02:41:44.914+05:30How to add Api key validation in Swagger<p>Just a quick post on how to add api key validation in swagger docs. Pretty easy and here is the code to add in <code>AddSwaggerGen</code> in the <code>program.cs</code> file. You can define your own Api key validation middleware.</p>
<pre><div style="background-color: #1e2534; color: #bbbbbb;"><pre style="font-family: 'JetBrains Mono',monospace; font-size: 9.8pt;"><br /></pre><pre style="font-family: 'JetBrains Mono',monospace; font-size: 9.8pt;"><span> </span>builder.<span style="color: #ef596f;">Services</span>.<span style="color: #61afef;">AddSwaggerGen</span>(<span style="color: #d19a66;">c </span>=><br /><span> </span>{<br /> <span> </span><span style="color: #d19a66;">c</span>.<span style="color: #61afef;">AddSecurityDefinition</span>(<span style="color: #89ca78;">"api_key"</span>, <span style="color: #d55fde;">new </span><span style="color: #e5c07b;">OpenApiSecurityScheme<br /></span><span style="color: #e5c07b;"> <span> </span></span>{<br /> <span> </span><span style="color: #ef596f;">Type </span>= <span style="color: #e5c07b;">SecuritySchemeType</span>.<span style="color: #d19a66;">ApiKey</span>,<br /> <span> </span><span style="color: #ef596f;">Name </span>= <span style="color: #89ca78;">"Authorization"</span>,<br /> <span> </span><span style="color: #ef596f;">In </span>= <span style="color: #e5c07b;">ParameterLocation</span>.<span style="color: #d19a66;">Header</span>,<br /> <span> </span><span style="color: #ef596f;">Description </span>= <span style="color: #89ca78;">"API key needed to access the endpoints."<br /></span><span style="color: #89ca78;"> <span> </span></span>});<br /><br /> <span> </span><span style="color: #5c6370;">// Define your security requirement (optional)<br /></span><span style="color: #5c6370;"> <span> </span></span><span style="color: #d19a66;">c</span>.<span style="color: #61afef;">AddSecurityRequirement</span>(<span style="color: #d55fde;">new </span><span style="color: #e5c07b;">OpenApiSecurityRequirement<br /></span><span style="color: #e5c07b;"> <span> </span></span>{<br /> <span> </span> {<br /> <span> </span><span style="color: #d55fde;">new </span><span style="color: #e5c07b;">OpenApiSecurityScheme<br /></span><span style="color: #e5c07b;"> <span> </span> </span>{<br /> <span> </span> <span style="color: #ef596f;">Reference </span>= <span style="color: #d55fde;">new </span><span style="color: #e5c07b;">OpenApiReference<br /></span><span style="color: #e5c07b;"> <span> </span></span>{<br /> <span> </span> <span style="color: #ef596f;">Type </span>= <span style="color: #e5c07b;">ReferenceType</span>.<span style="color: #d19a66;">SecurityScheme</span>,<br /> <span> </span> <span style="color: #ef596f;">Id </span>= <span style="color: #89ca78;">"api_key"<br /></span><span style="color: #89ca78;"> <span> </span> </span>}<br /> <span> </span>},<br /> <span> </span> <span style="color: #d55fde;">new string</span>[] { }<br /> <span> </span>}<br /> <span> </span>});<br /><span> </span>});</pre><pre style="font-family: 'JetBrains Mono',monospace; font-size: 9.8pt;"><br /></pre></div></pre>Ludmal de silvahttp://www.blogger.com/profile/08871386763862827832noreply@blogger.com0tag:blogger.com,1999:blog-11001074.post-49411142711230848442023-12-06T13:18:00.000+05:302023-12-06T13:18:20.677+05:30Title: Announcing My New Book: Crafting Minimal APIs with a Functional Twist!<p> </p><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjcdV29_V7t8DUlRIPGR3eWDDcTrfvtBcpqhcWgT8UMBSATLiABaTdK_JqkRRtHX9eEYDdoyNhOBOtPJb0bQZnDKHhD0FMs4CWNk0IwTEprU7NJmaSNhLCCIp595r30_AX4-IQ7HoYMtwKBQ0ovOW5jd2haG21Gw2Z1eXtKxuE4cX5fNMEwpannOQ/s1834/bookcover.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="1834" data-original-width="1307" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjcdV29_V7t8DUlRIPGR3eWDDcTrfvtBcpqhcWgT8UMBSATLiABaTdK_JqkRRtHX9eEYDdoyNhOBOtPJb0bQZnDKHhD0FMs4CWNk0IwTEprU7NJmaSNhLCCIp595r30_AX4-IQ7HoYMtwKBQ0ovOW5jd2haG21Gw2Z1eXtKxuE4cX5fNMEwpannOQ/s320/bookcover.PNG" width="228" /></a></div>I am thrilled to share with all of you a journey I've passionately embarked on – writing a book dedicated to the world of Minimal APIs with a functional approach. This book is not just a guide; it's a deep dive into the efficient and innovative world of Minimal APIs, explored through the lens of functional programming. I've poured my experience and insights into this work, aiming to offer a fresh perspective on building lean, effective APIs. Whether you're a seasoned developer or just starting out, this book promises to enrich your understanding and skills in creating powerful, minimalistic APIs with a functional twist. Stay tuned for more updates and snippets from my book!<p></p><div><br /></div><div>Coming Soon!</div>Ludmal de silvahttp://www.blogger.com/profile/08871386763862827832noreply@blogger.com0tag:blogger.com,1999:blog-11001074.post-31359229819928842312023-11-15T09:21:00.003+05:302023-11-15T09:21:17.850+05:30Azure Service Bus Queue RetryOptions<p>It's crucial to effectively handle transient errors during message processing. Many developers often attempt to create their own solutions for this issue, but there is already an elegant, built-in solution in the Azure Service Bus client. The key is to create a RetryOption and pass it to the Service Bus client during its creation. This straightforward approach leverages the native capabilities of Azure Service Bus to manage transient errors efficiently.</p><div style="background-color: #1f2430; color: #bbbbbb; font-family: 'JetBrains Mono',monospace; font-size: 9.8pt; white-space: pre;"><span style="color: #d19a66;"><br /></span></div><div style="background-color: #1f2430; color: #bbbbbb; font-family: 'JetBrains Mono',monospace; font-size: 9.8pt; white-space: pre;"><span style="color: #d19a66;"> builder</span>.<span style="color: #61afef;">AddServiceBusClient</span>(settings.<span style="color: #ef596f;">ConnectionStrings</span>.<span style="color: #ef596f;">AzureWebJobsServiceBus</span>).<span style="color: #61afef;">ConfigureOptions</span>(<span style="color: #d19a66;">options </span>=><br /> {<br /> <span style="color: #d19a66;">options</span>.<span style="color: #ef596f;">RetryOptions </span>= <span style="color: #d55fde;">new </span><span style="color: #e5c07b;">ServiceBusRetryOptions</span><span style="color: #7f8591;">()<br /></span><span style="color: #7f8591;"> </span>{<br /> <span style="color: #ef596f;">Delay </span>= <span style="color: #e5c07b;">TimeSpan</span>.<span style="color: #61afef;">FromSeconds</span>(<span style="color: #d19a66;">30</span>),<br /> <span style="color: #ef596f;">MaxDelay </span>= <span style="color: #e5c07b;">TimeSpan</span>.<span style="color: #61afef;">FromSeconds</span>(<span style="color: #d19a66;">30</span>),<br /> <span style="color: #ef596f;">Mode </span>= <span style="color: #e5c07b;">ServiceBusRetryMode</span>.<span style="color: #d19a66;">Exponential</span>,<br /> <span style="color: #ef596f;">MaxRetries </span>= <span style="color: #d19a66;">3<br /></span><span style="color: #d19a66;"> </span>};<br /> });</div><div style="background-color: #1f2430; color: #bbbbbb; font-family: 'JetBrains Mono',monospace; font-size: 9.8pt; white-space: pre;"><br /></div><p> </p>Ludmal de silvahttp://www.blogger.com/profile/08871386763862827832noreply@blogger.com0tag:blogger.com,1999:blog-11001074.post-65339022295319537402023-11-03T01:22:00.003+05:302023-11-03T01:27:02.060+05:30Structured logging .Net<p>Structured logging is an approach to logging that captures data in a way that's easy to parse and analyze, unlike traditional logging, which often involves plain text messages. In structured logging, log entries are composed of discrete fields, such as time stamps, log levels, messages, and other contextual information.</p><p>Here is an example:</p><div style="background-color: #1f2430; color: #bbbbbb; font-family: "JetBrains Mono", monospace; font-size: 9.8pt; white-space: pre;"><span style="color: #ef596f;"><br /></span></div><div style="background-color: #1f2430; color: #bbbbbb; font-family: "JetBrains Mono", monospace; font-size: 9.8pt; white-space: pre;"><span style="color: #ef596f;"> _logger</span>.<span style="color: #61afef;">LogInformation</span>(<span style="color: #89ca78;">"Request received </span><span style="color: #d19a66;">{@Request}</span><span style="color: #89ca78;">"</span>, <span style="color: #d19a66;">request</span>);</div><div style="background-color: #1f2430; color: #bbbbbb; font-family: "JetBrains Mono", monospace; font-size: 9.8pt; white-space: pre;"><br /></div><p><b>Why it is important? Well there are few main reasons. </b></p><p><b>Searchability and Filtering</b>: Structured logs allow for easier searching and filtering since each part of the log message is a distinct field. This makes it straightforward to find all logs related to a specific event, error code, or user action. As you can see in the following example, logs are written in a json format where you can easily search. </p><p></p><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEhlhZzrZMZbu10RrrcKN-J9GCr9cL1G60xLcMHgzQd6-st3hy6Niuw-cLLr7CiKthsxO3juo3EquUbH7iczMWClLPTEy-lm1IX1dCFgfIYwFDMpmbtA6kDyH1mKF7bejN-7uwceNk12HqcwfJm4AZ9wvA5cLUSpPvrlbdyqzrplorcN2JzdBgcjHw" style="margin-left: 1em; margin-right: 1em;"><img alt="" data-original-height="604" data-original-width="2142" height="159" src="https://blogger.googleusercontent.com/img/a/AVvXsEhlhZzrZMZbu10RrrcKN-J9GCr9cL1G60xLcMHgzQd6-st3hy6Niuw-cLLr7CiKthsxO3juo3EquUbH7iczMWClLPTEy-lm1IX1dCFgfIYwFDMpmbtA6kDyH1mKF7bejN-7uwceNk12HqcwfJm4AZ9wvA5cLUSpPvrlbdyqzrplorcN2JzdBgcjHw=w564-h159" width="564" /></a></div><br /><b>Performance: </b>When you use structured logging with deferred execution, such as with Serilog or NLog, the actual string interpolation doesn't happen unless the log level is enabled. This means you avoid unnecessary string manipulation if, for example, your debug logs are turned off in a production environment.<p></p><p><b>Why you shouldn't use logging with string interpolation?</b></p><p>Utilizing string interpolation in logging compromises the capability to efficiently search or filter through log entries. Additionally, it necessitates memory allocation for each log entry created, due to the fact that, unlike structured logging, the template is not established at compile-time, resulting in potentially higher overhead and less optimal performance.</p><div style="background-color: #1f2430; color: #bbbbbb; font-family: "JetBrains Mono", monospace; font-size: 9.8pt; white-space: pre;"><span style="color: #ef596f;"><br /></span></div><div style="background-color: #1f2430; color: #bbbbbb; font-family: "JetBrains Mono", monospace; font-size: 9.8pt; white-space: pre;"><span style="color: #ef596f;"> _logger</span>.<span style="color: #61afef;">LogInformation</span>(<span style="color: #89ca78;">$"Request received {</span><span style="color: #e5c07b;">JsonSerializer</span>.<span style="color: #61afef;">Serialize</span>(<span style="color: #d19a66;">request</span>)<span style="color: #89ca78;">}"</span>);</div><div style="background-color: #1f2430; color: #bbbbbb; font-family: "JetBrains Mono", monospace; font-size: 9.8pt; white-space: pre;"><br /></div><p>In conclusion, it is imperative to exercise discretion when implementing structured logging, particularly to mitigate the risks of inadvertently logging sensitive information or excessively large objects. Developers have the capacity to introduce entire objects into the log data, which could lead to breaches of privacy, security concerns, and potential performance issues due to the increased size and complexity of the log data. Therefore, it is essential to establish and adhere to best practices regarding what data should be logged, ensuring that the logs remain informative and valuable without compromising security or performance.</p>Ludmal de silvahttp://www.blogger.com/profile/08871386763862827832noreply@blogger.com0tag:blogger.com,1999:blog-11001074.post-9739313925359805242023-10-18T11:53:00.001+05:302023-10-18T11:53:41.716+05:30.NET 8 Dependency Injection Keyed Services<p>In .NET 8, Inversion of Control (IOC) has been enhanced to support keyed services, enabling more nuanced dependency injection in application architectures. </p><p>With keyed services, developers can associate specific keys with particular service implementations, granting more fine-grained control over service retrieval from the IOC container. This means that when a consumer requests a service, it can specify a key to receive a particular implementation of the service interface. </p><p>This flexibility is crucial for scenarios where multiple implementations of an interface exist, and the decision to use one over another is determined at runtime. Keyed services in .NET 8’s IOC container therefore facilitate a more dynamic, adaptable, and modular application architecture. </p><p>Here is a simple example of the Keyed services</p><p>Multiple implementation for the same interface </p><div style="background-color: #1f2430; color: #bbbbbb; font-family: "JetBrains Mono", monospace; font-size: 9.8pt; white-space: pre;"><span style="color: #d55fde;"><br /></span></div><div style="background-color: #1f2430; color: #bbbbbb; font-family: "JetBrains Mono", monospace; font-size: 9.8pt; white-space: pre;"><span style="color: #d55fde;">public interface </span><span style="color: #e5c07b;">IGreetingService<br /></span>{<br /> <span style="color: #d55fde;">string </span><span style="color: #61afef;">GetGreeting</span>();<br />}<br /><br /><span style="color: #d55fde;">public class </span><span style="color: #e5c07b;">EnglishGreetingService </span>: <span style="color: #e5c07b;">IGreetingService<br /></span>{<br /> <span style="color: #d55fde;">public string </span><span style="color: #61afef;">GetGreeting</span>() => <span style="color: #89ca78;">"Hello!"</span>;<br />}<br /><br /><span style="color: #d55fde;">public class </span><span style="color: #e5c07b;">SpanishGreetingService </span>: <span style="color: #e5c07b;">IGreetingService<br /></span>{<br /> <span style="color: #d55fde;">public string </span><span style="color: #61afef;">GetGreeting</span>() => <span style="color: #89ca78;">"¡Hola!"</span>;<br />}<br /></div><p>Register the implementation with a key</p><div style="background-color: #1f2430; color: #bbbbbb; font-family: "JetBrains Mono", monospace; font-size: 9.8pt; white-space: pre;">builder.<span style="color: #ef596f;">Services</span>.<span style="color: #61afef;">AddKeyedSingleton</span><<span style="color: #e5c07b;">IGreetingService</span>, <span style="color: #e5c07b;">EnglishGreetingService</span>>(<span style="color: #89ca78;">"English"</span>);<br />builder.<span style="color: #ef596f;">Services</span>.<span style="color: #61afef;">AddKeyedSingleton</span><<span style="color: #e5c07b;">IGreetingService</span>, <span style="color: #e5c07b;">SpanishGreetingService</span>>(<span style="color: #89ca78;">"Spanish"</span>);</div><p>Use the key to inject to the required functions</p><div style="background-color: #1f2430; color: #bbbbbb; font-family: "JetBrains Mono", monospace; font-size: 9.8pt; white-space: pre;"><br /></div><div style="background-color: #1f2430; color: #bbbbbb; font-family: "JetBrains Mono", monospace; font-size: 9.8pt; white-space: pre;">app.<span style="color: #61afef;">MapGet</span>(<span style="color: #89ca78;">"/greet"</span>, <br /> ([<span style="color: #e5c07b;">FromKeyedServices</span>(<span style="color: #89ca78;">"English"</span>)]<span style="color: #e5c07b;">IGreetingService </span><span style="color: #d19a66;">english</span>,<br /> [<span style="color: #e5c07b;">FromKeyedServices</span>(<span style="color: #89ca78;">"Spanish"</span>)]<span style="color: #e5c07b;">IGreetingService </span><span style="color: #d19a66;">spanish</span>) => </div><div style="background-color: #1f2430; color: #bbbbbb; font-family: "JetBrains Mono", monospace; font-size: 9.8pt; white-space: pre;"><span style="color: #89ca78;">$"English:{</span><span style="color: #d19a66;">english</span>.<span style="color: #61afef;">GetGreeting</span>()<span style="color: #89ca78;">} Spanish: {</span><span style="color: #d19a66;">spanish</span>.<span style="color: #61afef;">GetGreeting</span>()<span style="color: #89ca78;">}"</span>)<br /> .<span style="color: #61afef;">WithName</span>(<span style="color: #89ca78;">"GreetingEndpoint"</span>);</div><div style="background-color: #1f2430; color: #bbbbbb; font-family: "JetBrains Mono", monospace; font-size: 9.8pt; white-space: pre;"><br /></div><p>Hope this helps!</p>Ludmal de silvahttp://www.blogger.com/profile/08871386763862827832noreply@blogger.com0tag:blogger.com,1999:blog-11001074.post-50237038449344040412023-06-15T02:10:00.003+05:302023-12-20T11:08:28.666+05:30Request Throttling in Minimal Api<p>Throttling in Minimal API refers to the practice of limiting the number of requests a client can make within a certain time period. It helps prevent abuse and ensures fair usage of API resources. By implementing throttling mechanisms, developers can control the rate at which clients can access their APIs, improving performance and protecting against potential overloading or denial of service attacks.</p><p>
<!-- notionvc: 2fd60492-5306-4e62-96b2-2830ccd3a96d --></p><p>Typically these requests are handled via Api Gateway policies. However, .Net provides build in middleware to handle this effectively.</p><div style="background-color: #1f2430; color: #bbbbbb; font-family: "JetBrains Mono", monospace; font-size: 9.8pt; white-space: pre;"><br /><div style="background-color: #1e2534;"><pre style="font-family: 'JetBrains Mono',monospace; font-size: 9.8pt;"><span> </span>builder.<span style="color: #ef596f;">Services</span>.<span style="color: #61afef;">AddRateLimiter</span>(<span style="color: #d19a66;">r </span>=> <span style="color: #d19a66;">r<br /></span><span style="color: #d19a66;"> <span> </span></span>.<span style="color: #61afef;">AddFixedWindowLimiter</span>(<span style="color: #d19a66;">policyName</span>: <span style="color: #89ca78;">"fixed"</span>, <span style="color: #d19a66;">options </span>=><br /> <span> </span>{<br /> <span> </span><span style="color: #d19a66;">options</span>.<span style="color: #ef596f;">PermitLimit </span>= <span style="color: #d19a66;">4</span>;<br /> <span> </span><span style="color: #d19a66;">options</span>.<span style="color: #ef596f;">Window </span>= <span style="color: #e5c07b;">TimeSpan</span>.<span style="color: #61afef;">FromSeconds</span>(<span style="color: #d19a66;">12</span>);<br /> <span> </span>}));<br /><br /><span style="color: #d55fde;"><span> </span>var </span>app = builder.<span style="color: #61afef;">Build</span>();<br /><span> </span>app.<span style="color: #61afef;">UseRateLimiter</span>();<br /><br /><span> </span>app.<span style="color: #61afef;">MapGet</span>(<span style="color: #89ca78;">"/"</span>, () => <span style="color: #e5c07b;">Results</span>.<span style="color: #61afef;">Ok</span>(<span style="color: #7f8591;">$</span><span style="color: #89ca78;">"Hello World"</span>))<br /> <span> </span>.<span style="color: #61afef;">RequireRateLimiting</span>(<span style="color: #89ca78;">"fixed"</span>);</pre><pre style="font-family: 'JetBrains Mono',monospace; font-size: 9.8pt;"><br /></pre></div></div><p><br /></p>Ludmal de silvahttp://www.blogger.com/profile/08871386763862827832noreply@blogger.com0tag:blogger.com,1999:blog-11001074.post-57263883467047975712023-05-26T00:54:00.002+05:302023-05-26T00:54:10.891+05:30Mediatr Pipelines<p>MediatR is a popular open-source library in C# that provides a simple and elegant way to implement the Mediator pattern and build pipelines in your application. The library helps decouple components by promoting loose coupling and encapsulation of requests and handlers.</p><p>With MediatR, you define requests as plain C# classes representing a unit of work or a command, and you create handlers to process these requests. The library then handles the routing and execution of the requests to their corresponding handlers.</p><p>One of the key features of MediatR is its support for pipelines. A pipeline in MediatR is a sequence of behavior or middleware that can be applied before and after the execution of request handlers. Each behavior in the pipeline can intercept and modify the request, perform additional processing, or handle cross-cutting concerns such as validation, logging, caching, or authorization.</p><p>Following code example shows a simple Logging and Exception handling pipeline for Medatr requests. </p><div style="background-color: #1f2430; color: #bbbbbb; font-family: 'JetBrains Mono',monospace; font-size: 9.8pt; white-space: pre;"><span style="color: #d55fde;">public class </span><span style="color: #e5c07b;">AddUserCommand </span>: IRequest<Unit><br />{<br /> <span style="color: #d55fde;">public string </span><span style="color: #ef596f;">Username </span>{ <span style="color: #61afef;">get</span>; <span style="color: #61afef;">set</span>; }<br /> <span style="color: #d55fde;">public string </span><span style="color: #ef596f;">Email </span>{ <span style="color: #61afef;">get</span>; <span style="color: #61afef;">set</span>; }<br />}<br /><br /><span style="color: #d55fde;">public class </span><span style="color: #7f8591;">AddUserCommandHandler </span>: IRequestHandler<<span style="color: #e5c07b;">AddUserCommand</span>, Unit><br />{<br /> <span style="color: #d55fde;">private readonly </span>IUserService <span style="color: #ef596f;">_userService</span>;<br /><br /> <span style="color: #d55fde;">public </span><span style="color: #e5c07b;">AddUserCommandHandler</span>(IUserService <span style="color: #d19a66;">userService</span>)<br /> {<br /> <span style="color: #ef596f;">_userService </span>= <span style="color: #d19a66;">userService</span>;<br /> }<br /><br /> <span style="color: #d55fde;">public </span><span style="color: #e5c07b;">Task</span><Unit> <span style="color: #61afef;">Handle</span>(<span style="color: #e5c07b;">AddUserCommand </span><span style="color: #d19a66;">request</span>, <span style="color: #e5c07b;">CancellationToken </span><span style="color: #d19a66;">cancellationToken</span>)<br /> {<br /> <span style="color: #ef596f;">_userService</span>.AddUser(<span style="color: #d19a66;">request</span>.<span style="color: #ef596f;">Username</span>, <span style="color: #d19a66;">request</span>.<span style="color: #ef596f;">Email</span>);<br /> <span style="color: #d55fde;">return </span><span style="color: #e5c07b;">Task</span>.<span style="color: #61afef;">FromResult</span>(Unit.Value);<br /> }<br />}</div><p><br /></p><div style="background-color: #1f2430; color: #bbbbbb; font-family: 'JetBrains Mono',monospace; font-size: 9.8pt; white-space: pre;"><span style="color: #5c6370;">//Simple logging behavior<br /></span><span style="color: #d55fde;">public class </span><span style="color: #e5c07b;">LoggingBehavior</span><<span style="color: #e5c07b;">TRequest</span>, <span style="color: #e5c07b;">TResponse</span>> : IPipelineBehavior<<span style="color: #e5c07b;">TRequest</span>, <span style="color: #e5c07b;">TResponse</span>><br />{<br /> <span style="color: #d55fde;">private readonly </span>ILogger<<span style="color: #e5c07b;">LoggingBehavior</span><<span style="color: #e5c07b;">TRequest</span>, <span style="color: #e5c07b;">TResponse</span>>> <span style="color: #ef596f;">_logger</span>;<br /><br /> <span style="color: #d55fde;">public </span><span style="color: #e5c07b;">LoggingBehavior</span>(ILogger<<span style="color: #e5c07b;">LoggingBehavior</span><<span style="color: #e5c07b;">TRequest</span>, <span style="color: #e5c07b;">TResponse</span>>> <span style="color: #d19a66;">logger</span>)<br /> {<br /> <span style="color: #ef596f;">_logger </span>= <span style="color: #d19a66;">logger</span>;<br /> }<br /><br /> <span style="color: #d55fde;">public async </span><span style="color: #e5c07b;">Task</span><<span style="color: #e5c07b;">TResponse</span>> <span style="color: #61afef;">Handle</span>(<span style="color: #e5c07b;">TRequest </span><span style="color: #d19a66;">request</span>, <span style="color: #e5c07b;">CancellationToken </span><span style="color: #d19a66;">cancellationToken</span>, RequestHandlerDelegate<<span style="color: #e5c07b;">TResponse</span>> <span style="color: #d19a66;">next</span>)<br /> {<br /> <span style="color: #ef596f;">_logger</span>.LogInformation(<span style="color: #89ca78;">$"Handling {</span><span style="color: #d55fde;">typeof</span>(<span style="color: #e5c07b;">TRequest</span>).<span style="color: #ef596f;">Name</span><span style="color: #89ca78;">}"</span>);<br /><br /> <span style="color: #d55fde;">var </span>response = <span style="color: #d55fde;">await </span><span style="color: #d19a66;">next</span>();<br /><br /> <span style="color: #ef596f;">_logger</span>.LogInformation(<span style="color: #89ca78;">$"Finished handling {</span><span style="color: #d55fde;">typeof</span>(<span style="color: #e5c07b;">TRequest</span>).<span style="color: #ef596f;">Name</span><span style="color: #89ca78;">}"</span>);<br /><br /> <span style="color: #d55fde;">return </span>response;<br /> }<br />}<br /></div><p><br /></p><div style="background-color: #1f2430; color: #bbbbbb; font-family: 'JetBrains Mono',monospace; font-size: 9.8pt; white-space: pre;"><span style="color: #5c6370;">//Simple Exception handling behavior<br /></span><span style="color: #d55fde;">public class </span><span style="color: #e5c07b;">ExceptionHandlingBehavior</span><<span style="color: #e5c07b;">TRequest</span>, <span style="color: #e5c07b;">TResponse</span>> : IPipelineBehavior<<span style="color: #e5c07b;">TRequest</span>, <span style="color: #e5c07b;">TResponse</span>><br />{<br /> <span style="color: #d55fde;">private readonly </span>ILogger<<span style="color: #e5c07b;">ExceptionHandlingBehavior</span><<span style="color: #e5c07b;">TRequest</span>, <span style="color: #e5c07b;">TResponse</span>>> <span style="color: #ef596f;">_logger</span>;<br /><br /> <span style="color: #d55fde;">public </span><span style="color: #e5c07b;">ExceptionHandlingBehavior</span>(ILogger<<span style="color: #e5c07b;">ExceptionHandlingBehavior</span><<span style="color: #e5c07b;">TRequest</span>, <span style="color: #e5c07b;">TResponse</span>>> <span style="color: #d19a66;">logger</span>)<br /> {<br /> <span style="color: #ef596f;">_logger </span>= <span style="color: #d19a66;">logger</span>;<br /> }<br /><br /> <span style="color: #d55fde;">public async </span><span style="color: #e5c07b;">Task</span><<span style="color: #e5c07b;">TResponse</span>> <span style="color: #61afef;">Handle</span>(<span style="color: #e5c07b;">TRequest </span><span style="color: #d19a66;">request</span>, <span style="color: #e5c07b;">CancellationToken </span><span style="color: #d19a66;">cancellationToken</span>, RequestHandlerDelegate<<span style="color: #e5c07b;">TResponse</span>> <span style="color: #d19a66;">next</span>)<br /> {<br /> <span style="color: #d55fde;">try<br /></span><span style="color: #d55fde;"> </span>{<br /> <span style="color: #d55fde;">return await </span><span style="color: #d19a66;">next</span>();<br /> }<br /> <span style="color: #d55fde;">catch </span>(<span style="color: #e5c07b;">Exception </span>ex)<br /> {<br /> <span style="color: #ef596f;">_logger</span>.LogError(ex, <span style="color: #89ca78;">$"Exception occurred while handling {</span><span style="color: #d55fde;">typeof</span>(<span style="color: #e5c07b;">TRequest</span>).<span style="color: #ef596f;">Name</span><span style="color: #89ca78;">}"</span>);<br /> <span style="color: #d55fde;">throw</span>;<br /> }<br /> }<br />}</div><p><br /></p><p>Next step is to configure the pipeline in startup class.</p><div style="background-color: #1f2430; color: #bbbbbb; font-family: 'JetBrains Mono',monospace; font-size: 9.8pt; white-space: pre;"><span style="color: #5c6370;">//Configure the MediatR pipeline in StartUp Class<br /></span><span style="color: #d55fde;">var </span>services = <span style="color: #d55fde;">new </span>ServiceCollection();<br />services.AddMediatR(<span style="color: #d55fde;">typeof</span>(Startup));<br /><br /><span style="color: #5c6370;">// Register any other dependencies your handlers might require<br /></span>services.AddTransient<IUserService, UserService>();<br /><br /><span style="color: #5c6370;">// Configure pipeline behaviors<br /></span>services.AddTransient(<span style="color: #d55fde;">typeof</span>(IPipelineBehavior<,>), <span style="color: #d55fde;">typeof</span>(<span style="color: #e5c07b;">LoggingBehavior</span><,>));<br />services.AddTransient(<span style="color: #d55fde;">typeof</span>(IPipelineBehavior<,>), <span style="color: #d55fde;">typeof</span>(<span style="color: #e5c07b;">ExceptionHandlingBehavior</span><,>));</div><p>By utilizing MediatR's pipeline capabilities, you can easily insert and compose multiple behaviors in a flexible manner, providing a powerful way to modify and extend the behavior of your application's requests without tightly coupling them to specific implementations.</p><p>The pipeline in MediatR is typically implemented using a combination of decorators and the Decorator Pattern. Decorators wrap and modify the behavior of the underlying handler, allowing you to add or modify functionality at various points in the pipeline.</p><p>In summary, MediatR is a versatile library that simplifies the implementation of the Mediator pattern and facilitates the creation of pipelines in C# applications. It promotes decoupling, modularity, and extensibility, making it easier to handle requests, apply behaviors, and build scalable and maintainable applications.</p><p><a href="https://github.com/jbogard/MediatR">https://github.com/jbogard/MediatR </a></p>Ludmal de silvahttp://www.blogger.com/profile/08871386763862827832noreply@blogger.com0tag:blogger.com,1999:blog-11001074.post-57945927571930872272023-05-12T15:06:00.007+05:302023-05-12T15:10:16.549+05:30Simplified Messaging using MassTransit<p>MassTransit is an open-source message bus framework for .NET that makes it easier to build distributed applications by providing a way to communicate between different components or services within a system. <a href="https://masstransit.io/" target="_blank">https://masstransit.io/</a></p><p>In simple terms, MassTransit allows different parts of a system to send and receive messages, regardless of where they are located or how they are implemented. It provides a way to abstract away the details of communication protocols and message serialization, allowing developers to focus on the business logic of their applications. </p><p>I've used MassTransit many years ago and wanted to highlight the usage of it and the simplicty it provide to integrate with different message brokers. </p><p><br /></p><p></p><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEj_ElnzNhAvDDJv7Uufh71N5uJw_LgQVWoIde9OFEpfXGcH7UXV92xBfdL7jbNBjuSJpfzsT8M-MEI5M5Kxbh_tHGHSaucjfTuwgc_ZG4cmTJ5AEEZoNXWXArW9eCZCciYmkyAnGoszaevhueR-lRfegNkP-3OxCp3A8Z6p5IYqy6CEu7ixPI4" style="margin-left: 1em; margin-right: 1em;"><img alt="" data-original-height="1668" data-original-width="2286" height="233" src="https://blogger.googleusercontent.com/img/a/AVvXsEj_ElnzNhAvDDJv7Uufh71N5uJw_LgQVWoIde9OFEpfXGcH7UXV92xBfdL7jbNBjuSJpfzsT8M-MEI5M5Kxbh_tHGHSaucjfTuwgc_ZG4cmTJ5AEEZoNXWXArW9eCZCciYmkyAnGoszaevhueR-lRfegNkP-3OxCp3A8Z6p5IYqy6CEu7ixPI4" width="320" /></a></div><div class="separator" style="clear: both; text-align: center;"><br /></div><div class="separator" style="clear: both; text-align: left;">I have written a .Net 7 mininal api sample in MassTransit. Have a look at it and see how simple it is to integrate. This will eliminate tons of plumbing code to get the messaging working. </div><div class="separator" style="clear: both; text-align: left;"><br /></div><h2 style="clear: both; text-align: left;"><div style="background-color: #1f2430; font-family: "JetBrains Mono", monospace; font-size: 10.5pt; white-space: pre;"><span style="color: #bbbbbb;"><br /></span><span style="color: #7f8591;"> </span><span style="color: white;"> <a href="HTTPS://GITHUB.COM/LUDMAL/MASSTRANSITSAMPLE"><span style="color: white;">HTTPS://GITHUB.COM/LUDMAL/MASSTRANSITSAMPLE</span></a></span><span style="color: #5c6370;"><br /></span></div><div style="background-color: #1f2430; color: #bbbbbb; font-family: 'JetBrains Mono',monospace; font-size: 10.5pt; white-space: pre;"><span style="color: #5c6370;"><br /></span></div></h2><div class="separator" style="clear: both; text-align: left;"><br /></div><div class="separator" style="clear: both; text-align: left;"><br /></div><br /><br /><p></p>Ludmal de silvahttp://www.blogger.com/profile/08871386763862827832noreply@blogger.com0tag:blogger.com,1999:blog-11001074.post-84616571428795050502023-04-28T01:25:00.005+05:302023-04-28T01:25:51.900+05:30Minimal Api<p>Minimal API in .NET Core is a new approach to building web APIs with minimal ceremony and less boilerplate code. It is a feature that was introduced in .NET 6 and has been improved in subsequent versions, including .NET 7.</p><p>With Minimal API, developers can create HTTP endpoints with fewer lines of code and without having to set up complex routing or middleware configurations. This is achieved by providing a simplified syntax for defining endpoints, which reduces the amount of code required to create an API.</p><p>A simple example:</p><div style="background-color: #1f2430; color: #bbbbbb; font-family: 'JetBrains Mono',monospace; font-size: 9.8pt; white-space: pre;"><br /><span style="color: #d55fde;"><span> </span>using </span>Microsoft.AspNetCore.Mvc;<br /><span style="color: #d55fde;"><span> </span>using </span>Microsoft.Extensions.Logging;<br /><br /><span style="color: #d55fde;"><span> </span>var </span>builder = <span style="color: #e5c07b;">WebApplication</span>.CreateBuilder(<span style="color: #d19a66;">args</span>);<br /><br /><span style="color: #d55fde;"><span> </span>var </span>app = builder.Build();<br /><br /><span> </span>app.MapGet(<span style="color: #89ca78;">"/"</span>, () => <span style="color: #89ca78;">"Hello World!"</span>);<br /><br /><span> </span>app.Run();</div><div style="background-color: #1f2430; color: #bbbbbb; font-family: 'JetBrains Mono',monospace; font-size: 9.8pt; white-space: pre;"><br /></div><p>The goal of Minimal API is to enable developers to focus on writing business logic rather than dealing with infrastructure concerns. It provides a streamlined development experience, making it easier and faster to build APIs. Additionally, Minimal API integrates seamlessly with other .NET Core technologies, such as Dependency Injection and Entity Framework Core.</p><p>Another example for coherent code structure:</p><div style="background-color: #1f2430; color: #bbbbbb; font-family: 'JetBrains Mono',monospace; font-size: 9.8pt; white-space: pre;"><span style="color: #d55fde;">using </span>Microsoft.AspNetCore.Mvc;<br /><span style="color: #d55fde;">using </span>Microsoft.Extensions.Logging;<br /><br /><span style="color: #d55fde;">var </span>builder = <span style="color: #e5c07b;">WebApplication</span>.CreateBuilder(<span style="color: #d19a66;">args</span>);<br /><br /><span style="color: #d55fde;">var </span>app = builder.Build();<br /><br />app.MapPost(<span style="color: #89ca78;">"/change-password"</span>, <span style="color: #e5c07b;">UserEndpoints</span>.<span style="color: #61afef;">ChangePassword</span>);<br /><br />app.Run();<br /><br /><span style="color: #d55fde;">public static class </span><span style="color: #e5c07b;">UserEndpoints<br /></span>{<br /> <span style="color: #d55fde;">public static async </span><span style="color: #e5c07b;">Task</span><<span style="color: #e5c07b;">IResult</span>> <span style="color: #61afef;">ChangePassword</span>(</div><div style="background-color: #1f2430; color: #bbbbbb; font-family: 'JetBrains Mono',monospace; font-size: 9.8pt; white-space: pre;"><span style="color: #e5c07b;"><span> </span><span> </span><span> </span><span> </span><span> </span><span> </span><span> </span><span> </span><span> </span>HttpContext </span><span style="color: #d19a66;">context</span>, </div><div style="background-color: #1f2430; color: #bbbbbb; font-family: 'JetBrains Mono',monospace; font-size: 9.8pt; white-space: pre;"><span style="color: #e5c07b;"><span> </span><span> </span><span> </span><span> </span><span> </span><span> </span><span> </span><span> </span><span> </span>ChangePasswordRequest </span><span style="color: #d19a66;">request</span>,<br /> <span> </span><span> </span><span> </span><span> </span><span> </span><span> </span><span> </span><span style="color: #e5c07b;">IUserService </span><span style="color: #d19a66;">userService</span>)<br /> {<br /> <span style="color: #5c6370;">//Logic here<br /></span><span style="color: #5c6370;"> </span><span style="color: #d55fde;">return await </span><span style="color: #e5c07b;">Task</span>.<span style="color: #61afef;">FromResult</span>(<span style="color: #e5c07b;">Results</span>.<span style="color: #61afef;">Ok</span>());<br /> }<br />}</div><p>Overall, Minimal API in .NET Core provides a lightweight, modern approach to building web APIs, enabling developers to quickly create high-performance, scalable APIs with minimal effort. </p><p>I will be writing quite a bit of minimal api usages and best practices in future. So stay tuned. </p>Ludmal de silvahttp://www.blogger.com/profile/08871386763862827832noreply@blogger.com0tag:blogger.com,1999:blog-11001074.post-62574645626626158652023-04-26T11:32:00.005+05:302023-04-26T11:34:58.128+05:30Pattern matching using C# Switch expressions<p>Switch expressions pattern matching provides developers with a concise and expressive way to handle complex conditional logic. It allows you to match patterns within a switch expression, rather than just values.</p><p>One of the key benefits of switch expressions pattern matching is that it reduces the amount of code you need to write to handle different cases. This can make your code more readable, maintainable, and efficient.</p><p>Here's an example of how you can use switch expressions pattern matching in C#:</p><div style="background-color: #1f2430; color: #bbbbbb; font-family: "JetBrains Mono", monospace; font-size: 9.8pt; white-space: pre;"><span style="color: #d55fde;">public string </span><span style="color: #61afef;">Execute</span>(<span style="color: #e5c07b;">ICommand </span><span style="color: #d19a66;">command</span>) => <span style="color: #7f8591;">(</span><span style="color: #d19a66;">command</span><span style="color: #7f8591;">) </span><span style="color: #d55fde;">switch<br /></span>{<br /> <span style="color: #e5c07b;">OpenCommand </span><span style="color: #7f8591;">o </span>=> <span style="color: #89ca78;">"Open Command"</span>,<br /> <span style="color: #e5c07b;">CloseCommand </span><span style="color: #7f8591;">o </span>=> <span style="color: #89ca78;">"Close Command"</span>,<br /> <span style="color: #e5c07b;">ExecuteCommand </span><span style="color: #7f8591;">o </span>=> <span style="color: #89ca78;">"Execute Command"</span>,<br /> _ => <span style="color: #d55fde;">throw new </span><span style="color: #e5c07b;">ArgumentOutOfRangeException</span>(<span style="color: #d55fde;">nameof</span>(<span style="color: #d19a66;">command</span>), <span style="color: #d19a66;">command</span>, <span style="color: #d55fde;">null</span>)<br />};</div><p>In the above example, we define a method called Execute that takes an ICommand object as a parameter. We then use a switch expression to match the type of the command and return the corresponding action. Also it is far easier to use pattern matching on the properties of the paratmers. </p><div style="background-color: #1f2430; color: #bbbbbb; font-family: "JetBrains Mono", monospace; font-size: 9.8pt; white-space: pre;"><span style="color: #d55fde;">public string </span><span style="color: #61afef;">Execute</span>(<span style="color: #e5c07b;">ICommand </span><span style="color: #d19a66;">command</span>) => <span style="color: #7f8591;">(</span><span style="color: #d19a66;">command</span><span style="color: #7f8591;">) </span><span style="color: #d55fde;">switch<br /></span>{<br /> { <span style="color: #ef596f;">Valid</span>: <span style="color: #d55fde;">true </span>} <span style="color: #d55fde;">and </span>{<span style="color: #ef596f;">Value</span>: > <span style="color: #d19a66;">10 </span>}=> <span style="color: #89ca78;">"Open Command"</span>,<br /> { <span style="color: #ef596f;">Valid</span>: <span style="color: #d55fde;">false </span>} <span style="color: #d55fde;">and </span>{<span style="color: #ef596f;">Value</span>: <= <span style="color: #d19a66;">10 </span>} => <span style="color: #89ca78;">"Close Command"</span>,<br /> <span style="color: #e5c07b;">ExecuteCommand </span><span style="color: #7f8591;">o </span>=> <span style="color: #89ca78;">"Execute Command"</span>,<br /> _ => <span style="color: #d55fde;">throw new </span><span style="color: #e5c07b;">ArgumentOutOfRangeException</span>(<span style="color: #d55fde;">nameof</span>(<span style="color: #d19a66;">command</span>), <span style="color: #d19a66;">command</span>, <span style="color: #d55fde;">null</span>)<br />};<br /></div><p>The switch expression uses the arrow notation (=>) to match the pattern and return the result. The _ symbol acts as a catch-all case, which throws an exception if an invalid command is passed in.</p><p>Tuples significantly improves the pattern matching as shown in the below example.</p><div style="background-color: #1f2430; color: #bbbbbb; font-family: "JetBrains Mono", monospace; font-size: 9.8pt; white-space: pre;"><span style="color: #d55fde;">private static string </span><span style="color: #7f8591;">FormatMobileNumber</span>(<span style="color: #d55fde;">string </span><span style="color: #d19a66;">number</span>) =><br /> (<span style="color: #d19a66;">number</span>.<span style="color: #61afef;">StartsWith</span>(<span style="color: #89ca78;">"+6"</span>), <span style="color: #d19a66;">number</span>.<span style="color: #61afef;">StartsWith</span>(<span style="color: #89ca78;">"6"</span>), <span style="color: #d19a66;">number</span>.<span style="color: #61afef;">StartsWith</span>(<span style="color: #89ca78;">"04"</span>)) <span style="color: #d55fde;">switch<br /></span><span style="color: #d55fde;"> </span>{<br /> (<span style="color: #d55fde;">true</span>, _, _) => <span style="color: #d19a66;">number</span>,<br /> (<span style="color: #d55fde;">false</span>, <span style="color: #d55fde;">true</span>, _) => <span style="color: #89ca78;">$"+61{</span><span style="color: #d19a66;">number</span>[<span style="color: #d19a66;">1</span><span style="color: #e5c07b;">..</span>]<span style="color: #89ca78;">}"</span>,<br /> (<span style="color: #d55fde;">false</span>, <span style="color: #d55fde;">false</span>, <span style="color: #d55fde;">true</span>) => <span style="color: #89ca78;">$"+61{</span><span style="color: #d19a66;">number</span>[<span style="color: #d19a66;">1</span><span style="color: #e5c07b;">..</span>]<span style="color: #89ca78;">}"</span>,<br /> _ => <span style="color: #d19a66;">number<br /></span><span style="color: #d19a66;"> </span>};</div><p>Overall, switch expressions pattern matching is a powerful feature in C# that can help you write more expressive and maintainable code. Whether you're working on a small project or a large enterprise application, it's definitely worth considering using switch expressions pattern matching in your code.</p><p> </p>Ludmal de silvahttp://www.blogger.com/profile/08871386763862827832noreply@blogger.com0tag:blogger.com,1999:blog-11001074.post-7608565384191358682017-04-22T04:37:00.000+05:302017-04-22T04:37:12.650+05:30AI Product improvement cycle<div dir="ltr" style="line-height: 1.7999999999999998; margin-bottom: 0pt; margin-left: 18pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 12pt; white-space: pre-wrap;">Artificial Intelligence (AI) & Machine Learning(ML) has significant advantage over traditional algorithms which we used to improve our products. This is mainly due to the fact that ML improves with big data unlike the traditional algorithms. </span></div>
<div dir="ltr" style="line-height: 1.7999999999999998; margin-bottom: 0pt; margin-left: 18pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 12pt; white-space: pre-wrap;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEham-YptsBLq9BgSprrIn005HA0_59k9BXXBMknUuPn5h4REAc3SbykLJOlD4CBQlTtpdvYAEyYgLEDKTs3F_A75-wgBO6IwgnFeo9Z_Gcrpqi2BxvLnysZtoCCJq8cE_1uGSBsjg/s1600/ml.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="239" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEham-YptsBLq9BgSprrIn005HA0_59k9BXXBMknUuPn5h4REAc3SbykLJOlD4CBQlTtpdvYAEyYgLEDKTs3F_A75-wgBO6IwgnFeo9Z_Gcrpqi2BxvLnysZtoCCJq8cE_1uGSBsjg/s320/ml.png" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<b id="docs-internal-guid-bf69d480-92b9-6ebc-8ee6-18a5b0c85032" style="font-weight: normal;"><br /></b>
<div dir="ltr" style="line-height: 1.7999999999999998; margin-bottom: 0pt; margin-left: 18pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 12pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Big data is the key for the ML & AI. It helps ML learns and improve the accuracy. This is the main reason, companies such as Google benefits vastly from ML & AI. Moreover, AI & ML can improve the product significantly. When the product quality improves more users tend to use it and this generates more data. More data can be used for ML & AI to improve the product hence an infinite loop of improving the product. This is what I called -- “AI Product improvement cycle”</span></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEigYchJhfoCN-CwO3IYBR02C-j_c85LG1ZeuqkvlpHgt8pWAHUkmVUh6kJ939qROANl6vm07XzdTKYNanGKlAUuGwh2MgErNe7gstDp8tfoeuK3Nr2q3W71lDkkkaDfksRKWz5mWw/s1600/m2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEigYchJhfoCN-CwO3IYBR02C-j_c85LG1ZeuqkvlpHgt8pWAHUkmVUh6kJ939qROANl6vm07XzdTKYNanGKlAUuGwh2MgErNe7gstDp8tfoeuK3Nr2q3W71lDkkkaDfksRKWz5mWw/s320/m2.png" width="240" /></a></div>
<br /><br />
<div dir="ltr" style="line-height: 1.7999999999999998; margin-bottom: 0pt; margin-left: 18pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 12pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">AI & ML has become an essential part of any product development. Therefore, analysing and implementing ML algorithms will improve the quality of the product which can leads to more users. </span></div>
Ludmal de silvahttp://www.blogger.com/profile/08871386763862827832noreply@blogger.com0tag:blogger.com,1999:blog-11001074.post-88628442526435527882016-10-20T08:09:00.005+05:302016-10-20T08:11:39.523+05:30AWS.Net - Simple library for AWS services. i.e. S3, SQS & SESHave worked on many AWS projects but found their library wasn't designed for simplicity. So thought of writing my own library for my pet projects with AWS. It's very simple and easy to integrate S3, SQS & SES.<br />
<div>
<br /></div>
<div>
<a href="https://github.com/ludmal/AWS.Net">Visit my Github project for more details on how to use it.</a> - <a href="https://github.com/ludmal/AWS.Net">https://github.com/ludmal/AWS.Net</a><br />
<div>
<br /></div>
<div>
For example, sending a message to the SQS is easy as this. </div>
<div>
<pre style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; color: #333333; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 13.6px; font-stretch: normal; line-height: 1.45; overflow: auto; padding: 16px; word-break: normal; word-wrap: normal;"><span class="pl-k" style="box-sizing: border-box; color: #a71d5d;">var</span> service <span class="pl-k" style="box-sizing: border-box; color: #a71d5d;">=</span> <span class="pl-k" style="box-sizing: border-box; color: #a71d5d;">new</span> <span class="pl-en" style="box-sizing: border-box; color: #795da3;">SqsService</span><span class="pl-k" style="box-sizing: border-box; color: #a71d5d;"><</span>EmailMessage<span class="pl-k" style="box-sizing: border-box; color: #a71d5d;">></span>(<span class="pl-k" style="box-sizing: border-box; color: #a71d5d;">new</span> <span class="pl-en" style="box-sizing: border-box; color: #795da3;">AwsCredentials</span>
{
RegionEndpoint <span class="pl-k" style="box-sizing: border-box; color: #a71d5d;">=</span> <span class="pl-smi" style="box-sizing: border-box;">RegionEndpoint</span>.<span class="pl-smi" style="box-sizing: border-box;">USWest2</span>
});
<span class="pl-smi" style="box-sizing: border-box;">service</span>.<span class="pl-smi" style="box-sizing: border-box;">QueueUrl</span> <span class="pl-k" style="box-sizing: border-box; color: #a71d5d;">=</span> <span class="pl-smi" style="box-sizing: border-box;">ConfigurationManager</span>.<span class="pl-smi" style="box-sizing: border-box;">AppSettings</span>[<span class="pl-s" style="box-sizing: border-box; color: #183691;"><span class="pl-pds" style="box-sizing: border-box;">"</span>EmailQueue<span class="pl-pds" style="box-sizing: border-box;">"</span></span>];
<span class="pl-k" style="box-sizing: border-box; color: #a71d5d;">var</span> response <span class="pl-k" style="box-sizing: border-box; color: #a71d5d;">=</span> <span class="pl-smi" style="box-sizing: border-box;">service</span>.<span class="pl-en" style="box-sizing: border-box; color: #795da3;">Push</span>(<span class="pl-k" style="box-sizing: border-box; color: #a71d5d;">new</span> <span class="pl-en" style="box-sizing: border-box; color: #795da3;">HelloEmail</span>());</pre>
</div>
<div>
<br /></div>
<div>
And retrieving the message with Generic object is very simple.</div>
<div>
<pre style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; color: #333333; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 13.6px; font-stretch: normal; line-height: 1.45; overflow: auto; padding: 16px; word-break: normal; word-wrap: normal;"><span class="pl-k" style="box-sizing: border-box; color: #a71d5d;">var</span> service <span class="pl-k" style="box-sizing: border-box; color: #a71d5d;">=</span> <span class="pl-k" style="box-sizing: border-box; color: #a71d5d;">new</span> <span class="pl-en" style="box-sizing: border-box; color: #795da3;">SqsService</span><span class="pl-k" style="box-sizing: border-box; color: #a71d5d;"><</span>EmailMessage<span class="pl-k" style="box-sizing: border-box; color: #a71d5d;">></span>(<span class="pl-k" style="box-sizing: border-box; color: #a71d5d;">new</span> <span class="pl-en" style="box-sizing: border-box; color: #795da3;">AwsCredentials</span>
{
<span class="pl-c" style="box-sizing: border-box; color: #969896;">//SQS Service Region</span>
RegionEndpoint <span class="pl-k" style="box-sizing: border-box; color: #a71d5d;">=</span> <span class="pl-smi" style="box-sizing: border-box;">RegionEndpoint</span>.<span class="pl-smi" style="box-sizing: border-box;">USWest2</span>
});
<span class="pl-c" style="box-sizing: border-box; color: #969896;">//SQS Queue Url</span>
<span class="pl-smi" style="box-sizing: border-box;">service</span>.<span class="pl-smi" style="box-sizing: border-box;">QueueUrl</span> <span class="pl-k" style="box-sizing: border-box; color: #a71d5d;">=</span> <span class="pl-smi" style="box-sizing: border-box;">ConfigurationManager</span>.<span class="pl-smi" style="box-sizing: border-box;">AppSettings</span>[<span class="pl-s" style="box-sizing: border-box; color: #183691;"><span class="pl-pds" style="box-sizing: border-box;">"</span>EmailQueue<span class="pl-pds" style="box-sizing: border-box;">"</span></span>];
<span class="pl-k" style="box-sizing: border-box; color: #a71d5d;">var</span> items <span class="pl-k" style="box-sizing: border-box; color: #a71d5d;">=</span> <span class="pl-smi" style="box-sizing: border-box;">service</span>.<span class="pl-en" style="box-sizing: border-box; color: #795da3;">Process</span>();</pre>
</div>
</div>
Ludmal de silvahttp://www.blogger.com/profile/08871386763862827832noreply@blogger.com1tag:blogger.com,1999:blog-11001074.post-38225059459033701952016-04-22T01:34:00.002+05:302016-04-22T01:42:30.673+05:30ChalkChalk is a simple library written by me to output console text with different colors. Enough said! Get the nuget package and start using it.<br />
<br />
<pre style="background: #000; color: white; font-family: "arial"; font-size: 14px; margin: 0; padding: 10px; text-align: left; width: 99%;"><code style="background-color: black word-wrap: normal; color: white;">Install-Package Chalk
</code></pre>
<br />
How to use:<br />
<pre style="background: #f7f7f7; border-radius: 5px; color: black; font-family: "arial"; font-size: 14px; margin: 0; padding: 10px; text-align: left; width: 99%;"><code normal="" word-wrap:="">Chalk.Blue("Blue")
Chalk.Red("Red")
Chalk.Green("Green")
Chalk.Gray("Gray")
Chalk.Yellow("Yellow")
</code></pre>
<br />
<a href="https://github.com/ludmal/chalk"><b>Here is the Github link with Examples.</b></a>Ludmal de silvahttp://www.blogger.com/profile/08871386763862827832noreply@blogger.com0tag:blogger.com,1999:blog-11001074.post-73876294014663273512015-05-29T05:29:00.000+05:302016-04-22T01:40:01.066+05:30Better AngularJs service for SignalR<br />
SignalR makes our lives easy when buidling realtime webapps. Needless to say AngularJs has already found a permanant role in our webapps. Here is a quick AngularJs service which I wrote to integrate SignalR broadcasts.<br />
<br />
<br />
<pre style="background: #f7f7f7; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 10px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> var app = angular.module('signalr', []);
app.factory('SignalRService', ['$rootScope', '$window', function ($rootScope, $window) {
var srv = {};
srv.init = function (hub) {
var connection = $.hubConnection();
var proxy = connection.createHubProxy(hub);
proxy.on('broadcast', function (jobs) {
angular.forEach(jobs, function (item) {
console.log(item.EventName, item.Data);
$rootScope.$broadcast(item.EventName, item.Data);
});
});
connection.start()
.done(function () {
console.log('Connected');
})
.fail(function () { console.log('Failed to connect!'); });
};
return srv;
}]);
</code></pre>
<div>
<br /></div>
Ludmal de silvahttp://www.blogger.com/profile/08871386763862827832noreply@blogger.com0tag:blogger.com,1999:blog-11001074.post-83093585978446420172014-08-12T15:26:00.001+05:302014-08-12T15:38:51.178+05:30Future of Web Development : AnuglarJs + REST API ?It's a paradigm shift in web development. Unlike the days we used to develop web apps using classic Asp, Asp.Net or Php, the focus has changed into decoupling the frontend and backend. More and more web apps are adapting this methodology mainly due the evolution of mobile usage.<br />
<br />
With mobile & tablets revolution, developers are constantly finding ways to develop a single app to support all of the different devices and their browser sizes. It has been always difficult and costly to develop native apps for various different mobile platforms. Although the responsive design was the solution, it is extremely hard to avoid unnecessary page reloads while using the web app on mobile devices.<br />
<br />
SPA - Single Page App concept was the solution to the problem. However until the release of AngularJs, it wasn't very enjoyable development for the developers. There were plethora of MVC JavaScript libraries but none of them was even nearly good as AngularJs. While the AnugularJs solves the frontend problem, the backend lies in RESTful API's. The main advantage in this architecture is the app is decoupled hence frontend and backend can be developed using different technologies. For example, while the frontend is AngularJs, the backend API can be developed in Node.js, Asp.Net Web API or any other API provider technology.<br />
<br />
<div>
The basics of AngularJs + API driven Web app.</div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg7cLzer8gruixdnOr3OnTRbq-BTbybXm4mBw9fIotX6_vpEvVmV3tsRu8kR-Oume1VD53JxlBv2irD8d2TQbdb55IUoAEAVKJYR8vDHZfkHpTMJtQRxEy6G0_6HWomF6OwOzSyQg/s1600/rest1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg7cLzer8gruixdnOr3OnTRbq-BTbybXm4mBw9fIotX6_vpEvVmV3tsRu8kR-Oume1VD53JxlBv2irD8d2TQbdb55IUoAEAVKJYR8vDHZfkHpTMJtQRxEy6G0_6HWomF6OwOzSyQg/s1600/rest1.png" height="135" width="320" /></a></div>
<br />
<div>
This should be the preferred approach for any new web application development. However for the apps which are monolith or legacy could still gain the benefits by modularizing the APIs as shown in the following example. For example, some parts of the apps can be decoupled using an API layer on top of the legacy/monolith web application.</div>
<div>
<br /></div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjcLPzwyh79HwKNbzKhIuKs4eozv9cBY58_nouEM1xPjT-20tVU4GdgQbC8zthsRCMouPCRJJxoVQQoQXo5iiVIRIuX-sL5-1r-f3cH03j1lhlfWG1-f8THUkSbWehyn6hITJO8cA/s1600/rest2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjcLPzwyh79HwKNbzKhIuKs4eozv9cBY58_nouEM1xPjT-20tVU4GdgQbC8zthsRCMouPCRJJxoVQQoQXo5iiVIRIuX-sL5-1r-f3cH03j1lhlfWG1-f8THUkSbWehyn6hITJO8cA/s1600/rest2.png" height="224" width="320" /></a></div>
<div>
One of the best approaches to write a scalable backend API is by using micro-services architecture, which will be discussed in my next post.<br />
<br />
Writing scalable & high performance web applications have been a challenge, by making it device agnostic is even challenging. It is evident that AngujarJs + APIs solve the challenging nature of web apps to support multiple devices and increase the performance. </div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
Ludmal de silvahttp://www.blogger.com/profile/08871386763862827832noreply@blogger.com0tag:blogger.com,1999:blog-11001074.post-39446597738382460812014-02-11T02:43:00.000+05:302014-02-11T02:44:17.891+05:30Sending Emails using Templates Here is a simple Python module to send emails using HTML/TEXT templates. Feel free to use the code.<br />
<br />
<a href="https://github.com/ludmal/pylib">https://github.com/ludmal/pylib</a><br />
<h2 style="border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #333333; cursor: text; font-family: Helvetica, arial, freesans, clean, sans-serif; font-size: 2em; line-height: 1.7; margin: 1em 0px 15px; padding: 0px; position: relative;">
Step 1:</h2>
<div style="box-sizing: border-box; color: #333333; font-family: Helvetica, arial, freesans, clean, sans-serif; font-size: 15px; line-height: 25.5px; margin-bottom: 15px; margin-top: 15px;">
Create a TEXT/HTML file with the Keys as below</div>
<pre style="background-color: #f8f8f8; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221); box-sizing: border-box; color: #333333; font-family: Consolas, 'Liberation Mono', Courier, monospace; font-size: 13px; line-height: 19px; margin-bottom: 15px; margin-top: 15px; overflow: auto; padding: 6px 10px; word-wrap: normal;"><code style="background-color: transparent; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: none; box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Courier, monospace; font-size: 12px; margin: 0px; padding: 0px; word-wrap: normal;">Hi [username],
Thank you for your registration.
Best regards,
[from]
[url]
</code></pre>
<h2 style="border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #333333; cursor: text; font-family: Helvetica, arial, freesans, clean, sans-serif; font-size: 2em; line-height: 1.7; margin: 1em 0px 15px; padding: 0px; position: relative;">
<a class="anchor" href="https://github.com/ludmal/pylib#step-2" name="step-2" style="bottom: 0px; box-sizing: border-box; color: #4183c4; cursor: pointer; display: block; left: 0px; margin-left: -30px; padding-left: 30px; padding-right: 6px; position: absolute; text-decoration: none; top: 0px;"></a>Step 2:</h2>
<div style="box-sizing: border-box; color: #333333; font-family: Helvetica, arial, freesans, clean, sans-serif; font-size: 15px; line-height: 25.5px; margin-bottom: 15px; margin-top: 15px;">
Create a template passing the values to replace with the keys in template</div>
<pre style="background-color: #f8f8f8; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221); box-sizing: border-box; color: #333333; font-family: Consolas, 'Liberation Mono', Courier, monospace; font-size: 13px; line-height: 19px; margin-bottom: 15px; margin-top: 15px; overflow: auto; padding: 6px 10px; word-wrap: normal;"><code style="background-color: transparent; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: none; box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Courier, monospace; font-size: 12px; margin: 0px; padding: 0px; word-wrap: normal;">values = {}
values['username'] = 'Ludmal de silva!'
values['from'] = 'The Team'
values['url'] = 'http://www.ludmal.com'
temp = EmailTemplate(template_name='welcome.txt', values=values)
</code></pre>
<h2 style="border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #333333; cursor: text; font-family: Helvetica, arial, freesans, clean, sans-serif; font-size: 2em; line-height: 1.7; margin: 1em 0px 15px; padding: 0px; position: relative;">
<a class="anchor" href="https://github.com/ludmal/pylib#step-3" name="step-3" style="bottom: 0px; box-sizing: border-box; color: #4183c4; cursor: pointer; display: block; left: 0px; margin-left: -30px; padding-left: 30px; padding-right: 6px; position: absolute; text-decoration: none; top: 0px;"></a>Step 3:</h2>
<div style="box-sizing: border-box; color: #333333; font-family: Helvetica, arial, freesans, clean, sans-serif; font-size: 15px; line-height: 25.5px; margin-bottom: 15px; margin-top: 15px;">
Create a Mail Server</div>
<pre style="background-color: #f8f8f8; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221); box-sizing: border-box; color: #333333; font-family: Consolas, 'Liberation Mono', Courier, monospace; font-size: 13px; line-height: 19px; margin-bottom: 15px; margin-top: 15px; overflow: auto; padding: 6px 10px; word-wrap: normal;"><code style="background-color: transparent; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: none; box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Courier, monospace; font-size: 12px; margin: 0px; padding: 0px; word-wrap: normal;">server = MailServer(server_name='smtp.gmail.com', username='<username>', password='<password>', port=0, require_starttls=True)
</password></username></code></pre>
<h2 style="border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #333333; cursor: text; font-family: Helvetica, arial, freesans, clean, sans-serif; font-size: 2em; line-height: 1.7; margin: 1em 0px 15px; padding: 0px; position: relative;">
<a class="anchor" href="https://github.com/ludmal/pylib#step-4" name="step-4" style="bottom: 0px; box-sizing: border-box; color: #4183c4; cursor: pointer; display: block; left: 0px; margin-left: -30px; padding-left: 30px; padding-right: 6px; position: absolute; text-decoration: none; top: 0px;"></a>Step 4:</h2>
<div style="box-sizing: border-box; color: #333333; font-family: Helvetica, arial, freesans, clean, sans-serif; font-size: 15px; line-height: 25.5px; margin-bottom: 15px; margin-top: 15px;">
Create a mail message and send the email</div>
<pre style="background-color: #f8f8f8; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221); box-sizing: border-box; color: #333333; font-family: Consolas, 'Liberation Mono', Courier, monospace; font-size: 13px; line-height: 19px; margin-bottom: 15px; margin-top: 15px; overflow: auto; padding: 6px 10px; word-wrap: normal;"><code style="background-color: transparent; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: none; box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Courier, monospace; font-size: 12px; margin: 0px; padding: 0px; word-wrap: normal;">msg = MailMessage(from_email='ludmal@gmail.com', to_emails=['ludmal@gmail.com'], subject='Welcome')
send(mail_msg=msg, mail_server=server, template=temp)
</code></pre>
<div style="box-sizing: border-box; color: #333333; font-family: Helvetica, arial, freesans, clean, sans-serif; font-size: 15px; line-height: 25.5px; margin-top: 15px;">
Follow me on Twitter @ludmal</div>
Ludmal de silvahttp://www.blogger.com/profile/08871386763862827832noreply@blogger.com0tag:blogger.com,1999:blog-11001074.post-85563018148906423552014-02-07T02:30:00.001+05:302014-02-07T02:35:42.212+05:30Python File ArchiverI always wanted to quickly cleanup my harddrive without manually searching files and moving them. So here is the solution, a simple File Arhicver python script which I wrote to clean up my hard drive. It will search for files older than a given time period & size (parameterized) and then move to a Arhicve folder. I'll try to improve the code when I get some free time and here is the script file, download and feel free to use it.<br />
<br />
<a href="https://github.com/ludmal/pylib/blob/master/file_archiver">https://github.com/ludmal/pylib/blob/master/file_archiver</a>Ludmal de silvahttp://www.blogger.com/profile/08871386763862827832noreply@blogger.com0tag:blogger.com,1999:blog-11001074.post-85391502243120236602013-11-27T09:14:00.000+05:302013-11-27T10:55:02.754+05:30tf-idf, Term Frequency–Inverse Document Frequency<i>tf-idf</i> is stands for Term Frequency - Inverse document frequency and it is one of the effective algorithms to extract the keywords from a given document. It is often used in <a href="http://en.wikipedia.org/wiki/Natural_language_processing">NLP </a>and <a href="http://en.wikipedia.org/wiki/Information_retrieval">IR</a>. The extraction is performed in a statistical measure by calculating the weight of a word in a document list or a corpus. Many search engines using the benefits of <i>tf-idf</i> to extract keywords, frequently with combinations of other algorithms. Word's weight or importance is measured by the word frequency in a document and offset by the same word's frequency in the given corpus.<br />
<br />
<i><b>tf-idf = term frequency x inverse document frequency</b></i><br />
<br />
For example, if the word 'peace' appears 6 times in a document with 100 words the <i>tf</i> is 6/100 = 0.06. And if the corpus or document list contains 1000 documents and if 'peace' appears in 200 documents in the corpus then the <i>idf</i> is 1000/200 = 5. Hence the <i>tf-idf </i>for the word is 0.06 x 5 = 0.3. The weight or <i>tf-idf</i> is directly related to the importance word, i.e. if the tf-idf is higher then the importance of the word is high.<br />
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh67UmrKjfbEPMN8fm8S7i3vBazCC0k2CzXHHKzdsWBQAYqQpWFP5r1NDes8lndRNOq4l6T11h2hp97IMkW8tN9OVwBNExYXDeH75Rs98ZjIS1tpQne6hwPK1VkwwHFHEaz-kSvQA/s1600/tf-idf.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="186" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh67UmrKjfbEPMN8fm8S7i3vBazCC0k2CzXHHKzdsWBQAYqQpWFP5r1NDes8lndRNOq4l6T11h2hp97IMkW8tN9OVwBNExYXDeH75Rs98ZjIS1tpQne6hwPK1VkwwHFHEaz-kSvQA/s400/tf-idf.png" width="400" /></a></div>
<br />
<br />
I've written a python module to extract the keywords from a given corpus. This is useful if you want to extract the keywords from a given website links and categorized them according to the keywords. You can use the code freely by downloading from the following Github location.<br />
<br />
<a href="https://github.com/ludmal/pylib">https://github.com/ludmal/pylib</a><br />
<br />
Complete sample of the usage can be found here: <a href="https://github.com/ludmal/pylib/blob/master/sample.py">https://github.com/ludmal/pylib/blob/master/sample.py</a><br />
<br />
<br />
<br />Ludmal de silvahttp://www.blogger.com/profile/08871386763862827832noreply@blogger.com2tag:blogger.com,1999:blog-11001074.post-76222058436047250742013-07-23T03:52:00.002+05:302013-07-23T03:52:40.930+05:30GIT Tortoise I've recently moved all my projects to GIThub.com This is mainly due to the fact the popularity gain by GITHub compare to Google code. I was a big fan of Tortoise SVN and luckily it is now available for GIT as well. You can download it from the following location:<br />
<a href="https://code.google.com/p/tortoisegit/" style="background-color: white; color: #1155cc; font-family: arial, sans-serif; font-size: 13px;" target="_blank">https://code.google.com/p/<wbr></wbr>tortoisegit/</a><br />
<br />
Also if anyone wants to use GIT with Visual Studio, here is how;<br />
<br />
1. Install GIT for windows<br />
<a href="https://code.google.com/p/msysgit/downloads/list?q=full+installer+official+git" style="background-color: white; color: #1155cc; font-family: arial, sans-serif; font-size: 13px;" target="_blank">https://code.google.com/p/<wbr></wbr>msysgit/downloads/list?q=full+<wbr></wbr>installer+official+git</a><br />
<br />
2. Install GIT source control provider<br />
<a href="http://gitscc.codeplex.com/" style="background-color: white; color: #1155cc; font-family: arial, sans-serif; font-size: 13px;" target="_blank">http://gitscc.codeplex.com/</a><br />
<br />
and your done! Don't forget to select GIT from the VS Source control settings. <br />
<br />
<br />
<br />
<br />Ludmal de silvahttp://www.blogger.com/profile/08871386763862827832noreply@blogger.com0tag:blogger.com,1999:blog-11001074.post-86355606311081344422011-09-08T20:23:00.002+05:302011-09-08T20:29:42.709+05:30Google Buzz<br />
<div style="background-color: transparent;">
<span id="internal-source-marker_0.10284444410353899" style="background-color: transparent; font-family: Arial; font-size: 11pt; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">After months of inactivity, I finally decided to disable buzz. Sorry but I’m no longer on Buzz. </span><br />
<span style="background-color: transparent; font-family: Arial; font-size: 11pt; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"></span><br />
<span style="background-color: transparent; font-family: Arial; font-size: 11pt; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Reducing number of news streams helps me to focus on things which are relevant and important. By disabling buzz I reduced my social focus to Twitter, Google+, LinkedIn and Facebook. I also reduced people I follow in Twitter. Last few months I was overloaded with few things and could not read as much I used to. </span><br />
<span style="background-color: transparent; font-family: Arial; font-size: 11pt; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"></span><br />
<span style="background-color: transparent; font-family: Arial; font-size: 11pt; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">I’m not a big fan of Facebook, so I will be mainly using my twitter account for updates. And those updates will be automatically added to my Google+, LinkedIn and Facebook accounts. So if you’re interested, Twitter will be my main source for updates. Follow me @ludmal</span></div>
Ludmal de silvahttp://www.blogger.com/profile/08871386763862827832noreply@blogger.com0tag:blogger.com,1999:blog-11001074.post-91405685835487654172011-08-26T02:33:00.000+05:302011-08-26T02:33:40.091+05:30Is Silverlight really dead?<br />
<div style="background-color: transparent;"><span id="internal-source-marker_0.6309556933119893" style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">When Silverlight initially released I was skeptical about it. It was meant to replace Adobe Flash back then. There were quite a few arguments I had with my colleagues about Silverlight and its future. But today, after 4 years of Silverlight’s initial release how many web sites do we see in Silverlight?</span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"></span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">The future of the web depends on HTML 5 and Javascript. Open standards and 3rd party libraries are the main reasons for this adaption. I clearly don’t see a potential for another technology. However I’m really impressed with Windows 7 Mobile and MVC from Microsoft. I see a potential in terms of web and mobile. I also heard that Microsoft is working on a new UI application model --“Jupiter” which is simlier to Windows 7 Mobile.</span></div>Ludmal de silvahttp://www.blogger.com/profile/08871386763862827832noreply@blogger.com0tag:blogger.com,1999:blog-11001074.post-74122451773102659702011-08-05T08:04:00.000+05:302011-08-05T08:04:13.991+05:30Visual Studio LightSwitchNew product in Visual Studio family to create rapid data-centric applications for both desktop and cloud. <br />
<br />
Resources:<br />
<a href="http://msdn.microsoft.com/en-us/lightswitch">http://msdn.microsoft.com/en-us/lightswitch</a><br />
<a href="http://msdn.microsoft.com/en-us/magazine/hh335065.aspx">http://msdn.microsoft.com/en-us/magazine/hh335065.aspx</a><br />
<a href="http://msdn.microsoft.com/en-us/magazine/hh335061.aspx">http://msdn.microsoft.com/en-us/magazine/hh335061.aspx</a><br />
<br />
Hope this helps!<br />
<br />
Follow me at twitter @ludmal for quick updatesLudmal de silvahttp://www.blogger.com/profile/08871386763862827832noreply@blogger.com0tag:blogger.com,1999:blog-11001074.post-81717355964924273912011-07-28T08:18:00.000+05:302011-07-28T08:18:26.541+05:30Moving your business into the CloudCloud computing is ideal for medium and small scale business. Most of the large scale businesses however, are reluctant to move into the cloud. Mostly because they have already invested on their IT infrastructure or fear of exposing their corporate data. Entrepreneurs are finding cloud computing is more beneficial to their businesses. Mainly because to start their businesses with minimum cost on IT infrastructure. <br />
<br />
In Cloud Computing--computing power is used like water or electricity, pay only for usage. This has gained significant benefits for businesses. Scalability is vital for any business and cloud computing allows them to grow computing power with minimum cost. Business can run the IT infrastructure without support of internal tech staff hence save money on payroll. <br />
<br />
Drawbacks of using cloud computing are very low compare to its benefits. However, service outages are a major drawback on cloud computing. But those outages are significantly low with major service providers like <a href="http://www.google.com/">Google</a>, <a href="http://www.salesforce.com/">Salesforce </a>and <a href="http://www.amazon.com/">Amazon</a>. <br />
<br />
It is vital for businesses to keep their operation costs to minimum. By moving to cloud computing businesses can gain significant benefits like low operation cost, scalability and availability. For example <a href="http://www.google.com/apps/intl/en/business/index.html">Google Apps for Business</a> is ideal cloud solution for an small and medium scale business.Ludmal de silvahttp://www.blogger.com/profile/08871386763862827832noreply@blogger.com0tag:blogger.com,1999:blog-11001074.post-56610510842003410912011-07-20T19:57:00.001+05:302011-07-20T19:58:32.422+05:30Most of my personal projects will be retired soonFinally, I decided to retire most of my personal projects. It was too long ago I developed those software projects and it is time now to put them aside and move on with new ideas. Some of the projects however never actually completed. Following are the projects which are going to retire end of this month and domains are already on sale. Please let me know if anybody interested in purchase.<br />
<br />
<a href="http://boilcode.com/">boilcode.com</a> / <a href="http://codeswave.com/">codeswave.com</a> – Online code snippet management library for developers.<br />
<br />
<a href="http://facebook-stats.com/">facebook-stats.com</a> – Facebook statistics such as frequency of updates, user base, top users etc.<br />
<br />
<a href="http://twitter-stats.com/">twitter-stats.com</a> – Twitter statistics such as frequency of updates, user base, top users etc.<br />
<br />
<a href="http://groupon.lk/">groupon.lk</a> – <a href="http://groupon.com/">Groupon.com</a> like site for Sri Lanka, i.e. to get best deals in town.<br />
<br />
<a href="http://newsflippers.com/">newsflippers.com</a> – This project is actually similar to <a href="http://fastflip.googlelabs.com/">http://fastflip.googlelabs.com/</a>. Currently the concept still remains but with a different presentation in my new project <a href="http://www.channells.com/">www.channells.com</a><br />
<br />
<a href="http://prodznet.com/">prodznet.com</a> – An effort to categories the cheap and best products by price and user reviews on the internet.<br />
<br />
<a href="http://qnote.us/">qnote.us</a> – Online notepad with offline writing ability.<br />
<br />
<a href="http://webexten.com/">webexten.com</a> – Replacement for extensible-web.com but decided to keep the name as it is—<a href="http://extensible-web.com/">extensible-web.com</a><br />
<br />
However my <a href="http://code.google.com/p/extensible-web-toolkit/">XWT Framework</a> project , Extensible-web and <a href="http://channells.com/">Channells.com</a> site still in active development, also some of my new ideas yet to be released.<br />
<br />
All the above domains are for sale, but if anybody requires source code please email me and I would be more than happy to send them.Ludmal de silvahttp://www.blogger.com/profile/08871386763862827832noreply@blogger.com0