Serilog enrich with client IP
I wanted to include client IP in my logs but it didn't show up:
Nginx
In nginx the trailing slash is important in proxy_pass directive. If you have a trailing slash in the proxy_pass directive like this:
Turn off monitor PowerShell
Use the following PowerShell script to turn off monitor(s):
Git
Upstream vs Origin
Shell
Shell is the interface between the user and the operating system. It acts as a keyboard interpreter, taking the keyboard input from the user and delivering it to the operating system. You can think of the shell as being the part of the operating system that allows you to interact with the kernel.
Cache
Caching is a technique to improve the performance of applications by storing frequently accessed data in a temporary storage area. Caching reduces the time required to access data by retrieving it from the cache instead of the original source, such as a database or a remote server. Here are some common caching techniques:
Authentication
There are several types of authentication, each with its own pros and cons:
Postgres timestamp with timezone
I was using DateTime.UtcNow in .Net to store the current time in a Postgres database. However, after updating to the latest version of the Postgres I noticed that my application doesn't run anymore.
Custom app for Microsoft Teams
Microsoft Teams is a Microsoft collaboration tool and gained more popularity during COVID-19, becoming Microsoft's fastest-growing business app ever. But beyond the capabilities of collaboration and meetings, it comes with a rich library of extension apps which you can add to your teams.
Saved WIFI passwords
If you're connected to a WIFI network but you've forgot what was your password and you don't want to reset your router's passwod, you can follow the following steps:
CSRF
Cross-Site Request Forgery (CSRF)[pronounced see-surf] is an attack that forces an end user to execute unwanted actions on a web application in which they're currently authenticated.
XSS
Cross-site Scripting attack is a type of injection which is possible whenever a web application accepts an input from users without validating or encoding the input. For example if I enter scriptalert(0)/script in the search field of a website and the website is not encoding the special characters like or , then this script will be injected in raw format in the HTML and browser will execute it and diplay an alert box.
Compiler
In pre-.NET applications like VB6, the code are being converted to Native Code or Machine Code (.dll, .exe) via compiler and these codes will be run by the operating system. The problem with these languages is that they are not portable. This means that they can only run on a specific operating system that the compiler has designed for, so we cannot run these applications on different operating systems.
Imperative vs Declarative
In imperative languages, we give orders to the computer and it performs the orders for us. Imperative programming focuses on describing how a program operates step by step.
CQRS
CQRS stands for Command and Query Responsibility Segregation, a pattern that separates read and update operations for a data store. Implementing CQRS in your application can maximize its performance, scalability, and security. When the number of reads on the database is higher than the writes which is the case for most of the applications we can separate the read and write databases.
NoSQL
In 2006, Google released a paper that described its Bigtable distributed structured database. Bigtable is a distributed storage system for managing structured data that is designed to scale to a very large size: petabytes of data across thousands of commodity servers.
REST
RESTful APIs are designed to be simple, lightweight, and scalable, making them a popular choice for building web applications and services. One of the key benefits of RESTful APIs is that they are stateless, meaning that each request contains all the necessary information to complete the request, and the server does not need to maintain any session information. This makes RESTful APIs highly scalable and allows them to handle a large number of requests from multiple clients simultaneously.
Connection pooling
Connecting to a database server typically consists of several time-consuming steps. A physical channel such as a socket or a named pipe must be established, the initial handshake with the server must occur, the connection string information must be parsed, the connection must be authenticated by the server, checks must be run for enlisting in the current transaction, and so on.
Long-running tasks
In today's world, users expect applications or websites to be fast, and usually, a latency of around 100 milliseconds is considered reasonable. We can improve the latency of services by avoiding chatty APIs or leveraging materialised views for more expensive queries. However, for some long-running jobs like generating a PDF or performing a complex calculation, there is not much we can do to make them run faster rather than scaling up/out. In this article, I'm going to take a look at two patterns for handling such requests.
Scalable data systems
In today's applications unlike decades ago, CPU power is not the only limiting factor anymore and data handling became a more challenging part of our applications. From capturing various sensor data for farm monitoring to the contents created by users in social media to track users' behaviour on e-commerce websites, all and all are bombarding our data systems.
ASP.NET middleware
Middleware is a component in the app pipeline to perform some work on request and response, handing the modified request or response to the next middleware until the response is sent to the client.
Static website in Azure storage
Static websites are getting more popular again with the increased use of Single Page Applications (SPA). They are a cheaper alternative to dynamic websites which need a backend. In the simplest form, they are more secure as there is no backend code. However, they could be fully-fledged websites that use JavaScript for client-side scripting and communicating with the backend using API and serverless architecture.
Angular unit tests in GitLab
Unit testing brings many benefits to our projects by assuring that code mistakes could be captured early and not in production. You don't need to remember every single logic you or other developers have used in the code before refactoring. You start refactoring and tests will tell you when something has broken.
AWS site-to-site VPN
Have you ever wondered why in some organisations you need to connect to a VPN to use other offices' private information while in some other organisations just being connected to the local network gives you access to all those information?
AWS EC2 auto start/stop
I was on a gig that needed to have an on-premise infrastructure and from time to time we needed to take servers out for on-field testing. During that time the servers were inaccessible to developers. We decided to create an AWS Serverless stack that we could use for our development and test environment. In our first attempt, we created the stack but we noticed if we want to use the serverless stack we need to modify our reverse proxy and some project configs. And with this change, the development environment was going to be a bit different than our production environment.
Windows "PATH" environment variable
When we type a command in windows terminal, it automatically searches the PATH variables and if it could find a match, it'll execute it otherwise it'll display an error that couldn't find the command. All the locations that windows searches for the commands are listed in PATH variables in the following location:
Vim
Vim is a highly configurable text editor built to enable efficient text editing. It's included in many Unix-like operating systems, including Linux and macOS, and is available for other platforms as well. Understanding Vim can be beneficial for tasks such as editing configuration files, programming, or making quick changes in a terminal environment, enhancing overall productivity on these systems.
Azure Function App Redeployment Using Bicep Deletes Functions
I was working on an Azure Function App project with two repositories. The initial repository aimed at creating and configuring resources within Azure, while the second one focused on an Azure function code.
Bicep Linter Issue When Folder Contains Space
I cloned a project and noticed that the bicep template fails to resolve the paths inside my template. The template was compiling successfully and the problem was just in VSCode.
Connection refused on connecting to PostgreSQL running in Docker using pgAdmin
I was running both my database and the RDBS in a docker container to have all the development tools ready without installing additional software. My Docker compose file looked like this:
Concurrency
Concurrency is the ability of a system to perform multiple tasks simultaneously, without blocking or delaying the execution of other tasks.
Atomicity
Atomicity is a concept in computer science that refers to the property of a transaction or operation being treated as a single, indivisible unit. It means that either the entire transaction succeeds or fails, and there is no partial execution or data loss.
Greedy algorithm vs dynamic programming
Greedy algorithms and dynamic programming are both techniques used in computer science for solving optimization problems, but they differ in their approach to finding the optimal solution.
Sorting algorithms
There are many different sorting algorithms, each with its own set of advantages and disadvantages depending on the type of data being sorted and the desired outcome.
Update NPM packages to the latest version
If you want to update all of your application's packages to their latest version, you first need to identify the packages that are out of date. To do this, run the following command to discover any out-of-date packages:
Regex
Regex can be a powerful tool for working with text, but it can also be complex and difficult to master. This cheat sheet provides a quick reference for some of the most common regex patterns and syntax.
Python package manager
Python package managers are tools that allow you to install, manage, and update third-party Python libraries and dependencies in your Python environment. Using a package manager can help simplify the process of installing and managing dependencies for your Python projects, ensuring consistency and reproducibility across different environments.
Delete duplicate files in a folder using PowerShell
If you have a folder with duplicate files that you want to delete, one way to do this is by using PowerShell. This involves computing the hash of each file, comparing the files based on their hash value, and deleting the files that have identical hash values.
Entity Framework many to many relationship using Fluent API
In Entity Framework you don't need to manually insert an entry into the join table. Even you don't need to define the join table in your setup. Whenever you add a new object to either of the tables via Entity Framework, it takes care of the rest.
Windows credential manager
We can store credentials in Windows Credential Manager instead of hard-coding them into our code. If we want to use a service or a PowerShell script that requires some form of credentials/secrets we can use this feature. Navigate to Windows Credential Manager by:
.NET memory management
The summary and highlights of the book "Under the hood of .NET memory management" which I enjoyed reading it. Some of the contents might be outdated but I think it gives you a good understanding of how the languages memory management work.
Reference type vs value type
Classes and objects are reference types and when we assign them to a new object, we are just assigning the reference, not the actual object. And this is valid for C#, JavaScript, LINQ, the map function of es6 and everywhere.
Messaging pattern
Messaging patterns help in connecting services in a loosely coupled manner. What it means is that services never talk to each other directly. Instead, a service generates and sends a message to a broker (generally a queue) and any other service that is interested in that message can pick it up and process it. We can use Bus or Queue for implementing the messaging pattern.
Throttling design pattern
Control the consumption of resources used by an instance of an application or service. This can allow the system to continue to function and meet service level agreements (SLA), even when an increase in demand places an extreme load on resources.
Strategy design pattern
With design patterns, instead of code reuse, we get experience reuse. For this pattern, we need to identify the aspects of our code that are changing with every new requirement and we need to pull it out and separate it from all other stuff that doesn't change.
Check variables value in RAM
If you want to check the value of a variable in your RAM, get the address of that variable using the following code:
Fast and slow pointer technique
The fast and slow pointer technique (also known as the tortoise and hare algorithm) uses two pointers to determine traits about directional data structures. This can be an array, a singly-linked list, or a graph. It is often applied to determine if there are any cycles in the data structure and is therefore also known as Floyd’s Cycle Detection Algorithm.
Android Debug Bridge (ADB)
ADB is a command-line tool that lets you communicate with an Android device. It includes three components: Client, Daemon (adbd) and Server. The client is the adb.exe file in the platform tools folder. The daemon runs the command on a device and it's a background process on the device. The server manages communication between the client and the daemon and runs as a background process on your development machine.
SQL server index
If we have a composite non-cluster index, the order of columns is important. For example, if I create an index on columns A,B,C and I query database filtering based on A,B,C columns, this index will help my query to run faster but if I want to query on B, C columns and not A, this index will not be used by SQL because the index has been created first on column A and if column A is not in the filtering criteria then SQL cannot use this index. If I query on A, B columns and not C because the starting column exists in the where clause then SQL can partially use the index.
React hooks
Hooks are a new way of creating stateful components without classes. you can use hooks only on the body of the components or the body of other hooks and you cannot use them on helper functions or inside other functions.
Environment-specific config in React
If we want to have different settings based on the environment (development, test, production) we can leverage environment variables. However, if we bootstrapped our React application using "Create-react-app" command, we don't have access to the Webpack for the fully customised build. Instead, we can define variables in our NPM scripts and in our code we can test those variables and implement different functionalities.
Basic Regular Expression vs Extended Regular Expression
POSIX or "Portable Operating System Interface for Unix" is a collection of standards that define some of the functionality that a UNIX operating system should support. One of these standards defines two flavours of regular expressions. Commands involving regular expressions, such as grep and egrep , implement these flavours on POSIX-compliant UNIX systems.
Rename pictures in a folder to date taken using PowerShell
To rename all the pictures in a folder to their date taken value, run the following script in a PowerShell in that folder:
Read Large Files in .NET
If the file we want to process from a network location is huge and doesn't fit in the memory, we can read just the header of the file and read the body as stream. We can either pass the HttpCompletionOption to the GetAsync method or use GetStreamAync method:
You don't need maximum length for PostgreSQL columns
In PostgreSQL unlike SQL Server or some other databases, we don't need to specify the max length for varchar or char data types. Based on the Postgres official documentation, in most cases we can use text field that is identical to nvarchar(MAX) in other database systems.