Monday, 26 August 2024

TSPSC G-2

https://www.youtube.com/watch?v=Q6CKkQ8xgbc

 









Dotnet core

 Pagination: Use `Skip` and `Take` for efficient pagination.

var pagedOrders = await _context.Orders
.Skip((pageNumber - 1) * pageSize)
.Take(pageSize)
.ToListAsync();

Angular issues

 Developing high-performance Angular apps requires avoiding common pitfalls. Here are key practices that harm performance and how to fix them.

Angular bad performance

Developing high-performance applications with Angular requires attention to details that are often overlooked. Here are some common practices that can kill the performance of your Angular application, along with examples of bad code and their corrections.

1. Excessive Change Detection

Bad Code:

Change detection is triggered too frequently, affecting performance.

@Component({
selector: 'app-my-component',
templateUrl: './my-component.component.html',
})
export class MyComponent {
@Input() data: any;
}

Correction:

Use the OnPush strategy in components where possible. This makes change detection occur only when the component's input changes.

@Component({
selector: 'app-my-component',
templateUrl: './my-component.component.html',
changeDetection: ChangeDetectionStrategy.OnPush
})
export class MyComponent {
@Input() data: any;
}

2. Inefficient DOM Manipulation

Bad Code:

Direct DOM manipulations can be inefficient and hard to manage.

ngAfterViewInit() {
document.getElementById('elementId').style.color = 'blue';
}

Correction:

Use Angular’s Renderer2 to manipulate the DOM more efficiently.

import { Renderer2 } from '@angular/core';

constructor(private renderer: Renderer2) {}

ngAfterViewInit() {
const element = this.renderer.selectRootElement('#elementId');
this.renderer.setStyle(element, 'color', 'blue');
}

3. Overuse of Pipes

Bad Code:

Pipes that perform heavy operations can be re-executed frequently, hurting performance.

@Pipe({
name: 'heavyPipe',
pure: false
})
export class HeavyPipe implements PipeTransform {
transform(value: any): any {
// Heavy transformation logic
}
}

Correction:

Use pure pipes (pure: true) for lightweight operations or avoid pipes for heavy operations.

@Pipe({
name: 'heavyPipe',
pure: true
})
export class HeavyPipe implements PipeTransform {
transform(value: any): any {
// Light transformation logic
}
}

4. Excessive Initial Load

Bad Code:

Loading all modules and components at initialization can delay loading time.

@NgModule({
declarations: [AppComponent, FeatureComponent],
imports: [BrowserModule, FeatureModule],
bootstrap: [AppComponent]
})
export class AppModule {}

Correction:

Use lazy loading for modules that are not immediately needed.

const routes: Routes = [
{ path: 'feature', loadChildren: () => import('./feature/feature.module').then(m => m.FeatureModule) }
];

5. Unmanaged Subscriptions

Bad Code:

Not cancelling subscriptions can lead to memory leaks.

ngOnInit() {
this.myService.myObservable.subscribe(value => {
// Do something with value
});
}

Correction:

Use the async pipe or manage subscriptions with takeUntil or Subscription.

import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';

@Component({
selector: 'app-my-component',
templateUrl: './my-component.component.html',
styleUrls: ['./my-component.component.css']
})
export class MyComponent implements OnDestroy {
private destroy$ = new Subject<void>();

constructor(private myService: MyService) {
this.myService.getData()
.pipe(takeUntil(this.destroy$))
.subscribe(data => {
// Handle the data
});
}

ngOnDestroy() {
this.destroy$.next();
this.destroy$.complete();
}
}

For Angular 16+ use takeUntilDestroyed.

import { Component, OnDestroy } from '@angular/core';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';

@Component({
selector: 'app-my-component',
templateUrl: './my-component.component.html',
styleUrls: ['./my-component.component.css']
})
export class MyComponent implements OnInit, OnDestroy {

constructor(private myService: MyService) {
}

ngOnInit(): void {
this.myService.getData()
.pipe(takeUntilDestroyed(this))
.subscribe(data => {
// Handle the data
});
}

ngOnDestroy() {
}
}

6. Excessive Dependencies in Providers

Bad Code:

Registering too many providers in the root module increases the bundle size.

@NgModule({
providers: [MyService]
})
export class AppModule {}

Correction:

Register providers only where they are necessary.

@NgModule({
providers: [MyService] // Register only where necessary
})
export class FeatureModule {}

7. Lack of AOT Compilation

Bad Code:

Using JIT (Just-in-Time) compilation can be less efficient.

// No specific configuration for AOT

Correction:

Configure the application to use AOT (Ahead-of-Time) compilation.

{
"projects": {
"my-app": {
"architect": {
"build": {
"options": {
"aot": true
}
}
}
}
}
}

8. Lack of Bundle Optimization

Bad Code:

Unoptimized bundles increase loading time.

// Default Angular CLI configuration

Correction:

Use tools like Webpack and Angular CLI build configurations to optimize bundles.

