teleren/devto huggingface dataset:
Combine Two Tables | LeetCode | MSSQL
Tags: leetcode, computerscience, codenewbie, mssql
Published: 2023-05-10 11:50:33

## The Problem

Consider the following tables: Person and Address. 

#### Table: Person

| Column Name | Type    |
|-------------|---------|
| personId    | int     |
| lastName    | varchar |
| firstName   | varchar |

personId is the primary key column for this table. This table contains information about the ID of some persons and their first and last names.

#### Table: Address

| Column Name | Type    |
|-------------|---------|
| addressId   | int     |
| personId    | int     |
| city        | varchar |
| state       | varchar |

addressId is the primary key column for this table. Each row of this table contains information about the city and state of one person with ID = personId.

The task is to write an SQL query to report the first name, last name, city, and state of each person in the Person table. If the address of a personId is not present in the Address table, report null instead.

The result table can be returned in any order.

## The Solution

To solve this problem, we can use a **LEFT JOIN** SQL operation. The LEFT JOIN keyword returns all records from the left table (Person), and the matched records from the right table (Address). The result is NULL from the right side, if there is no match.

This is especially effective in this case because we want to report all people regardless of whether their address is available or not. This makes our solution cost-effective in terms of performance, as we don't have to perform separate queries or complex subqueries.

### The Code

Here's the MSSQL query that achieves this:

```sql
SELECT p.firstName, p.lastName, a.city, a.state
FROM Person p LEFT JOIN Address a ON p.personId = a.personId
```

This query selects firstName, lastName from the Person table and city, state from the Address table. The LEFT JOIN ensures that every personId from the Person table appears in the result, regardless of whether it appears in the Address table or not.

In the case where a personId from the Person table doesn't have a matching entry in the Address table, the city and state fields are reported as NULL.

The result will be a comprehensive list of all persons along with their respective addresses (if available).

![my results](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pv4iccvhvpgtr4y9ijgw.png)

