Skip to main content

Posts

Mongo DB Conditional Serialization

Mongo DB - Conditional Serialization Sometimes, the documents retrieved from the database should be serialized differently for different conditions. We can make use of the below technique to do that, public class Company {     public ObjectId Id { get; set; }     [BsonDateTimeOptions(DateOnly = true)]     public DateTime JoiningDate { get; set; }     public bool ShouldSerializeJoiningDate() {         return JoiningDate > new DateTime(1900, 1, 1);     } } For more information on conditional serialization, refer the Mongo DB documentation below https://mongodb.github.io/mongo-csharp-driver/1.11/serialization/

Git Shortcuts and Bash Aliases

Git Shortcuts that come in handy during development to make things easier.  Edit  /.gitconfig and add a section like below: [alias]     co=checkout     cob=checkout -b     br=branch     brd=branch -d     brD=branch -D     st=status     cm=commit -m     unstage=reset --soft HEAD^     ls = log --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%Cvlue\\ [%cn]" --decorate     ll = log --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%Cvlue\\ [%cn]" --decorate -- numstat     la="!git config -l | grep alias | cut -c 7-" Adding Bash aliases -  Edit /.bashrc as below, echo ".bashrc running..." alias al='source C:\\Users\\{{username}}\\.bashrc' alias cdgit = 'cd C:\\Git' {{similarly you can all shortcutes to your workspaces for easy navigation}} alias gcd='git checkout develop ; git status' alias gs='git status' alias g='git' alias gp='git pull' alias h='history' alias l...

Angular vs React

Angular vs React Angular and React are the most used modern JavaScript frameworks out there currently. Here's a look at their features and comparing the differences                                          1. Performance Angular - Competitive, optimized with change detection Angular performs worse, especially in the case of complex and dynamic web pages. The performance of Angular apps is negatively affected by the bidirectional data-binding. Each binding is assigned a watcher to track changes and each loop continues until all the watchers and associated values are checked. Because of this, the more bindings you have, the more watchers are created, and the more cumbersome the process becomes. However, the most recent update of Angular has greatly improved its performance, and it does not lose to React anymore. Moreover, the size of an Angular application is slightly smaller than the...

Angular Features

