teleren/devto huggingface dataset:
PHP: why make your own exceptions?
Tags: php, beginners, programmers
Published: 2023-12-03 10:48:19

Like many other programming languages, PHP allows throwing and catching exceptions.

If you surround your code with a `try/catch` block, you can handle exceptions very precisely in your app.

The how is quite straightforward, so do not hesitate to [read the documentation](https://www.php.net/manual/en/language.exceptions.php) to achieve it.

Here, I want to discuss the why and when you should use your own exceptions.

## Why use exceptions anyway?

As a beginner, you might not see why exceptions can be useful, and even think that's not a great idea.

Why raise errors? Handling default values and behaviors should give a better experience to the end users when _failures_ happen.

Pay attention to the words and their meanings. It's critical to understand the difference between failures and exceptions.

Exceptions are meant to handle unexpected situations and behaviors. You do want some failures to happen, so the idea is not to replace all error cases with an exception.

However, it's particularly useful when using third-party APIs and similar resources, as **you don't control them**.

If you maintain public APIs, raise exceptions **early**, especially when you receive wrong inputs. Don't let malformed payloads reach the heart of your app.

## The built-in exception vs. your custom exception

In code, this would mean:

```PHP
if (SOME_CONDITION) {
    throw new Exception('Error.');
}
```

vs.:

```PHP
class MyException extends Exception {}

if (SOME_CONDITION) {
    throw new MyException('My specific error happened.');
}
```

The `throw` keyword is usually found within methods and functions (not like the above example) to force an error for a specific condition or when wrong inputs are sent to the app.

Then, developers can catch it with a `try/catch` block, just like with the basic built-in exception.

A good reason not to use the basic exception would be to provide a specific case other parts of the code can catch instead of the generic exception.

## Catch them all?

You may catch more than one custom exceptions in PHP:

```PHP
try {
   // success
} catch(MyException $e) {

} catch(MyOtherException $e) {

}
```

However, don't _mute_ them. For example, the following code would be considered as a bad practice:

```PHP
  try {
        $PDO = new PDO( '...' );
  } catch (PDOException $e) {
        $this->log->error($e->getMessage());
  } 
```

If your critical DB request fails, it's an emergency, and you want to know it, so let it cry.

## Wrap up

Exceptions are great to handle processes and resources you don't control, like third-party vendors and APIs.

Making you own exceptions can be great for your maintenance and to keep your app consistent.

However, don't try to wrap all failures or catch bugs.
Angular Signal Effect
Tags: angular, programming
Published: 2023-12-03 11:00:00

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xdxc5k1ootod7qak7eev.png)

A [Signal](https://angular.dev/guide/signals#what-are-signals) is a wrapper around a value that can notify affected consumers when that value changes.

But what if something happens when a Signal is modified?

That's where [Effect ](https://angular.dev/guide/signals#effects)comes in.

Effects are performed only when the value of a signal within it changes.

When an Effect is executed, it keeps track of any reading of the Signal value. Each time one of these values changes, the Effect is executed again.

Let's say that in behavior they are similar to signal computed.
There are just a few things to keep in mind with Effect:
🌟 They must be created within the constructor or in a component property.
🌟 Effects are always executed asynchronously, during the Change Detection process.

In addition, Effects were created to handle certain cases, not to change the State of a component or application.

The use cases are as follows:
🌟 To perform Data Logging.
🌟 To keep data synchronized with localStorage.
🌟 To add custom behaviors to the DOM.

Trying to update a Signal within an effect() is not allowed by default, as it could trigger unwanted behavior (infinite loop such as SignalA triggers update of SignalB that updates SignalC that updates SignalA - and around we go).

That said, if you know what you're doing and are 100% sure that you won't trigger an infinite loop, you can override that setting with the optional parameter allowSignalWrites as follows:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c2n6alabuqojkoca6u8e.png)

**Conclusion:**
Effects are very powerful, but you have to be careful how you use them.
Example here: https://stackblitz-starters-yzbh3d.stackblitz.io/