[Original Source](https://leetcode.com/problems/combine-two-tables/)

For more insightful solutions and tech-related content, feel free to connect with me on my [Beacons page](https://beacons.ai/ranggakd).

{% embed https://beacons.ai/ranggakd %}
The Benefits of Working Remotely for Senior Software Engineers at letsremotify
Published: 2023-05-10 11:44:34

Working from home has become a popular work option for many freelancers, particularly in the technology industry. With the rise of remote work and the increasing number of companies offering remote positions, it has never been easier for freelancers to work from home. In this blog post, we will discuss the top benefits of working from home for freelancers on LetsRemotify.

Flexibility
One of the most significant benefits of working from home is the flexibility it provides. Freelancers can work at any time of day and from any location. This means that they can work around their personal schedules and have the freedom to work from wherever they feel most comfortable.

Increased Productivity
Studies have shown that people who work from home are more productive than those who work in a traditional office setting. Working from home eliminates distractions such as office gossip and interruptions from coworkers. Freelancers are able to focus on their work and complete tasks more efficiently.

Reduced Commuting Time and Cost
Commuting to and from work can be time-consuming and expensive. By working from home, freelancers eliminate the need to commute, which can save them a significant amount of time and money. This also reduces the amount of stress associated with commuting, which can have a positive impact on their mental health and well-being.

Improved Work-Life Balance
Working from home can help freelancers achieve a better work-life balance. With the flexibility to work at any time of day, freelancers can schedule work around their personal lives. This allows them to spend more time with their families and pursue hobbies and interests outside of work.

Reduced Stress and Improved Health
Working from home can help reduce stress and improve overall health. Without the stress associated with commuting and the distractions of a traditional office, freelancers can focus on their work and complete tasks more efficiently. This can lead to a greater sense of accomplishment and reduce stress levels.

In conclusion, working from home offers numerous benefits for freelancers on LetsRemotify. From increased flexibility to improved productivity and work-life balance, freelancers can enjoy a more fulfilling work experience. By taking advantage of the benefits of working from home, freelancers can enjoy a more balanced and fulfilling life both inside and outside of work.
How I can display the numeric value of the day of week into Greek?
Tags: help, postgres
Published: 2023-05-10 11:44:30

I need some help upon representing a value ranging from 0...6 as week day (0 - Sunday, ... 6 - Saturday)

I try to represent a work schedule like this:
https://dba.stackexchange.com/q/326955/118215

And I want the day of week to be represented as Greek Localized text. Any Idea how?
Machine Learning
Tags: machinelearning, datascience, ai, deeplearning
Published: 2023-05-10 11:21:24

In this day and age there are booming buzz words in the tech sphere. Some being Artificial Intelligence, machine learning and deep learning.

What do these words mean? We'll cover them in a few but we'll put our focus majorly in **machine learning**.

## Artificial Intelligence

According to a research paper by John McCarthy artificial intelligence is the science and engineering of making intelligent machines, especially intelligent computer programs. It is related to the similar task of using computers to understand human intelligence, but AI does not have to confine itself to methods that are biologically observable.

Turing on the other hand, provided a set of tests that an artificially intelligent computer has to pass.

Generally AI focuses on the simulation of human intelligence in computers/machines.

## Machine Learning
It is a subset of artificial intelligence (AI) in which algorithms are developed and trained on a dataset from which they make predictions or decisions based on the in fed data.
This means that computers learn from data rather than being programmed.

There are three types of machine learning algorithms.
- Supervised Learning
- Unsupervised Learning
- Reinforcement Learning

> a. **Supervised Learning**
The algorithms are trained with labeled datasets. This means that the training data has both the input features and the expected output. 
It pretty similar to when you teach a class by also providing them answers for the test so that they can gauge their understanding.
Thus the algorithm learns to recognize patterns to make predictions/decisions about new, unlabeled data.
Some of the common supervised algorithms are:

>> - linear regression
>> - logistic regression
>> - random forest
>> - support vector machine(svm)

> b. **Unsupervised Learning**
The algorithm is trained on unlabeled data. This means that the algorithm has to recognize patterns in the data and then group similar data together.

Some common algorithms used in unsupervised machine learning are:
>> - neural networks
>> - k-means clustering
>> - probabilistic clustering methods

> c. **Reinforcement Learning**
The algorithm learns to make decisions by interacting with an environment and receiving feedback in the form of reward or penalties. The algorithms strives to maximize rewards while reducing penalties. 

An example of a reinforcement learning algorithm is a robot to pick items. It holds items and attempts to lift them. If the item falls the robots via trial and error adjusts various features such as holding more tightly or looking for a more suitable place to hold the item. Over time it learns the best way to pick up the item and now significantly does so effortlessly.

## Applications of Machine Learning
- self driving cars
- speech recognition
- computer vision
- recommendation engines
- fraud detection

Machine learning is an essential tool in data science. We'll explore these algorithms as we progress.
Create a movie card using Tailwind CSS and one code
Tags: webdev, tailwindcss, css, coding
Published: 2023-05-10 11:08:21

**To create a movie card post using Tailwind CSS CDN and one code, you can follow the steps below:**


**1.**First, you need to link the Tailwind CSS CDN to your HTML file. You can do this by adding the following code to the head section of your HTML file:

```
<!doctype html>
<html>
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="bg-slate-700">
</body>
</html>
```

**2.**Inside this code in body, you can create a movie card using the following code:
```
<div class="m-4 mb-8 w-auto px-4 mx-auto sm:w-1/2 md:w-1/3 lg:w-1/4">
  <div class="rounded-lg bg-white shadow-lg">
    <img src="https://source.unsplash.com/400x500/?dark" alt="movie poster" class="rounded-t-lg" />
    <div class="p-4">
      <h2 class="mb-2 text-lg font-semibold">Movie Title</h2>
      <p class="mb-2 text-sm text-gray-700">Release Date: January 1, 2023</p>
      <p class="mb-4 text-sm text-gray-700">Director: John Doe</p>
      <a href="#" class="block rounded-lg bg-blue-500 px-4 py-2 text-center font-semibold text-white hover:bg-blue-600">Watch Movie</a>
    </div>
  </div>
</div>
```

**3.**Replace the image with the movie poster and update the movie title, release date, director, and trailer link as necessary.

```
<!doctype html>
<html>
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="bg-slate-700">
<div class="m-4 mb-8 w-auto px-4 mx-auto sm:w-1/2 md:w-1/3 lg:w-1/4">
  <div class="rounded-lg bg-white shadow-lg">
    <img src="https://source.unsplash.com/400x500/?dark" alt="movie poster" class="rounded-t-lg" />
    <div class="p-4">
      <h2 class="mb-2 text-lg font-semibold">Movie Title</h2>
      <p class="mb-2 text-sm text-gray-700">Release Date: January 1, 2023</p>
      <p class="mb-4 text-sm text-gray-700">Director: John Doe</p>
      <a href="#" class="block rounded-lg bg-blue-500 px-4 py-2 text-center font-semibold text-white hover:bg-blue-600">Watch Movie</a>
    </div>
  </div>
</div>
</body>
</html>
```

**4.**Finally, you can customize the movie card's appearance by adjusting the classes used in the HTML code. The classes used in this example are from Tailwind CSS and provide a responsive layout, rounded corners, drop shadows, and color styles.

**That's it! You now have a movie card post created using Tailwind CSS CDN and one code.**
Hiring | Junior Backend Web Developer
Tags: hiring, backend, web3, webdev
Published: 2023-05-10 11:06:48

We are seeking a Junior Backend Web Developer to join our dynamic development team. The ideal candidate should be highly skilled in backend web development, able to work collaboratively with our senior developer and contribute to the development of web applications. Previous work experience is not as important as the candidate's ability to build something from scratch.

### Key Responsibilities:

- Design and develop backend systems for web applications
- Build and maintain APIs for web applications
- Collaborate with front-end developers to integrate user-facing features with server-side logic
- Write clean and maintainable code
- Develop and maintain database schemas and data models
- Debug and troubleshoot production issues
- Ensure high performance, scalability, and security of web applications
- Stay up-to-date with the latest web development trends and technologies
- Write technical documentation for code and APIs

### Requirements:

- At least 1-2 years of experience in backend web development
- Strong experience in at least one of the popular backend programming languages like Typescript, Python, Java or Golang
- Familiarity with NoSQL databases
- Experience building and maintaining APIs
- Familiarity with cloud-based infrastructure like AWS or Azure
- Excellent problem-solving skills
- Ability to work in a team environment
- Good communication skills

If you are passionate about backend web development and have a proven track record of building scalable and reliable systems, we encourage you to apply for this exciting opportunity — please share your resume with your GitHub link to hi@furrend.xyz. 

---

### About Furrend

Furrend is the next-gen web3 consumer app built for 10 billion pet lovers. We are a team of world-class builders from leading blockchain projects, top-tier tech companies, and the most prestigious banking firms with expertise across blockchain engineering, smart contract development, consumer product, SaaS, and more.

For more info, please visit [https://furrend.xyz](https://furrend.xyz/)/ or check out [https://twitter.com/hifurrend](https://twitter.com/hifurrend) on Twitter.
Managing different scripts in separate pages while using barba.js
Tags: webdev, javascript, barbajs
Published: 2023-05-10 10:58:48

Those who don't know about [barba.js](https://barba.js.org/docs/getstarted/intro/), **Barba.js** is a small (7kb minified and compressed) and easy-to-use library that helps you create fluid and smooth transitions between your website’s pages. It makes your website run like a SPA (Single Page Application) and help reduce the delay between your pages, minimize browser HTTP requests and enhance your user’s web experience.

I am using barba.js for this website [Visit Suruga](https://www.visit-suruga.com/) and it is performing really well. You can visit the website and check how the smooth transitions are working.

But everything isn't perfect. Same goes for barba.js.

Lets see how barba.js works:

Barba.js follows a specific DOM structure.
```
<body data-barba="wrapper">
  <!-- put here content that will not change
  between your pages, like <header> or <nav> -->

  <main data-barba="container" data-barba-namespace="home">
    <!-- put here the content you wish to change
    between your pages, like your main content <h1> or <p> -->
  </main>

  <!-- put here content that will not change
  between your pages, like <footer> -->
</body>
```
Barba.js will only update the contents which are inside the `data-barba="container"`. Other parts of this DOM will remain the same what we had during the page load.

For this feature we have to load all the scripts, styles, libraries during the page load. Even if that page isn't using those style or script, which eventually make the initial page loading a bit slower.

Normally almost all pages has the same style and scripts needed. But there are few pages which requires extra libraries or styles. If we don't load those libraries the functionality will not work on those pages.

To fix this issue we took the advantage of the `data-barba-namespace` attribute. Normally it is used for Transition rules and Views.

So we set the page name `spot` in the `data-barba-namespace` value in that page. And we also did added the library scripts in the bottom of the page (If we load the page first time). And after that based on the namespace value we added the same script inside barba hook.

```
barba.hooks.enter((data) => {
   if (data.next.namespace === 'spot') {
     // Initialize library
   } 
});
```

By doing this even if we go to the `spot` page after transition from another page the library will be initialized in the page. So there will be no more error and the initial loading time of the index page will be reduced.

That's all for today. Thank you for reading!
Code Documentation
Tags: php, laravel, documentation, webdev
Published: 2023-05-10 10:55:20

A DocBlock explains the purpose of a specific class, method, or other structural component. DocComments are a specific form of comment that always enclose DocBlocks. A DocComment is denoted by the characters `/** (opener)` and `*/ (closer)`.
There should be an asterisk (*) at the beginning of every line between the DocComment opener and its closer.

The phpdoc command can be used with phpDocumentor to provide comprehensive documentation for your Laravel project.

How effectively is your source code documented?


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m5cauek3n8p2hzm5y2yo.png)
PHP: types of data
Tags: php, beginners, webdev
Published: 2023-05-10 10:53:22

A variety of data types can be assigned to a variable in PHP(and beyond), ranging from simple strings and numbers to more complex data types such as arrays and objects. The PHP language offers support for eight primitive data types: Integer, Floating-point numbers, Strings, Booleans, Arrays, Objects, NULL; each of these data types is used to construct variables.
Let us now look in detail at the individual data types:

**Integer**
Integers are numbers without decimal points(Ex. 0, 1, 2, -1, -2, -3), and can be specified in:

1. Decimal notation (base 10)

2. Hexadecimal notation (base 16 with, prefixed with 0x)

3. Octal notation (base 8, with prefix 0)

Numbers may optionally be preceded by the - or + sign.

**Strings**
Strings are nothing more than a sequence of characters, where each is equivalent to one byte. A string can be up to 2GB in size, and can contain letters, numbers, and special characters. The simplest way to specify a string is to enclose it in single quotation marks ('Hello world!'), however, double quotation marks can also be used ("Hello world!").

**Floating Point Numbers**
I numeri in virgola mobile sono numeri frazionari o decimali, come quelli mostrati di seguito:

$x = 1.456

$y = 10.2e3

$z = 4E-10  

**Booleans**
Booleans can represent only two types of values: 1(true) or 0(false).

**Array**
An array is a type of variable that can hold more than one value at a time, and is used to aggregate a set of related items such as, for example, a set of city or country names. Formally, an array is defined as an indexed data collection of values; each index (known as a key), uniquely represents the value it refers to.

**Objects**
A more complex type of data is objects. These allow not only the storage of data, but also contain information on how to process it. Each object is a specific instance of a class that serves as a model for it; objects are created precisely according to this model, using the keyword _new_. It is important to know that each object has properties and methods that correspond to those of its parent class: each instance is independent, with its own properties and methods, and can therefore be manipulated independently of other objects of the same class.

**Null**
The special value NULL is used to represent empty variables in the PHP language. A variable of this type is a variable with no data.
Spring Security role based Authentication & Authorization Implementation with Spring Boot 3.0
Tags: webdev, programming, api, java
Published: 2023-05-10 10:30:15


Hello learners, here we are going to know about spring security implementation with spring boot. Spring security provides authentication, authorization, and protection against common attacks.


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


**Authentication** - Authentication is how we verify the identity of the user trying to access a particular resource, once authentication is performed we know the identity and can perform authorization.
**Authorization** - Authorization means giving permission to access particular resource/url.

**Steps to Implement Spring Security**

Step 1: Add Spring Security dependency in POM.XML

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


Step 2: Create a configuration class , add authentication and authorization methods.

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


**@EnableWebSecurity** provides default security configuration to our application.Default security activates both HTTP security filters and the security filter chain and applies basic authentication to our endpoints.

**@Configuration** tells Spring Boot to scan the class for bean definitions and register them with the application context.

authenticateProvider() method is used to store all the user deatils like username, password, roles.Spring Security contains DaoAuthenticationProvider class which contains userDetailsService and passwordEncoder.passwordEncoder() is used to encrypt the password and encrypted password is stored in DB.

SecutityFilterChain() method is to authorize the resources, here
.requestMatchers("/products/welcome","/products/new").permitAll() is to give access to all the users, any user can access those two urls.
requestMatchers("/products/**").authenticated() is to give access to authenticated users.

Step 3: Implement role based authorization

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


**@PreAuthorize** annotation is used to specify a expression that will be evaluated before the method is executed. If the expression evaluates to true, the method is executed otherwise, an AccessDeniedException is thrown.

The getAllProducts() method can only be executed by users with the ROLE_USER role, while the getProductById() method can be executed by users with the ROLE_ADMINrole.
Testing the implementation

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


Added the sample code to test the implementation.

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


After giving user credentials user can able to access the user endpoint
When user try to access Admin endpoint with user credential, error page will display

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eq04wsq91q2ozo3ncovf.png)
V𝗮𝗹𝗶𝗱𝗮𝘁ing 𝘂𝘀𝗲𝗿 𝗯𝗲𝗳𝗼𝗿𝗲 𝗮𝗻𝘆 𝗔𝗣𝗜 𝗰𝗮𝗹𝗹 𝘂𝘀𝗶𝗻𝗴 𝗔𝘅𝗶𝗼𝘀 𝗶𝗻𝘁𝗲𝗿𝗰𝗲𝗽𝘁𝗼𝗿𝘀
Tags: react, javascript, frontend, webdev
Published: 2023-05-10 10:22:51

Interceptors are methods that are triggered before the main method

𝗦𝘁𝗲𝗽𝘀

1️⃣ Create Axios instance

let me tell you some benefits of creating an Axios instance

a. if you have multiple API calls, to the same endpoint, you specify baseURL and some headers properties which they in common to avoid
writing the same code multiple times

const instance = axios.create({
baseURL: '',
timeout: 1000,
headers: {'X-Custom-Header': 'foobar'}
});

what else hmmm 🤔 🤔 , let me know if you have some ideas in the comment section

2️⃣ 𝗔𝗱𝗱 𝗶𝗻𝘁𝗲𝗿𝗰𝗲𝗽𝘁𝗼𝗿𝘀 𝘁𝗼 𝗮 𝗰𝘂𝘀𝘁𝗼𝗺 𝗶𝗻𝘀𝘁𝗮𝗻𝗰𝗲 𝗼𝗳 𝗔𝘅𝗶𝗼𝘀

const instance = axios.create();
instance.interceptors.request.use(function () {/*...*/});

🔴 𝗪𝗲 𝗵𝗮𝘃𝗲 𝟮 𝘁𝘆𝗽𝗲𝘀 𝗼𝗳 𝗶𝗻𝘁𝗲𝗿𝗰𝗲𝗽𝘁𝗼𝗿𝘀

1️⃣ Request interceptor- Assume you want to confirm that your login information is accurate before submitting a request.

You can therefore verify at the interceptor level that your credentials are correct rather than making an actual API call.

If you need to add a token to each request performed, you can create an interceptor that does this for you rather than repeating the token addition logic at each Axios call.

2️⃣ Response interceptor- response interceptors accept two function arguments: the first function is when the response that comes back is a 200 status HTTP response, and the second function is when it’s a status code that falls outside of the 200 range


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