Features of Angular Angular is a powerful modern Javascript framework and it comes with a lot of inbuilt features to develop secure web and mobile applications. Let's look at the features of angular that makes it stand out. Cross-platform  - Web, Native and Desktop Applications Productivity  - IDE's, Templates, Angular CLI Forms  - Template-driven and Reactive forms for building UI pages Inbuilt Angular Router Module  - HttpClientModule Inbuilt Dependency Injection RxJS support for asynchronous calls (Observables) Tree shaking : Build Optimization step which tries to ensure any unused code does not get used on the final bundle. Smaller bundles and faster startup time. @Injectable { providedIn: } Differential Loading  - Map files for Old and Modern browsers Ivy  - New Rendering Engine ngRx  for State Management Internalization and Localization  using i18n inbuilt tool or Ngx-translate third-party tool. (Internalization - Process of desi...

Differential Loading in Angular

Differential Loading in Angular Angular is a complete javascript framework with many inbuilt features like routing, dependency injection, form validation but the downside is the application bundle size. In order to overcome this issue, Angular 8 introduces the concept of differential loading. Until angular 7 versions, when we do an ng build command, the typescript files are converted into js files that can support both modern and old browsers. Since the build bundle should contain js files for new and old browsers, this results in huge bundle sizes. With angular 8 Differential loading, when we do an ng build two different bundles are created one for modern browsers (supports recent syntax changes in JavaScript such as arrow functions in ES2015 or async functions in ES2017) and other for older browsers (es5 ex. IE) When the app is deployed, both the bundles get deployed and based on the browser the clients opens the app from, the specific bundle gets loaded by the browser Basic...

Angular - nvm (Node Version Manager)

nvm - Node Version Manager Node Version Manager helps you to install different Node versions and easily switch between different versions.  How to Install Node Version Manager? Install Node Version Manager from this link -  https://github.com/coreybutler/nvm-windows/releases/tag/1.1.7  (nvm-setup.zip) Open Command Prompt in Admin mode and perform the below steps,  Common Issues: Error Message:  This usually happens because your environment has changed since running 'npm install'. Run 'npm rebuild node-sass' to download the binding for your current environment. Solution: node-sass install steps -    1. npm -g uninstall node-sass    2. npm -g i node-sass    3. npm rebuild node-sass (in the app location)

Javascript vs TypeScript

JavaScript vs TypeScript Javascript   - Client-side programming language to create interactive web pages.  But it has a few disadvantages. As code grows, it becomes difficult to maintain and reuse code It doesn't support Object Orientation, strong type checking and compile-time error checks Can be used for small applications with the minimal code base, but not effective when application code grows. Typescript  - A modern age Javascript development language which can run on node.js or any browser which supports ECMAScript3 or above.  Features: Superset of Javascript Optionally typed scripting language . Typescript variable with no type will be inferred by Transcript Language Service(TLS) based on its value. Supports Object-oriented programming techniques like classes, interface, inheritance, subclasses etc.. Rich IDE available with autocomplete and code navigation features Compilation - Typescript transpiler provides error checking feature. It compiles the code, ge...

PCF - Blue Green Deployment

BLUE GREEN DEPLOYMENT PCF Blue-Green deployment is a technique to reduce the downtime of applications during deployment and also reduce the risk ie. if something unexpected happens we have an option to roll back to the previous version by switching back There are two identical production environments running called Blue(live) and Green(idle) and at any time only one of the environments is live.  When a new version of the app/software needs to be deployed, final stage of testing happens in the green environment and once it is fully tested, we can switch the router so all incoming requests now go to Green instead of blue. Green is now live and Blue is idle. For more details, please refer pivotal resource link -  https://docs.pivotal.io/pivotalcf/2-5/devguide/deploy-apps/blue-green.html

Angular - NGINX - PCF Integration

NGINX - PCF Nginx is a web server that can be used as a reverse proxy, load balancer, HTTP Cache etc.  In order to deploy apps with NGINX configuration, you need to have an Nginx.conf file in your app so that PCF uses it when deploying. Uses -     1. To get the PCF Environment variable for respective environments to manage them in Angular apps    2. To set the page refresh order before throwing 404 error An example nginx.conf file is shown below. You can configure the way you want based on your requirements and need.

Angular - Useful Extensions

There are a lot of useful extensions that can be used to improve productivity while developing Angular applications. Some useful extensions listed below,

Working with MongoDB in .Net Core (Part 5) - Mongo Queries

Mongo Aggregation pipeline Queries //Pipeline Query use Collection; db.getCollection(collectionName).aggregate( [ { " $match " : { " {field1} " : { " $eq " : " string " }, " {field2} " : { " $eq " : " string " } }, }, { " $group " : { " _id " : " $field " , " Count " : { " $sum " : 1.0 }, " Results " : { " $addToSet " : " $field " } } }, { " $sort " : { " Count " : -1.0 } }, { " $project " : { " count " : 1.0, " _id " : 1.0, " AccountId " : 1.0 } } ], ...

SwashBuckle - Swagger Open API Documentation

Swashbuckle Open API Swagger is Open API documentation used to understand the various methods and the request/responses of various endpoints. It generates the Web API SDK for clients. Swashbuckle .AspNetCore is an open-source project for generating Swagger documents for ASP.Net Core Web APIs.  Another open-source project is  NSwag  for generating swagger documents. Enable Swagger in .NET Core Apps -  Note - Install the  Swashbuckle.AspNetCore NuGet package  into your solution.Don't install Swashbuckle.AspNetCore.Swagger package) Add the below to the Configure() Method -  app.UseSwagger(); app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "AppName"); }); using Swashbuckle.AspNetCore.Examples ; using Swashbuckle.AspNetCore.Swagger ; public void ConfigureServices (IServiceCollection services) { // Register the Swagger generator, defining 1 or more Swagger documents services.AddSwaggerGen(c => { ...

Working with MongoDB in .Net Core (Part 3) - Definitions and Builders

                 Mongo Queries - C# Driver Writing Complex Mongo Queries using Aggregation - Builders and BsonDocuments Builders -  1 2 3 4 5 6 7 8 9 10 11 12 //Filter Definition Builder var builder = Builders<T>.Filter; var filter = builder.Ne(_=>_.{field}, true ); filter = filter & builder.Eq(_=>_.{field}, value ); filter = filter & builder.Gte(_=>_.{field}, value ); filter = filter & builder.Lte(_=>_.{field}, value ); filter = filter & builder.In(_=>_.{field}, value ); filter = filter & builder.In(_=>_.{field}, new List< string > { value1, value2}); filter = filter & builder.AnyEq(_=>_.{field}, value ); filter = filter & builder.Or(_=>_.{field}, value ); filter = filter & builder.And(_=>_.{field}, value ); filter = filter & builder.ElemMatch(_=>_.{field}, t => t.Id == Id, t.Key == Key); 1 2 3 4 5 6 7 8 9 //Sort Def...