Skip to content

Instantly share code, notes, and snippets.

View KeyurRamoliya's full-sized avatar
🎯
Focusing

Keyur Ramoliya KeyurRamoliya

🎯
Focusing
View GitHub Profile
@KeyurRamoliya
KeyurRamoliya / SQL - Optimize Your SQL Queries for Performance.md
Created September 30, 2023 07:40
SQL - Optimize Your SQL Queries for Performance

SQL - Optimize Your SQL Queries for Performance

Optimizing SQL queries is crucial for achieving efficient database operations. Well-optimized queries can significantly improve the performance of your applications. Here are some tips for optimizing SQL queries:

  1. Use Indexes Wisely: We've already discussed the importance of indexes, but it's worth repeating. Properly chosen indexes can dramatically speed up query execution. Analyze your query execution plans to identify where indexes can be beneficial and ensure that your indexes are regularly maintained.

  2. *Avoid Using SELECT : Instead of selecting all columns using SELECT *, explicitly list the columns you need. This reduces the amount of data transferred from the database to your application and can improve query performance.

  3. Limit the Result Set: Use the LIMIT or TOP clause to restrict the number of rows a query returns, especially when you don't need the

@KeyurRamoliya
KeyurRamoliya / SQL - Use Indexes Wisely for Performance Optimization.md
Created September 30, 2023 06:18
SQL - Use Indexes Wisely for Performance Optimization

SQL - Use Indexes Wisely for Performance Optimization

Indexes are database structures that improve the speed of data retrieval operations on database tables. Properly using indexes can significantly enhance the performance of your SQL queries. Here are some tips for using indexes wisely:

  1. Identify the Right Columns to Index: Not every column needs an index. Focus on indexing columns that are frequently used in WHERE clauses for filtering, JOIN conditions, and sorting (ORDER BY). Primary keys and foreign keys are good candidates for indexing. Avoid over-indexing, as it can slow down data inserts and updates.

  2. Clustered vs. Non-clustered Indexes: Understand the difference between clustered and non-clustered indexes. A table can have only one clustered index, which determines the physical order of data in the table. Non-clustered indexes are separate data structures that store a copy of a portion of the data and the indexed columns.

  3. Consider Composite Indexes: Composite indexes inc

@KeyurRamoliya
KeyurRamoliya / C# - Parallel Programming with async and await for Concurrent Execution.md
Created September 30, 2023 06:03
C# - Parallel Programming with async and await for Concurrent Execution

C# - Parallel Programming with async and await for Concurrent Execution

C# provides asynchronous and parallel programming tools, making performing multiple tasks concurrently and efficiently easier. When working with tasks and async/await, you can use Task.WhenAll to execute multiple asynchronous operations concurrently and wait for all of them to complete.

Here's an example:

using System.Diagnostics;
public class Program
{
@KeyurRamoliya
KeyurRamoliya / REST API - Version Your API.md
Created September 28, 2023 10:04
REST API - Version Your API

Version Your API

When designing a RESTful API, including a version number in your API's URL is a good practice. This allows you to make changes and improvements to the API without breaking existing clients that rely on the older version.

Here's an example of how to version your API:

https://api.example.com/v1/resource
@KeyurRamoliya
KeyurRamoliya / Docker - Use Docker's Health Checks for Container Health Monitoring.md
Created September 28, 2023 09:51
Docker - Use Docker's Health Checks for Container Health Monitoring

Use Docker's Health Checks for Container Health Monitoring

Docker provides a built-in health check feature that allows you to monitor the health of your containers. Health checks are valuable for ensuring the availability and reliability of your services running inside containers. By defining health checks, you can detect when a service becomes unhealthy and take appropriate actions, such as restarting the container.

Here's how to implement a health check in your Dockerfile:

FROM nginx:latest

# Add a simple health check command
@KeyurRamoliya
KeyurRamoliya / SQL - Use Transactions for Data Consistency.md
Created September 28, 2023 09:33
SQL - Use Transactions for Data Consistency

SQL - Use Transactions for Data Consistency

Transactions are a fundamental concept in SQL databases that help maintain data consistency and integrity. A transaction is a sequence of one or more SQL statements that are treated as a single atomic unit. Transactions ensure that either all the changes within the transaction are applied, or none of them are, which helps prevent data corruption and inconsistencies. Here's how to use transactions effectively:

Start a Transaction: Depending on your database system, You can start a transaction using the BEGIN TRANSACTION or START TRANSACTION statement.

BEGIN TRANSACTION;
@KeyurRamoliya
KeyurRamoliya / Prune Unused Resources in Docker.md
Created September 23, 2023 08:06
Prune Unused Resources in Docker

Prune Unused Resources in Docker

Over time, Docker can accumulate unused resources like containers, images, volumes, and networks. These unused resources consume disk space and can make your Docker environment less efficient. To keep your system clean and free up disk space, it's a good practice to regularly prune these resources using Docker's built-in commands.

Here are some useful commands for resource pruning:

  • Prune Unused Containers:
    docker container prune
@KeyurRamoliya
KeyurRamoliya / Custom Event Accessors with Delegates.md
Created September 23, 2023 06:40
Custom Event Accessors with Delegates

Custom Event Accessors with Delegates

In C#, events are often used to provide a way for classes to notify other classes when certain actions or changes occur. Events typically use the event keyword to declare them and are associated with a delegate that defines the event's signature.

However, you can create custom event accessors by directly using delegates, which allows you more control over event subscriptions and unsubscriptions. This is especially useful when implementing custom logic around event handling.

Here's an example:

using System;
@KeyurRamoliya
KeyurRamoliya / Optimize Performance with Memoization.md
Created September 23, 2023 06:06
Optimize Performance with Memoization

Optimize Performance with Memoization

Memoization is an advanced technique used to optimize the performance of functions by caching the results of expensive or time-consuming computations. By storing previously calculated results, you can avoid redundant calculations and improve the efficiency of your code.

Here's a basic example of memoization:

// Without memoization
function fibonacci(n) {
    if (n <= 1) return n;
@KeyurRamoliya
KeyurRamoliya / List Comprehensions for Filtering and Transforming Lists.md
Created September 23, 2023 05:22
List Comprehensions for Filtering and Transforming Lists

List Comprehensions for Filtering and Transforming Lists

List comprehensions are a concise and powerful way to create, filter, and transform lists in Python. They provide a more readable and Pythonic approach than traditional loops when working with lists. Here's a quick overview of list comprehensions:

Basic List Comprehension:

You can create a new list by applying an expression to each item in an existing iterable (e.g., a list, tuple, or range). The basic syntax is:

new_list = [expression for item in iterable]