Some array sorting issues and solutions in ReactJS
To sort the data array, we can use many methods. Incorrect selection can lead to errors that are difficult to detect with uniform, standard-format test data. I would like to share some errors and solutions that I have encountered in a React project, as follows:
Your company is using Google Workplace, You have many information in Gmail, Google Drive, Google Calendar, Google Contacts and others alike. Suddenly, you remember you need to find some information, and you don't remember where that information is in Google Workplace. Google Cloud Search is is what you need in this case.
NextJS: Encrypt Cookie-Based sessions with NodeJS Crypto module
Cookie-base is one of the primary uses for session management. It is easy to implement, suits smaller applications, and has a lower server load but may offer less security than others.
As cookies are susceptible to client-side security risks, the key to safeguarding user information from unauthorized access is to carefully encrypt the sensitive data before storing it in the cookie. This way, even if a cookie is stolen, the data inside remains unreadable.
Be Confident with Data Security: Introducing Microsoft Azure's KeyVault.
In today's digital world, data security has become a top priority for businesses and organizations. Microsoft Azure, one of the world's leading cloud computing platforms, has introduced a powerful solution to this problem, which is a KeyVault.
Building A Basic Real-Time Application with Socket.io in Node.js and React.js
In today's digital age, real-time communication has become a crucial aspect of web applications. Whether it's for live chats, collaborative editing, or dynamic data updates, users expect instantaneous responses. Achieving this functionality is made possible by technologies like Socket.io, particularly when combined with the power of Node.js on the backend and React.js on the frontend.
Enhancing Coding Experience: The Value of ChatGPT for Programmers
In the dynamic world of technology, programmers encounter a diverse array of challenges. These range from debugging intricate code to devising innovative solutions for software development projects. Amidst this complexity, ChatGPT emerges as a valuable companion for programmers, offering several advantages to streamline and enhance their coding experience.
The software production and business environment is becoming more and more competitive, customers have more and better choices of high-quality products or services on the market.
Companies must differentiate themselves from the competition by hearing customer requirements and providing products or services that meet customer requirements with high levels of reliability and quality.
The cost of quality (CoQ)
The cost of quality is all of the costs that the software development team must bear to ensure the production of quality products or services.
The cost of quality allows the software development team to analyze the causes of problems and improve their products or services.
The cost of quality associated with a project consists of the cost of good quality and the cost of poor quality.
The cost of good quality (Cost of conformance) includes Prevention costs and Appraisal costs.
The cost of poor quality (Cost of nonconformance) includes Internal failure costs and External failure costs.
Prevention costs
These are costs associated with preventing problems and errors from occurring during the development of a product or service.
This includes activities such as training, process improvement, quality management planning, etc.
Appraisal costs
These are costs associated with evaluating product or service quality by finding errors and detecting defects during the development of a product or service.
This includes activities such as testing, inspection, etc.
Internal failure costs
Internal failure costs are the costs that arise when problems or issues are found and corrected before the product or service is released to users.
This includes costs associated with rework, scrap, etc.
External failure costs
External failure costs are the costs that arise when problems or bugs are found in a product or service after it has been released to users.
This includes costs associated with customer complaints, warranty claims, etc.
In summary, the cost of quality plays an important role in ensuring the quality of a product or service and creating value for customers.
The software development team should invest in preventing problems and errors from occurring by training employees on quality,
improving quality control processes and strengthening evaluation activities of product quality in the production process to ensure that the product or service meets quality standards and customer requirements.
The optimal cost of quality reflects the appropriate balance for investing in the cost of prevention and appraisal to avoid failure costs (internal/external).
Introducing Ngrok: Unified Ingress Platform for developers
By creating a tunnel from your computer (desktop, localhost) through the Firewall/Nat system, you can access the workstation from the internet. Ngrok can help you run project demos for customers to view from their own computers without needing to deploy the web to the server.
Additionally, you can test responsiveness on mobile easily through the URL that Ngrok provides and build a webhook to your local host.
Ngrok is available for macOS, Windows, and Linux.
How does Ngrok Work?
When you use Ngrok, you start it on your local machine and specify the port number of the local server that you want to expose. When you do that, Ngrok creates a secure tunnel to a public endpoint (a ngrok.io URL) that is accessible over the internet.
So now, all the traffic to the public endpoint is forwarded as a request to the local server running on your machine. Your local server responds to this request or traffic back to this public endpoint. This is also called port forwarding or localhost tunneling. This is the underlying principle through which Ngrok maps your local development server to one of its servers, making it seem like it’s just your local development server hosted somewhere.
Pricing
Ngrok currently includes 1 free package and 3 paid packages.
Ngrok is a highly secure platform for remote access and is safe to use. Ngrok provides tunneling, as mentioned above, which enables users to access local-hosted servers from outside the machine.
Quick start
Step 1: Install Ngrok
https://ngrok.com/download
Step 2: Connect your account
You need to go to the homepage https://dashboard.ngrok.com/, register and manage your account, here after logging in, go to the Your Authtoken section to get the login token.
Run the following command in your terminal to install the auth token and connect the Ngrok agent to your account.
-> ngrok config add-authtoken <TOKEN>
Step 3: Start Ngrok by running the following command
-> ngrok http http://localhost:8080
If your app is listening on a different URL, change the above command to match.
As shown above, the tunnel is created - press CTRL+C to terminate this connection, once the connection is maintained you can access your web application using the URL provided by ngrok
You can access this address from any device on the internet such as using your phone to access, send to friends, send customers to check first...
Conclusion
We’ve learned how Ngrok works internally by understanding the concept of port-forwarding and local-host tunneling. Ngrok is an extremely helpful tool for developers, especially for testing and debugging purposes in various types of applications.
StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < stringArray.Count; i++){
stringBuilder.Append(stringArray[i]);
}
return stringBuilder.ToString(); }
Using Span over arrays to circumvent unnecessary memory allocations and copying
Not good: Using the arrays may lead to unnecessary memory allocations and copying byte[] inputData = GetData(); ProcessingData(inputData);
Good: Using Span<T> helps avoid additional memory allocation and copying
byte[] inputData = GetData();
Span<byte> spanData = inputData.AsSpan();
ProcessingData(dataSpan);
Using Lazy Loading for Resources
Not good: Loading image resource when not needed var employeeImage = LoadImage(); // Some processsing
Good: Loading image resource when need to use Lazy<Bitmap> employeeImage = new Lazy<Bitmap>(() => LoadImage()); // After doing some processsing //... // Load the image when accessed Bitmap actualEmployeeImage = employeeImage.Value;
Conclusion:
These are just a few examples for improving performance when working with C#.
In the mid-1990s, Robert C. Martin gathered five principles for object-oriented class design, presenting them as the best guidelines for building a maintainable object-oriented system.
Michael Feathers attached the acronym SOLID to these principles in the early 2000s.
SOLID Class Design Principles
Single Responsibility Principle (SRP).
Open-closed principle (OCP)
Liskov Substitution Principle (LSP)
Interface Segregation Principle (ISP)
Dependency Inversion Principle (DIP)
Single Responsibility Principle (SRP)
The “S” in SOLID is for the Single Responsibility Principle. Classes should have one, and only one, reason to change. Keep your classes small and single-purpose.
Ex: Class ProductManager is performing 3 tasks: getting data from the database, processing data, and printing reports.
class ProductManager { public void QueryDataFromDB(); public void ProcessData(); public void PrintReport(); }
The ProductManager class is performing 3 tasks: getting data from the database, processing data, and printing reports. One class performs many tasks, so it violates the Single Responsibility Principle.
According to the principle, we need to separate this class into 3 separate classes so that the code is easy to read, has few bugs, and is easy to maintain.
class ProductManager { public void QueryDataFromDB(); }
class ReportLogic { public void ProcessData(); }
class PrintService { public void PrintReport(); }
Open-Closed Principle (OCP)
The “O” in SOLID is for the Open-Closed Principle. Design classes to be open for extension but closed for modification; you should be able to extend a class without modifying it. Minimize the need to make changes to existing classes
Ex: We have a ConnectionManager class that can be implemented to connect to database systems such as SQL Server, and MySQL.
class ConnectionManager { public function doConnection(object $connection) { if ($connection instanceof SqlServer) { // connect with SqlServer } elseif ($connection instanceof MySql) { // connect with MySql } } }
With the above class, if we want to support another database system like PostgreSQL, we must modify the class to support creating a connection to PostgreSQL, thus violating the Open-Closed Principle.
To not violate the above principle, we can correct it as follows:
abstract class Connection { public abstract function doConnect(); } class SqlServer extends Connection { public function doConnect() { // connect to SqlServer } } class MySql extends Connection { public function doConnect() { // connect to MySql } } class ConnectionManager { public function doConnect(Connection $connection) { $connection->doConnect(); // do something... } }
Liskov Substitution Principle( LSP)
The “L” in SOLID is for the Liskov Substitution Principle. Subtypes should be substitutable for their base types. From a client's perspective, override methods should not break functionality.
Ex: We define the Brid interface to have 3 functions: fly(), eat() and walk ().
interface Bird { public function fly(); public function walk(); public function eat();
} class Pigeon implements Bird { public function fly() { // do something } public function walk() { // do something } public function eat() { // do something } } class Penguin implements Bird { public function fly() { // penguin can not fly. } public function eat() { // do something } public function walk() { // do something } }
In the case of the Pigeon class implementing Bird, it is correct, but the Penguin class implementing Bird violates the Liskov Substitution Principle because Penguin cannot fly.
We can fix it in the following way so as not to violate the Liskov Substitution Principle. interface Bird { public function eat(); } interface FlyingBird extends Bird { public function fly(); } interface WalkingBird extends Bird { public function walk(); } class Pigeon implements FlyingBird, WalkingBird { public function fly() { // do something } public function eat() { // do something } public function walk() { // do something } } class Penguin implements WalkingBird { public function eat() { // do something } public function walk() { // do something } }
Interface Segregation Principle (ISP)
The “I” in SOLID is for the Interface Segregation Principle. Clients should not be forced to depend on methods they don’t use. Split a larger interface into several smaller interfaces.
Ex: The Bird interface defines many functions, but not every class that inherits this interface uses all the functions that have been defined. For example, Pigeon implementing Bird cannot use the fly function.
interface Bird { public function fly(); public function walk(); public function eat(); }
We can divide the Bird interface according to each function as follows:
interface Bird { public function eat(); } interface FlyingBird extends Bird { public function fly(); } interface WalkingBird extends Bird { public function walk(); }
Dependency Inversion Principle (DIP)
The “D” in SOLID is for the Dependency Inversion Principle. High-level modules should not depend on low-level modules; both should depend on abstractions. Abstractions should not depend on details; details should depend on abstractions.
Why does SOLID help programming be more efficient?
Easy to understand: The clear division of functions of each class makes reading the code easier to understand.
Easy to update & maintain: Because it is easy to understand, updating or maintaining will be easier when a bug occurs.
Reuse: because the components do not depend on each other, each module can be separated and these modules can be reused for future projects.