---

I hope you found it useful. Thanks for reading. 🙏

Let's get connected! You can find me on:
- Medium: https://medium.com/@nhannguyendevjs/
- Dev: https://dev.to/nhannguyendevjs/
- Substack: https://nhannguyendevjs.substack.com/
- Linkedin: https://www.linkedin.com/in/nhannguyendevjs/
- X (formerly Twitter): https://twitter.com/nhannguyendevjs/
Stay warm with hometex comforter
Published: 2023-12-03 10:47:38

Comforter has significant importance in winter for many reasons. When winter is coming people find the **[best comforter set](z2dge)**. Because nowadays people want to decorate their room with some fashionable and colorful comforter. Comforters especially made of some materials like wool, and synthetic fibers, provide exceptional warmth.

A comfortable sleep mood environment is crucial for quality rest. This warmth and softness can provide comfort. Now you can search for the **[best comforter in Bangladesh](z2dge)**. You can see many companies who sell comforters. 

Hometexltd.com sells the best hometex comforter. And **[hometex comforter prices in Bangladesh](z2dge)** are also affordable. They sell a variety of sizes, designs, and fashionable comforters. That is to decorate your home and give it a new look.

So you can **[buy hometex comforters in Bangladesh](z2dge)**. They have a mobile banking system and online payment methods. So it's very easy to purchase and stay warm this winter.
Explain about Agile Methodology
Published: 2023-12-03 10:42:57

**Agile methodology** is a project management approach that prioritizes cross-functional collaboration and continuous improvement. It divides projects into smaller phases and guides teams through cycles of planning, execution, and evaluation.
**Agile’s four main values are**:
•	Individuals and interactions over processes and tools.
•	Working software over comprehensive documentation.
•	Customer collaboration over contract negotiation.
•	Responding to change over following a plan.
Many teams embrace the Agile approach for the following reasons:
**Rapid progress** : By effectively reducing the time it takes to complete various stages of a project, teams can elicit feedback in real time and produce working prototypes or demos throughout the process.
**Customer and stakeholder alignment** : Through focusing on customer concerns and stakeholder feedback, the Agile team is well positioned to produce results that satisfy the right people
**Continuous improvement** : As an iterative approach, Agile project management allows teams to chip away at tasks until they reach the best result.
**Types of Agile methodologies**
Agile project management is not a singular framework but an umbrella term that includes a wide range of methodologies, including Scrum, Kanban, Extreme Programming (XP), and the Adaptive Project Framework (APF).
• **Scrum** : It is ideal for projects with rapidly changing requirements, using short sprints.
• **Kanban** : It visualizes project progress and is great for tasks requiring steady output.
• **Lean** : It streamlines processes, eliminating waste for customer value.
• **Extreme Programming (XP)** : It enhances software quality and responsiveness to customer satisfaction.
• **Adaptive Project Framework (APF)** : Works well for projects with unclear details, as it adapts to constantly evolving client needs.
Describe the difference between a. Smoke and Sanity Testing b. Validation and Verification
Published: 2023-12-03 10:35:52

