Posts

AWS Cognito fine grained Authorization

https://aws.amazon.com/blogs/security/use-amazon-cognito-to-add-claims-to-an-identity-token-for-fine-grained-authorization/

PST to UTC Date

I had a requirement to return customer usage between two days, but database saved all usage records with end of the day PST time in UTC dates. Since API accepts date only, database has records with UTC, API need to convert date into end of the day and convert same into UTC to retrive right DB records. Eg - Given date - 4/30/2022 Database has record saved as- 5/1/2022 6:59:59 AM +00:00 (4/30/2022 23:59:59 PST) Since DB saved usage dated 4/30 as 5/1 in UTC, API would miss last record if no date conversion implemented. The below code converts given date only string into end of the day for the intended timezone with UTC format to compare records and include last record with given date ranges. //Get Pacific Time from the machine. var pacificTimeZone = "America/Los_Angeles"; //for linux env if (Environment.OSVersion.VersionString.Contains("Windows")) pacificTimeZone = "Pacific Standard Time"; var pstZone = TimeZoneInfo.FindSystemTimeZoneById(pacific...

BFS - Breadth First Search

The below is sample code to iterate through graph nodes using breadth first search - //build graph nodes var tree = new Dictionary<int, List<int>>(); tree.Add(1, new List<int> { 2, 3, 4 }); tree.Add(2, new List<int> { 5 }); tree.Add(3, new List<int> { 6, 7}); tree.Add(4, new List<int> { 8 }); tree.Add(5, new List<int> { 9 }); tree.Add(6, new List<int> { 10 }); //get root element of graph Queue q = new Queue(); q.Enqueue(tree.ElementAt(0).Key); HashSet<int> visitiedNode = new HashSet<int>(); //iterate queue to visit nodes while(q.Count > 0) { //dequeue 1st element var item = Convert.ToInt32(q.Dequeue()); //check if element already visited if (visitiedNode.Contains(item)) continue; //add element to visited list visitiedNode.Add(item); Console.WriteLine(item); //get next adjecent nodes tree.TryGetValue(item, out List<int> adjcentNodes); //enqueue new nodes to the queue if (adjcentNodes != null)...

Generate Google, Outlook Calendar events links

We had a requirement to save calendar events with out downloading of ICS file and save events into the customer's email client calendar directly. This requirement seems hard, but the email clients had calendar API and can have links targeted to call the right API to make this happen. The below APP provides links and can be included in an email to the customer to save events into the calendar.   https://www.labnol.org/apps/calendar.html

Initialize postman variables using Pre-request script