{
"projects": {
"my-app": {
"architect": {
"build": {
"configurations": {
"production": {
"optimization": true,
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"aot": true,
"vendorChunk": false,
"buildOptimizer": true
}
}
}
}
}
}
}

Conclusion

By following these practices and corrections, you can significantly improve the performance of your Angular application, making it more efficient and responsive.

Thursday, 22 August 2024

Dtabase design

 OLX, like many large-scale online platforms, employs a variety of data structures and technologies to manage its data effectively. While specific details about OLX's internal architecture are not publicly disclosed, we can infer some common data structures and technologies used in similar applications:

  1. Relational Databases: OLX likely uses relational databases (such as MySQL or PostgreSQL) to store structured data like user profiles, listings, and transactions. These databases use tables to represent data and relationships.
  2. NoSQL Databases: For handling unstructured or semi-structured data, OLX may utilize NoSQL databases (like MongoDB or Cassandra) to store user-generated content, such as images or descriptions of listings.
  3. Search Indexes: To facilitate fast search capabilities, OLX probably uses search engines like Elasticsearch or Apache Solr, which employ inverted indexes to allow quick retrieval of data based on search queries.
  4. Caching: To improve performance, OLX likely implements caching mechanisms (such as Redis or Memcached) to store frequently accessed data in memory, reducing the load on databases.
  5. Data Structures for Recommendations: For features like personalized recommendations, OLX might use graph structures or tree-based algorithms to analyze user behavior and interactions.
  6. Message Queues: For handling asynchronous tasks (like notifications or processing transactions), OLX may use message queue systems (like RabbitMQ or Apache Kafka).

These data structures and technologies help OLX manage large volumes of data efficiently, ensuring that users can quickly access and interact with the platform.

Wednesday, 21 August 2024

Coding challenges

 https://www.codewars.com/kata/search/csharp


https://edabit.com/challenges/csharp


https://www.w3resource.com/csharp-exercises/basic-algo/index.php

https://www.roundthecode.com/dotnet-coding-challenges

https://www.fullstack.cafe/interview-questions/net-core

https://coddy.tech/courses/coding_problems


File upload to blob using C#

 public async Task<bool> CapitalItemFileUploadtoCloud(IFormFileCollection _lstFiles, string _strIncidentId)

        {
            var blobServiceClient = new BlobServiceClient(strAzureConnectionString);
            try
            {
                bool _blnResult = false;
                var blobContainerClient = blobServiceClient.GetBlobContainerClient(strEnvironment); // Container reference

 

                // Create the container if it doesn't exist
                await blobContainerClient.CreateIfNotExistsAsync();

 

                foreach (var file in _lstFiles)
                {
                    if (file.Length > 0)
                    {
                        // Create a reference to the blob within the container
                        var blobClient = blobContainerClient.GetBlobClient($"{_strIncidentId}/{file.FileName}");

 

                        // Upload the file to the blob
                        using (var stream = new MemoryStream())
                        {
                            try
                            {
                                stream.Seek(0, SeekOrigin.Begin);
                                await blobClient.UploadAsync(stream, new BlobHttpHeaders { ContentType = file.ContentType });
                                _blnResult = true; // Set result to true if upload succeeds
                            }
                            catch (Exception uploadEx)
                            {
                                // Handle exceptions during upload
                                Console.WriteLine($"Upload failed: {uploadEx.Message}");
                                _blnResult = false;
                            }
                        }
                    }
                }

 

                return _blnResult;
            }
            catch (Exception ex)
            {
                // Handle exceptions during setup or container operations
                Console.WriteLine($"An error occurred: {ex.Message}");
                return false;
            }
        }

Monday, 19 August 2024

Tspsc g2 studyplan

 https://www.aspirantsclass.com/2023/03/tspsc-group-2-exam-100-days-study-plan.html

Wednesday, 14 August 2024

Find dupicates records using groupby

 SELECT 

    EmployeeNumber, 

    COUNT(*) as CountOfDuplicates

FROM 

    profiles

GROUP BY 

    EmployeeNumber

HAVING 

    COUNT(*) > 1;

Friday, 9 August 2024

apps

 https://www.nimbleappgenie.com/blogs/how-to-build-an-app-like-blablacar/

Wednesday, 7 August 2024

Harsco interview Qstns

 1.app initilizer

2.ngrx state management.

3.observable(i have admin access batch update using observable(observables)).

4.difference and obseravable and promises

5.how you did jwt in apis side how you consumed in angular side

what happen after expire token

6.change button syntax to be

1.in the center 

2.open modal popup

3.hide the button

Monday, 5 August 2024

angular firestore

 image store inside firebase storage section,




after successfull upload





Sunday, 4 August 2024

angula firebase immp

 add firebase to the angular application

ng add @angular/fire


https://www.youtube.com/watch?v=O0uVYhRE850&list=PL1UHgDbN7Tm4SZ6yLE9yDI-YDtf02uc7d

how to start emulator without android studio run

 https://www.youtube.com/watch?v=RHiw-NROo80

c#

 https://github.com/dcyuksel/Result