**Smoke and Sanity Testing:**
The process to create an executable program uses “build” software and is called “Software Build”.   
**Sanity testing:** Sanity Testing verifies the new functionality like bug fixes and is a is a subset of Regression Testing.
Sanity testing is performed to check if new module additions to an existing software build are working as expected and can pass to the next level of testing. It is a subset of regression testing and evaluates the quality of regressions made to the software. The main purpose of Sanity testing is to verify that the changes or the proposed functionality are working according to plan. Suppose there are minor changes to be made to the code, the sanity test further checks if the end-to-end testing of the build can be performed seamlessly.
**Smoke Testing:** Smoke Testing verifies the critical functionalities of the system and is a subset of acceptance testing.
Smoke Testing is carried out post software built in the early stages of SDLC (software development life cycle) to reveal failures, if any, in the pre-released version of a software. The testing ensures that all core functionalities of the program are working smoothly and cohesively. The intent of smoke testing is not exhaustive testing but to eliminate errors in the core of the software. It detects errors in the preliminary stage so that no futile efforts are made in the later phases of the SDLC. 
**Validation and Verification:**
**Verification**  in Software Testing is a process of checking documents, design, code, and program to check if the software has been built according to the requirements or not. The main goal of verification process is to ensure quality of software application, design, architecture etc. The verification process involves activities like reviews, walk-throughs, and inspection. It does not involve executing the code. It comes before validation.
**Validation**  in Software Engineering is a dynamic mechanism of testing and validating if the software product meets the exact needs of the customer or not. The process helps to ensure that the software fulfills the desired use in an appropriate environment. The validation process involves activities like unit testing, integration testing, system testing and user acceptance testing. It always involves executing the code. It comes after verification.
Safecryptowallet: An Overview Of The New Cryptocurrency Wallet
Published: 2023-12-03 10:27:13

In a world of rapidly growing technologies and cryptocurrencies, the secure storage of digital assets is becoming an increasingly important issue. One of the latest players providing solutions in this area is Safecryptowallet. In this article, we will look at the key aspects of this cryptocurrency wallet, which promises to provide security and convenience for storing and managing your digital assets.

1. Security
One of the main criteria when choosing a cryptocurrency wallet is the level of security. Safecryptowallet, according to the developers, provides a high level of protection for user assets. This includes the use of modern encryption technologies, two-factor authentication and other security measures.

2. Ease of use
Despite the importance of security, the user experience is also of great importance. Safecryptowallet probably offers an intuitive interface that makes storing, sending and receiving cryptocurrencies accessible even for beginners.

3. Mobile Application
Mobile applications are becoming increasingly popular for managing cryptocurrency assets on the move. Safecryptowallet arguably provides a mobile application, providing flexibility and convenience for users.

4. Reputation and User Reviews
Before entrusting your cryptocurrency assets to any wallet, it is useful to read the reviews and opinions of other users. This will help you get an idea of the real experience of using Safecryptowallet.

Conclusion
Safecryptowallet represents another important element in the world of cryptocurrency wallets. It is important to investigate its functionality, security and usability in detail before deciding on choosing a wallet to store your digital assets. Perhaps this will become a reliable tool to protect your cryptocurrency portfolio.
http://safecryptowallet.io
Torpe page layout
Published: 2023-12-03 10:16:07

The next step in the process is to define a layout design for the page. For most people, starting from scratch can be a bit challenging. Instead of creating something entirely new, we're going to take inspiration from a [website](https://lajarecords.lojavirtualnuvem.com.br/) that my friend and I like. We've chosen this website, which was originally created with NuvemShop. While NuvemShop is great for quickly setting up a selling platform, our goal is to create a fully responsive and well-structured e-commerce site.

Based on that website, I have created this initial design. As you can see, both designs are quite similar, with the mobile version having fewer logos and images for better rendering.

![initial design](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nnrwp87h0065no48el7u.png)

With this concept in mind, I will start creating issues for each task on GitHub and begin the coding process.
What is the difference between manual and Automation testing?
Published: 2023-12-03 10:16:07

In manual testing, a human performs the tests step by step, without test scripts. In automated testing, tests are executed automatically via test automation frameworks, along with other tools and software. 
When manually testing, the tester validates the key features of a software application. Analysts execute test cases and develop summary error reports without specialized automation tools. 
Automated testing helps testers execute more test cases and improve test coverage. When comparing manual vs. automation testing, manual takes longer. Automated testing is more efficient.
Both have their strengths and weaknesses. Manual testing is slow and tedious. But its strength is that it better handles complex scenarios. Automated testing requires coding and test maintenance. But on the plus side, it is much faster and covers many more permutations.
**Manual:**
•	Done manually by QA testers.
•	Time-consuming and less efficient.
•	Entirely manual tasks.
•	Difficult to ensure sufficient test coverage.
•	less expensive as one does not need to spend a budget on automation tools and processes.
•	Manual testing is flexible as it can adapt easily to changes in the user interface.
**Automation:**
•	Done automatically using automation tools and scripts.
•	More testing in less time and greater efficiency.
•	Most tasks can be automated, including real user simulations.
•	Easy to ensure greater test coverage.
What is the difference between QA and QC?
Published: 2023-12-03 10:15:07