Image
 Often times we need to set postman variables before call API and API requests may use other API responses. Postman offers a pre-request script section that can be used to initialize postman variables. In the below request, I require to send a mfa-token as part of the header to consume API, but mfa-token is not a static one to hardcode in postman global variables. I had get this for each request to get updated mfa-token from other API. This can be achieved through pre-request script to set dynamic values. Set mfa-token variable through pre-request script by consuming another API response -  Text out of Image - const   reqObject   =  {   url:  'http://internalUrl/authentication/mfa-token' ,   method:  'GET' ,   header: { 'channel' : 'customer' } }; pm .sendRequest( reqObject , ( err ,  res )  =>  {      token   =   res .json()      console . log (...

In-memory & Distributed (Redis) Caching in ASP.NET Core

https://medium.com/net-core/in-memory-distributed-redis-caching-in-asp-net-core-62fb33925818

Call API gateway endpoint using jQuery (Ajax)

The below shows one of the samples get calls to retrieve data from AWS API gateway - Click!

Kubernetes vs Docker vs Fargate

https://containerjournal.com/topics/container-ecosystems/kubernetes-vs-docker-a-primer/ https://www.dragonspears.com/blog/aws-container-orchestration-101-ecs-vs-fargate-vs-eks
TFS Build Errors - If you happen  run  into below errors -  The job has been abandoned because agent Agent1-XXXX did not renew the lock. Ensure agent is running, not sleeping, and has not lost communication with the service. -Or- Microsoft.TeamFoundation.DistributedTask.WebApi.TaskAgentSessionConflictException: The task agent Agent1-XXXX already has an active session for owner XXXX. Resolution - - Make sure VSO agent running on TFS Build server - Restart Source control servers services (your code repository aka TFS Server)        -- Visual Studio Team Foundation Background Job Agent - TFSJobAgent       -- Visual Studio Team Foundation Build Service Host 2015 - TFSBuildServiceHost.2013 Hope this resolves your issue too.

Building Simple Website - Angular 2

http://onehungrymind.com/build-a-simple-website-with-angular-2/

Render rows as columns AngularJs

The best & minimal data chopping approach to render rows as columns - http://code.notsoclever.cc/column-and-row-based-tables-in-angularjs/ Working JsFiddle - https://jsfiddle.net/vpavulu/rxrox8nt/ using ng-repeat/ng-switch - https://jsfiddle.net/vpavulu/s358y77t/

Create common controls as Angular Directive (Dropdown / select list)

You can create state/country dropdown list as common controls to make use of them as global controls instead of re-creating for each controller. http://plnkr.co/edit/V5ub3CBRMlQcjGMs2Px2?p=preview Ref:  http://stackoverflow.com/questions/18459681/how-add-options-to-a-select-with-an-angularjs-directive For Two-way binding working from/to directive, need to use controller in directive instead of link function. Fiddle -  https://jsfiddle.net/vpavulu/h2ng6wdw Another way to make 2-way binding to work with Button & Unordered list as dropdown list - http://plnkr.co/edit/mIKHqMixUALMR8DA18Vh

Static content, java script, css, png, image files not rendering

http://stackoverflow.com/questions/10512053/css-images-js-not-loading-in-iis

Static Methods Unit test by MOQ

Today I got pulled into one of the existing project and it had data layer with all static methods and its tightly coupled with service layer. I had to write unit test by using Moq framework for one of service method call and it had 5 different db layer method dependencies. Unfortunately Moq doesn't support to mock static methods directly. Moq is meant to mock Interfaces not concrete methods. Fortunately explicit interface implementation helped to achieve to write unit tests. I have followed below article and helped to write some unit tests for service layer. Ref -  https://guptaashish.com/2012/10/17/unit-testing-a-static-method-which-calls-another-static-method/#comments

How to write Unit testable code?

The below article may be older, but it gives how to start your classes to make more unit testable. http://www.asp.net/mvc/overview/older-versions-1/contact-manager/iteration-4-make-the- application-loosely-coupled-cs http://web.archive.org/web/20150318150744/http://www.remondo.net/repository-pattern-example-csharp/

React JS tutorial Videos

https://www.youtube.com/playlist?list=PLoYCgNOIyGABj2GQSlDRjgvXtqfDxKm5b

Good article of IoC & Dependency Injection

http://www.codeproject.com/Articles/615139/An-Absolute-Beginners-Tutorial-on-Dependency-Inver

Azure Service Error - The HTTP request was forbidden with client authentication scheme Anonymous/ System.Web.Services.Protocols.SoapException: SOAP Server Application Faulted

When I was working on WCF services consumption through one of azure web/worker role I was getting the below service errors - 1) System.InvalidOperationException: Operation failed with internal server errors:{"message":"The HTTP request was forbidden with client authentication scheme 'Anonymous'" 2) System.Web.Services.Protocols.SoapException: SOAP Server Application Faulted In both scenarios, I had service authentication through Certs auth and I have certs installed on azure management portal. After bit investigation I have realized the certs are not uploaded by their .pfx files, instead .cer certs uploaded into portal. When you deploy your azure web/worker roles, it won't complain about missing cert since cert store has .cer file. But when you role calls WCF service, service expects to send .pfx file instead of .cer and you see above service errors. To resolve the issue, you need to remove cert from management portal and upload cert with .pfx ...

Good Article on basic understanding of KnockOut Js

http://www.dotnet-tricks.com/Tutorial/knockout/bSKG240313-Understanding-Knockout-Binding-Context-Variable.html Good explanation of Cart Editor example - http://blogs.msdn.com/b/thebeebs/archive/2011/07/11/knocoutjs.aspx

Resource ID : 1. The request limit for the database is 180 and has been reached.

Image
How to find root cause for SQL Azure DB error - " Resource ID : 1. The request limit for the database is 180 and has been reached." I have ran the following two queries to find long running queries that causing connection limit issue. When you run below queries the result set 1 shows all current running query on DB with active session ids. If result set1 has non-zero values in “blocking_session_id” column, you can find same session id in 2 nd result set and see the query text. Based on query text, you can guess which job is running this query & kill/suspend the job/query to release the server resources. select r . session_id , r . blocking_session_id , r . wait_type , r . wait_time , r . wait_resource , r . total_elapsed_time , r . cpu_time , r . reads , r . writes , s . nt_user_name , s . program_name , s . total_elapsed_time from sys . dm_exec_requests r join sys . dm_exec_sessions s on s . session_id = r . session_id SELECT  ...