teleren/devto huggingface dataset:
How to install and configure Xdebug in linux
Tags: php, beginners, linux
Published: 2024-01-31 21:14:45

`Xdebug` is an **extension** for PHP and provides a variety of features to improve the PHP development experience.

### Installation

Installing `Xdebug` with a package manager is usually the quickest way. Depending on your distribution, run the following command

**Ubuntu** (18.04 LTS/Bionic, 20.04 LTS/Focal):

```plaintext
sudo apt-get install php-xdebug
```

**Ubuntu** ([Ondřej Surý's PPA](https://launchpad.net/~ondrej/+archive/ubuntu/php/+sourcepub/13437320/+listing-archive-extra)):

```plaintext
sudo apt-get install php(version)-xdebug
```

For other linux distributions [here](https://xdebug.org/docs/install#linux).

### Installing with PECL

You can install `Xdebug` via `PECL` on Linux with Homebrew.

Prerequisites:

* `GCC` and associated libraries.
    
* `PHP` development headers.
    

Run:

```plaintext
pecl install xdebug
```

### Configuring

First we have to find the `xdebug` configuration file, on linux it is **located** in the following path:

```plaintext
cd /etc/php/your_php_version/mods-available
```

In this directory you will find `xdebug.ini`, the `xdebug`**configuration file** and open the file with a code editor.

```plaintext
sudo your_editor xdebug.ini
```

Enter the following settings:

```plaintext
zend_extension=xdebug.so
xdebug.mode=debug,develop
xdebug.start_with_request=yes
xdebug.client_port=8000
xdebug.client_host=127.0.0.1
xdebug.cli_color=1
xdebug.show_local_vars=1
```

In `xdebug.client_port` enter the port you use in your applications.

Let's check that `xdebug` has been installed and is working. To do this, use the following php code:

```php
phpinfo();
```

In the php info you should find an xdebug section.

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


### Solving a problem


In the image above, it shows that our `xdebug` has the **Development Helpers** and **Step Debugger** modes active, but if in a given project we want to activate or deactivate any mode without touching the main `xdebug file`.

To make this possible, we'll use the `XDEBUG_MODE` environment variable, as in the example below:

```bash
XDEBUG_MODE=coverage php -S 127.0.0.1:8000
```

If we check again in the xdebug section we will only have **coverage** mode enabled

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

[Here](https://xdebug.org/docs/all_settings#mode) are the instructions for the other modes and all the possible `xdebug` **configurations**.

This concludes our guide to installing and configuring xdebug on linux.

**Don't forget to add a reaction if the post has helped.**
Highlight job ads posted by job agent in LinkedIn Jobs
Tags: javascript
Published: 2024-01-31 20:54:18

## Notice

I wrote this article and was originally published on [Qiita](https://qiita.com/saladlam/items/f97e41f9339d97ce7c9d) on 31 August 2021.

---

# Reason to write this
When I look up jobs in "LinkedIn Jobs", I found that there are so much ads posted by job agent. I used so much time every day to filter out these ads. Therefore I wrote this code.
This code is written by pure JavaScript and no 3rd library is used. I tried it on Google Chrome only and it seens that can work on other browser.

# How to use the code
1. fill your agent list into variable "agentList"

```javascript
let agentList = [
  "ADD YOUR LIST INTO HERE"
];

function highlightAgent() {
  document.querySelectorAll("a[data-control-name='job_card_company_link']").forEach(function(currentValue) {
    let name = currentValue.text.trim();
    let agentName = agentList.find(function(input) {return input === name});
    if (agentName !== undefined) {
      currentValue.style.backgroundColor = "#FF0000";
    }
  });
}

window.setInterval(highlightAgent, 5000);
```

2. paste the code into "Console" of "DevTools" (assume that you are using Google Chrome). The highlight function will be run in every 5 seconds, so you can see result at most 5 seconds after you press next page. 

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

It is in active when you press next page, unless you press "reload" of browser.
== operator for object in Java
Tags: java
Published: 2024-01-31 20:50:01

## Notice

I wrote this article and was originally published on [Qiita](https://qiita.com/saladlam/items/c867416f9b0db83b5e1d) on 31 August 2021.

---

In past I don't understand why code in inner block doesn't run.

```Java
if (new Integer(1) == new Integer(1)) {
  doImportantJob();
};
```

Since "==" operator for object means if both objects point to the same memory location. The code above means two Integer(1) object is created, of course two sides must point to different memory location.
How To Host Wordpress Sites for Free on AWS EC2 in 5 Easy Steps
Tags: wordpress, hosting, webdev, tutorial
Published: 2024-01-31 20:46:41

## Dreaming of launching your WordPress site without breaking the bank? Look no further than Amazon Web Services (AWS) EC2! This powerful platform offers a free tier that's perfect for hosting your WordPress site, empowering you to create a dynamic online presence without upfront costs. Ready to dive in? Here's a 5-step roadmap to guide you through the process:


Step 1. Laying the Foundation: Dependencies and Server Setup

- Begin by installing the essential software components, including PHP, MySQL, and Nginx. These tools work together to power your WordPress site.

- Optimize MySQL for memory efficiency to ensure smooth performance.

Step 2. Creating a Database Home for Your Content

- Establish a MySQL database to store all your WordPress content, from posts and pages to media files.

- Assign a dedicated user with secure credentials to manage database interactions.

Step 3. Fine-tuning PHP for WordPress Harmony

- Configure PHP settings to align perfectly with WordPress requirements, ensuring optimal functionality and resource usage.

- Adjust parameters like upload limits, memory allocation, and execution time to suit your website's needs.

Step 4. Welcoming WordPress to Your Server

- Download the latest WordPress files and extract them to the designated directory within your server.

- Grant appropriate permissions to ensure seamless website operations.

Step 5. Empowering Nginx to Serve Your Content

- Configure Nginx, a high-performance web server, to handle incoming requests and deliver your WordPress content to visitors.

- Set up domain names, access logs, and error handling for a comprehensive web experience.

Bonus Step: Securing Your Site with HTTPS

- Install Certbot to obtain a free SSL/TLS certificate, enabling secure HTTPS connections and safeguarding user data.

- Verify automatic certificate renewal to maintain website security effortlessly.

And to make things even easier, here's a video tutorial that explains the process in more detail.

{% embed https://youtu.be/Sy8zN318dv4?sub_confirmation=1 %}
== operator for String object in Java
Tags: java
Published: 2024-01-31 20:45:08

## Notice

I wrote this article and was originally published on [Qiita](https://qiita.com/saladlam/items/4ff1c56607db19acf986) on 31 August 2021.

---

First please read [this](https://dev.to/saladlam/-operator-for-object-in-java-581a) if you don't sure how to use == operator for object.

# Example from The Java® Language Specification

Got from [here](https://docs.oracle.com/javase/specs/jls/se8/html/jls-3.html#jls-3.10.5).

```Java
package testPackage;
class Test {
    public static void main(String[] args) {
        String hello = "Hello", lo = "lo";
        System.out.print((hello == "Hello") + " ");  // (1)
        System.out.print((Other.hello == hello) + " ");  // (2)
        System.out.print((other.Other.hello == hello) + " ");  // (3)
        System.out.print((hello == ("Hel"+"lo")) + " ");  // (4)
        System.out.print((hello == ("Hel"+lo)) + " ");  // (5)
        System.out.println(hello == ("Hel"+lo).intern());  // (6)
    }
}
class Other { static String hello = "Hello"; }
```

```Java
package other;
public class Other { public static String hello = "Hello"; }
```

The output is

```
true true true true false true
```

# Things you need to know about String class

1. String object is immutable
2. A pool of strings, initially empty, is maintained privately by the class String. You may use [intern()](https://docs.oracle.com/javase/8/docs/api/java/lang/String.html#intern--) for looking up reference (Output of (6))
3. All String constants will refer to the same String instance if the values are the same during compile time, no matter what package is in. And a reference will be stored in pool stated in point 2 (Output of (1), (2), (3), (4))
4. New String object will be created during runtime (Output of (5))

# Suggestion

**Don't** use == operator for checking if value of two String objects are equal. Please use [equals()](https://docs.oracle.com/javase/8/docs/api/java/lang/String.html#equals-java.lang.Object-) instead.
Passing object as parameter into function
Tags: java
Published: 2024-01-31 20:39:00

## Notice

I wrote this article and was originally published on [Qiita](https://qiita.com/saladlam/items/4759cb6ff0bb4b4d0abc) on 1 September 2021.

---

Please read following code.

```Java
public class Test {

	public static void main(String[] args) {
		// Integer reference called "clz"
		Integer clz = new Integer(1);
		changeValue(clz);
		System.out.println("After called changeValue(): " + clz.toString());
	}

	public static void changeValue(Integer input) {
		System.out.println("Start changeValue(): " + input);
		input = new Integer(2);
		System.out.println("Finish changeValue(): " + input);
	}

}
```

The output is

```
Start changeValue(): 1
Finish changeValue(): 2
After called changeValue(): 1
```

# Finding

1. Changing the value of reference (ie create a new object) inside a function will not affect the original value of reference passed into
2. Before function is executed in JVM, value of reference "clz" **copy** to stack memory space "input". During execution, the change is on that stack memory space and after function is executed value of stack memory space **will not** copy back to original

# Reference

1. [Passing String as parameter to a method](https://ibytecode.com/blog/passing-string-as-parameter-to-a-method/)
Default Servlet filter loaded by Spring Boot
Tags: spring, springsecurity, springboot
Published: 2024-01-31 20:37:09

## Notice

I wrote this article and was originally published on [Qiita](https://qiita.com/saladlam/items/0b3c47a6034bffb5e69f) on 4 September 2021.

---

# What is servlet filter

You can get the answer from [here](https://docs.oracle.com/cd/B14504_01/dl/web/B10321_01/filters.htm).

# How Spring Boot creates and loads filter

First creates bean which implements *javax.servlet.Filter* interface (Normally filter bean is extended from *org.springframework.web.filter.GenericFilterBean* class). Below is an example

```java
public class HttpEncodingAutoConfiguration {
	//...

	@Bean
	@ConditionalOnMissingBean
	public CharacterEncodingFilter characterEncodingFilter() {
		CharacterEncodingFilter filter = new OrderedCharacterEncodingFilter();
		filter.setEncoding(this.properties.getCharset().name());
		filter.setForceRequestEncoding(this.properties.shouldForce(Type.REQUEST));
		filter.setForceResponseEncoding(this.properties.shouldForce(Type.RESPONSE));
		return filter;
	}

	// ...
}
```  

Then during Servlet registrate to servlet container (Servlet class is *org.springframework.web.servlet.DispatcherServlet*), beans created above will be collected and registered at

```Java
public class ServletContextInitializerBeans extends AbstractCollection<ServletContextInitializer> {
	// ...

	@SuppressWarnings("unchecked")
	protected void addAdaptableBeans(ListableBeanFactory beanFactory) {
		MultipartConfigElement multipartConfig = getMultipartConfig(beanFactory);
		addAsRegistrationBean(beanFactory, Servlet.class, new ServletRegistrationBeanAdapter(multipartConfig));
		// *** HERE ***
		addAsRegistrationBean(beanFactory, Filter.class, new FilterRegistrationBeanAdapter());
		for (Class<?> listenerType : ServletListenerRegistrationBean.getSupportedTypes()) {
			addAsRegistrationBean(beanFactory, EventListener.class, (Class<EventListener>) listenerType,
					new ServletListenerRegistrationBeanAdapter());
		}
	}

	// ...
}
```

# Filter registered by default

| Filter | Function |
| --- | --- |
| org.springframework.security.web.FilterChainProxy | Used by Spring Security. It holds many sub-filter for performing security policy |
| org.springframework.boot.web.servlet.filter.OrderedRequestContextFilter | Exposes the request object to the current thread|
| org.springframework.boot.web.servlet.filter.OrderedHiddenHttpMethodFilter | Converts posted method parameters into HTTP methods |
| org.springframework.boot.web.servlet.filter.OrderedFormContentFilter | Parses form data for HTTP PUT, PATCH, and DELETE requests and exposes it as Servlet request parameters. By default the Servlet spec only requires this for HTTP POST |
| org.springframework.boot.web.servlet.filter.OrderedCharacterEncodingFilter | apply default character encoding for request if not specify in request |
Basic operation of NIO Buffer classes
Tags: java
Published: 2024-01-31 20:32:48

## Notice

I wrote this article and was originally published on [Qiita](https://qiita.com/saladlam/items/5e3e3c708c8c23752203) on 14 September 2021.

---

There are 4 internal indicators (capacity, limit, position, remaining) in Buffer classes, example below shows the change of these indicators.

```java
import java.nio.Buffer;
import java.nio.ByteBuffer;

public class BufferTest {

	public static void main(String[] args) {
		ByteBuffer buf = ByteBuffer.allocate(8);
		System.out.println("[new buf]");
		printBufferInfo(buf);

		buf.put((byte) 1).put((byte) 2).put((byte) 3);
		System.out.println("[put 3 elements]");
		printBufferInfo(buf);

		for (int i = 0; i < buf.position(); i++)
			System.out.println(buf.get(i));
		System.out.println("[get 3 elements by index]");
		printBufferInfo(buf);

		buf.flip();
		System.out.println("[flip]");
		printBufferInfo(buf);

		for (int i = 0; i < 2; i++)
			System.out.println(buf.get());
		System.out.println("[get 2 elements]");
		printBufferInfo(buf);

		buf.compact();
		System.out.println("[compat]");
		printBufferInfo(buf);

		buf.put((byte) 4);
		System.out.println("[put 1 element]");
		printBufferInfo(buf);

		buf.clear();
		System.out.println("[clear]");
		printBufferInfo(buf);
	}

	public static void printBufferInfo(Buffer buf) {
		System.out.println("Capacity: " + buf.capacity());
		System.out.println("Limit: " + buf.limit());
		System.out.println("Position: " + buf.position());
		System.out.println("Remaining: " + buf.remaining());
	}

}
```

The output is

```
[new buf]
Capacity: 8
Limit: 8
Position: 0
Remaining: 8
[put 3 elements]
Capacity: 8
Limit: 8
Position: 3
Remaining: 5
1
2
3
[get 3 elements by index]
Capacity: 8
Limit: 8
Position: 3
Remaining: 5
[flip]
Capacity: 8
Limit: 3
Position: 0
Remaining: 3
1
2
[get 2 elements]
Capacity: 8
Limit: 3
Position: 2
Remaining: 1
[compat]
Capacity: 8
Limit: 8
Position: 1
Remaining: 7
[put 1 element]
Capacity: 8
Limit: 8
Position: 2
Remaining: 6
[clear]
Capacity: 8
Limit: 8
Position: 0
Remaining: 8

```
🚀 Mastering Node.js in 10 Easy Steps 🌐
Published: 2024-01-31 20:25:59



Are you ready to dive into the world of backend development with Node.js? Whether you're a beginner or brushing up your skills, these 10 steps will guide you through the essentials of Node.js. Let's get coding!

**1️⃣ Install Node.js:** Download and install Node.js from nodejs.org. Choose the version that suits your development needs.

**2️⃣ Understand npm:** npm (Node Package Manager) is your toolkit for managing packages. Learn to install, update, and manage dependencies with npm.

**3️⃣ Create Your First Node.js Application:** Start with a simple "I Love Pakistan" application. Initialize a new project with npm init and create your first JavaScript file.

**4️⃣ Explore Node.js Modules:** Node.js modules are reusable code blocks. Understand built-in modules like HTTP, Path, and FS, and how to import them using require().

**5️⃣ Asynchronous Programming:** Grasp the concept of asynchronous programming in Node.js, especially callbacks, promises, and async/await.

**6️⃣ Build a Basic Server:** Use the HTTP module to build your first server. Learn to handle requests and responses.

**7️⃣ Work With Express.js:** Express.js is a popular Node.js framework. Set up an Express server and explore routing, middleware, and more.

**8️⃣ Connect to a Database:** Learn to connect your Node.js application to a database like MongoDB or MySQL for data storage.

**9️⃣ Unit Testing:** Write unit tests for your application. Familiarize yourself with testing frameworks like Mocha and Chai.

**🔟 Deploy Your Application:** Learn about deployment options. Deploy your application on platforms like Heroku or AWS.

🔗 Stay Consistent and Keep Learning: Node.js is vast and constantly evolving. Keep experimenting and building new projects.

🌟 #NodeJsJourney #BackendDevelopment #JavaScript #WebDevelopment #Programming #TechCommunity

Feel free to connect and share your Node.js experiences and projects! Let's grow together in this exciting journey of backend development.
Github: [Hadiraza04](https://github.com/hadiraza04)
Risk of user password recovery in leaked application database
Tags: security
Published: 2024-01-31 20:23:02

## Notice

I wrote this article and was originally published on [Qiita](https://qiita.com/saladlam/items/92cf4731f4c5db4240ac) on 23 August 2022.

---

# Introduction

One of the application design practices is, user passwords should not be stored into a database directly. A better way is to hash the password by hash function (e.g. sha1) and store the password hash.

# Potential vulnerability

Below is a sha1 hash. Do you know the original value?

```
21bd12dc183f740ee76f27b78eb39c8ad972a757
```

I thought it was impossible to recover the original value because the hash function is a one way function. But I am **PARTLY** wrong.

There are some hash lookup websites, which store the hash value of commonly used passwords plus word lookup from a dictionary. When I lookup hash above in one of these websites, I got

```
P@ssw0rd
```

This is a commonly used password, used in training material of Microsoft product. When the database of an application is leaked, hackers can use this way (called dictionary lookup) to recover the password of an account using a weak password. Still there is no way to restore strong password.

# Improvement

Try to append a string which is not related to user information to the password before passing to the hash function. But it is useless if the source code of the system is leaked also.
Common Serverless Runtime Limits
Tags: serverless, webdev, programming, devops
Published: 2024-01-31 20:13:32

When does Coherence get useful instead of purely serverless functions, like those offered on Vercel/Netlify/CloudFlare? There are a few reasons why you might hit limits and need to go beyond their hosting, especially for backend APIs.

One set of limits is execution time limit on functions:

- e.g 10 seconds on free on Vercel, 10 seconds on Netlify
- You can pay to increase this on some platforms, for example the paid tier on Vercel is 60 seconds. This is still not enough for many real-world use cases, especially if you talk to 3rd party APIs from your code.

Another set of limits is the package, request size, or memory limit:

- 50 MB total deployment size limit on Vercel serverless
- 1024 MB memory limit on Vercel or Netlify serverless
- 4.5 MB max request body size

In addition to serverless functions, some platforms like Vercel also offer edge functions. These have their own limits.

- Edge functions are even more limited, e.g. 30s max timeout for all plans or 4 MB size limit even for enterprise plans. There are some caveats here such as that streaming responses can consume more time as long as they are actively sending data back to the client.

There are additional limits that apply to some applications, for example:

- No outbound TCP connections, e.g. to redis. There are workarounds here, such as using a HTTP wrapped API via a provider like Upstash, but these mean that you're locked into a vendor's ecosystem instead of the open standard software itself.
- No ability to connect to database resources in a VPC, must use public IP and open your database up to the internet. In addition to security risks, this is a performance bottleneck and a cost drawback

[Coherence](https://www.withcoherence.com/) has no limits aside from the underlying limits on Cloud Run (GCP) or Fargate (AWS). With Coherence, you can easily deploy an application to your own AWS or GCP account using a container and remove the limits on slug/package size, memory, and execution time right away. You’ll still get the developer experience of branch previews and an intuitive UI that Vercel provides. These features might be useful for your application, for example if you are doing long-running jobs that process data or talk to external APIs where you don’t control the response speed. You might also want to use:

- A database instance or redis instance in your VPC on the cloud provider, for example postgres or mysql
- Separate worker tiers running with different machine types, for example using libraries like celery, sidekiq, or bee-queue
- CI/CD with database migrations or seeding built in, similar to what Jenkins, Drone, CircleCI, gitlab CI, or GitHub Actions might provide
- A Cloud IDE based on VSCode to develop your project, similar to what GitPod or GitHub Codespaces might be used for

Feel free to reach out [zach@withcoherence.com](zach@withcoherence.com) with any questions if we can help you get started!
Chào mừng đến với Nến thơm Manifest - cửa hàng nến thơm!
Published: 2024-01-31 19:57:36

Chúng tôi là một cửa hàng chuyên cung cấp các sản phẩm liên quan đến nến thơm, tinh dầu, sáp thơm,...cùng nhiều sản phẩm liên quan khác. Với nhiều năm kinh nghiệm trong ngành, chúng tôi cam kết mang đến cho khách hàng những sản phẩm chất lượng cao và dịch vụ tốt nhất.

Hãy đến và ghé thăm cửa hàng nến thơm của chúng tôi để khám phá các sản phẩm chất lượng và tìm kiếm những dịch vụ tốt nhất đến từ cửa hàng chúng tôi. Chúng tôi rất mong được phục vụ bạn!
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/77ixvegicyz7r8msyqbq.jpg)
Creates Spring Boot application runs in Java Servlet container
Tags: java, springboot
Published: 2024-01-31 19:36:39

## Notice

I wrote this article and was originally published on [Qiita](https://qiita.com/saladlam/items/487a403029d1fed0e21e) on 23 August 2022.

---

# On Servlet 3.0 container

If you plan to run your project on Servlet 3.0 container (e.g. Apache Tomcat start from 7.0), it is very easy to convert the project from run in command line to run in a Servlet container.
1. in software project management tool, change generate file format from jar to war, and prevent to append version number to file name
1. include **org.springframework.boot:spring-boot-starter-tomcat** into project's dependency
1. change the class which annotated with @SpringBootApplication, to extend **org.springframework.boot.web.servlet.support.SpringBootServletInitializer**

That's all!

# Reference
1. [Deploy a Spring Boot WAR into a Tomcat Server](https://www.baeldung.com/spring-boot-war-tomcat-deploy)