QA is process-oriented, and it focuses on preventing quality issues. QC is product-oriented and focused on identifying quality issues in manufactured products that could affect customer satisfaction. Another way to understand this distinction is actions vs. results.
QA Processes:
•	Documentation
•	Audits
•	Supplier management
•	Personnel training
•	Change control
•	Investigation procedures
QC Procedures:
•	Batch inspection
•	Product sampling
•	Validation testing
•	Laboratory testing
•	Software testing

Many people think QA and QC are the same and interchangeable, but this is not true. Both are tightly linked and sometimes it is very difficult to identify the differences. Fact is both are related to each other, but they are different in origins. QA and QC both are part of Quality Management however QA is focusing on preventing defect while QC is focusing on identifying the defect.
Vitepress Auto-generate Sidebar Data Plugin
Published: 2023-12-03 07:28:04

## Vite Plugin: vite-plugin-vitepress-auto-sidebar

### Background

A while ago, I started migrating my personal blog site's tech stack from `vuepress` to `vitepress`. The migration process was quite straightforward, and the overall experience improved significantly. The default theme also looked much better.

This is the version you are currently visiting~

However, during the process, I encountered an issue. Vitepress officially does not support automatic generation of sidebars, unlike `vuepress`, which can generate them automatically.

This dilemma led me to an idea: could I write a `vitepress` plugin to handle the sidebar generation for me? After some research, I found that the official Vitepress plugin system is not available yet.

Considering that Vitepress is based on Vite, I thought, why not write a Vite plugin instead? And that's how `vite-plugin-vitepress-auto-sidebar` came to be.

### Features

- Automatically creates sidebar data.
- Real-time updates to the sidebar data by monitoring file changes.

### Installation
```bash
npm install vite-plugin-vitepress-auto-sidebar
```

### Usage

Simply add the plugin in the `.vitepress/config.ts` file:

```JavaScript
import AutoSidebar from 'vite-plugin-vitepress-auto-sidebar';
export default defineConfig({
  vite:{
    plugins:[
      // add plugin
      AutoSidebar()
    ]
  },
})
```

- Plugin Project Link: [vite-plugin-vitepress-auto-sidebar](https://github.com/QC2168/vite-plugin-vitepress-auto-sidebar)

- Example Code: [example code](https://github.com/QC2168/vite-plugin-vitepress-auto-sidebar/tree/main/example)

## May 7, 2023

The plugin has been updated to version 1.4.0, now supporting prefix deletion and sidebar collapsing. (See [readme.md](https://github.com/QC2168/vite-plugin-vitepress-auto-sidebar) for details)

Special thanks to @[酱路油过](https://juejin.cn/user/2612095359386861) for contributing code to the plugin!

> If you encounter any issues or have suggestions during use, feel free to raise an issue or pull request~ 😊😊
How to use OpenAI API with JavaScript
Tags: javascript, openai, typescript, gpt4
Published: 2023-12-03 10:14:02

(This article is translated from https://zenn.dev/hikaelis/articles/b93cc6f94a6bd3)
This shows how to access to GPT4/3.5 using openai v4 of JavaScript Library. 
The usage was changed from version 4 . I tried it on node18. 

## 1. Install the Library

Install openai v4 via npm or yarn

```bash
npm install --save openai
# or
yarn add openai
```

## 2. Get API KEY of OpenAI

Get API KEY of OpenAI from OpenAI site. Please be careful it isn't the same as ChatGPT Plus. 
https://openai.com/blog/openai-api

## 3. Coding

The usage was significantly changed from v4 (it became easier)
I learned from this video(is it ok? cuz he showed his API KEY...)
[How to use the OpenAI API in NodeJS](https://www.youtube.com/watch?v=o0HdBsxZjw0)

The example of coding is below↓

```js
const openai = new OpenAI({
	apiKey: OPENAI_API_KEY // API KEY
})
const message = "message to GPT"
const completion = await openai.chat.completions.create({
	            model: "gpt-4", // GPT Model name
	            messages: [{ "role": "user", "content": message }],
});
console.log(completion.choices[0].message.content); // GPT answer
```

You can confirm available GPT models on this Document. 
https://platform.openai.com/docs/models

## 4. Summary

If you just want to listen to GPT in chat format, I think this usage is sufficient.
I am actually using this usage to run the bot. (I will write an article about it later.)
https://github.com/hikaelis/nostr_shinjiro_bot_public

GPT is rapidly making progress, so usage will probably be changed when updates. So please check out openai-node documents. 
https://github.com/openai/openai-node
What is the difference between QA and QC?
Published: 2023-12-03 10:09:09

QA is process-oriented, and it focuses on preventing quality issues. QC is product-oriented and focused on identifying quality issues in manufactured products that could affect customer satisfaction. Another way to understand this distinction is actions vs. results.
**QA Processes:**
•	Documentation
•	Audits
•	Supplier management
•	Personnel training
•	Change control
•	Investigation procedures
**QC Procedures:**
•	Batch inspection
•	Product sampling
•	Validation testing
•	Laboratory testing
•	Software testing

Many people think QA and QC are the same and interchangeable, but this is not true. Both are tightly linked and sometimes it is very difficult to identify the differences. Fact is both are related to each other, but they are different in origins. QA and QC both are part of Quality Management however QA is focusing on preventing defect while QC is focusing on identifying the defect.
The Power of Symfony in DevOps
Tags: symfony, devops, webdev, backend
Published: 2023-12-03 09:41:52

Symfony is a potent PHP framework known for its flexibility and robust architecture, making it a popular choice in web development. Its seamless compatibility with DevOps practices underscores its relevance in modern development workflows. This blog post will explore the DevOps side of Symfony development, covering essential topics such as continuous integration, deployment strategies, and monitoring.

## Continuous Integration with Symfony:
**- Setting the Foundation:**

![setting](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kfh1272do9w4j9vpisp0.png)
**- Building Pipelines:**

![pipelline](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n9ll8rskp25vhyg064gy.png)
**- Versioning and Dependency Management:**

![versioning](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xssjqp0mw9pe1a8py6i4.png)

## Deployment Strategies for Symfony:
Gain an understanding of various deployment strategies, such as the blue-green deployment method, which entails using two identical environments (blue and green) and redirecting traffic between them during the deployment process.
**- Automated Deployment with CI/CD:**

![cicd](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/54671krkakq810pburbh.png)
**- Zero-Downtime Deployment:**

![deployment](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iuaj1arltf8l3e7s8js8.png)

## Monitoring Symfony Applications:

**What is Monitoring:**
Acknowledge the critical role of monitoring in pinpointing performance bottlenecks, detecting errors, and maintaining the overall well-being of your Symfony application.

**Monitoring Tools:**
Opt for and set up a monitoring tool such as New Relic. Refer to the tool's documentation for guidance on installing and configuring it seamlessly within your Symfony application.

**Issue Management:**
Establish alert mechanisms within the monitoring tool to promptly receive notifications for specific events, such as elevated response times or heightened error rates. Configure automated actions or notifications to the development team, fostering a proactive approach to issue resolution.

---
By embracing DevOps practices, Symfony developers can greatly improve the efficiency, reliability, and scalability of their projects through continuous integration, well-defined deployment strategies, and robust monitoring. Symfony continues to lead in the evolving DevOps landscape, providing a strong foundation for developing and deploying modern, high-performance web applications. 🧠​👩‍💻​