teleren/devto huggingface dataset:
Why I no longer use GraphQL for new projects
Tags: graphql, webdev, react, javascript
Published: 2021-12-01 10:31:48

Before I go further, I want to clarify that I love GraphQL as a frontend engineer. It empowers me to create.

I also think GraphQL is a great choice for larger engineering organizations. Having a GraphQL server as an API layer over different micro services allows frontend engineers to just build without dealing with the complexity.

For new projects, however, I will no longer be using GraphQL. My definition of a new project is a project without a clear market fit and a project with a small team (less than 3 engineers).

## Performance

As a backend engineer, I hate GraphQL. GraphQL provides a lot of flexibility on the client side but this means that we cannot optimize as aggressively on the server.

Making sure that our GraphQL server is performant requires discipline and care. It's questionable if this investment is justified unless the team is already well versed in GraphQL performance. For example the team will need to know how to utilize dataloaders to avoid n + 1 queries.

## Security

With a traditional REST API, we can add security on each of the routes that we are exposing. With a GraphQL API we have to be cognizant of the fact that there could be endless permutations of queries that can be triggered.

Types and access to types have to be organized with care. We have to make sure that we don't unexpectedly add a subquery that exposes sensitive fields.

## Engineer Onboarding

GraphQL is new to a lot of engineers. Traditional REST API is familiar to many engineers. It's one extra thing someone has to learn before they can be productive. 

It's tempting to reach for GraphQL especially if we want to learn it, or because we really enjoy working with it. Before we reach for GraphQL, we should ask ourselves 'Is this tradeoff worth it early on in the project?'

## Conclusion

There is an argument that we should just start off with GraphQL if that's ultimately where we want to get to once the project gets big. If there is a guarantee that the project will get big, then yes I agree.

However, if we aren't sure if our project is going to be a runaway success with 30+ engineers in a span of 6 months...I believe going the more traditional route will allow the team to be more nimble and add talent easier. Time is of the essence, GraphQL can be added later when the organization matures.
9 Best VS Code Extensions
Published: 2021-12-01 10:29:31

## [1. Live Server](https://marketplace.visualstudio.com/items?itemName=ritwickdey.LiveServer)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/frb7d2tnq3orjiihvi3t.gif)
 
## [2. Color Highlight](https://marketplace.visualstudio.com/items?itemName=naumovs.color-highlight)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1gsfalaeyohji9iqg82j.png)
 
## [3. Html Meta Tags Hero](https://marketplace.visualstudio.com/items?itemName=nadim-vscode.html-meta-tags-hero)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/36w4qv5a8lyaef4uxclv.png)
 
## [4. Material Icon Theme](https://marketplace.visualstudio.com/items?itemName=PKief.material-icon-theme)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hb6049dx49iti4m5u7dv.png)
 
## [5. Auto Rename Tag]()
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sdg5ozqituiwbspzn41t.gif)

## [6. Live Share](https://marketplace.visualstudio.com/items?itemName=MS-vsliveshare.vsliveshare)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mi3o14zqri9yectarie8.png)

## [7. Comment Anchors](https://marketplace.visualstudio.com/items?itemName=ExodiusStudios.comment-anchors)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2nv5sq1ofh475cle0tgy.png)

## [8. Dracula Official](https://marketplace.visualstudio.com/items?itemName=dracula-theme.theme-dracula)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/564gamkhe1ym073offsy.png)

## [9. Prettier-Code formatter](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nawsrstyiafv2burjdlk.gif)
 
**Thank you for being with us until the end of this article. If you liked this article, do not forget to like and follow.❤**
Operators in Java
Tags: java, programming
Published: 2021-12-01 10:27:57

#Operators:
Operator in Java is a symbol that is used to perform operations. For example: +, -, *, / etc.

There are many types of operators in Java which are given below:

Unary Operator,
Arithmetic Operator,
Shift Operator,
Relational Operator,
Bitwise Operator,
Logical Operator,
Ternary Operator and
Assignment Operator.

#Java Unary Operator:
The Java unary operators require only one operand. Unary operators are used to perform various operations i.e.:
incrementing/decrementing a value by one
negating an expression
inverting the value of a boolean
#Java Arithmetic Operators
Java arithmetic operators are used to perform addition, subtraction, multiplication, and division. They act as basic mathematical operations.
#Java Left Shift Operator
The Java left shift operator << is used to shift all of the bits in a value to the left side of a specified number of times.
#Java Right Shift Operator
The Java right shift operator >> is used to move the value of the left operand to right by the number of bits specified by the right operand.
#Java AND Operator Example: Logical && and Bitwise &
The logical && operator doesn't check the second condition if the first condition is false. It checks the second condition only if the first one is true.
The bitwise & operator always checks both conditions whether first condition is true or false.
#Java OR Operator Example: Logical || and Bitwise |
The logical || operator doesn't check the second condition if the first condition is true. It checks the second condition only if the first one is false.
The bitwise | operator always checks both conditions whether first condition is true or false.
#Java Ternary Operator
Java Ternary operator is used as one line replacement for if-then-else statement and used a lot in Java programming. It is the only conditional operator which takes three operands.
#Java Assignment Operator
Java assignment operator is one of the most common operators. It is used to assign the value on its right to the operand on its left.
#Java Assignment Operator Example
public class OperatorExample{  
public static void main(String[] args){  
int a=10;  
a+=3;//10+3  
System.out.println(a);  
a-=4;//13-4  
System.out.println(a);  
a*=2;//9*2  
System.out.println(a);  
a/=2;//18/2  
System.out.println(a);  
}}  
Output:
13
9
18
9
Binary Search Templates
Tags: algorithms, java, programming, 100daysofcode
Published: 2021-12-01 10:22:19

[Reference](https://segmentfault.com/a/1190000016825704)
# Request
1. Sorted Array
2. Need `N(logN)`

# Templates
## 1. Standard Templates

```java
class BinarySearch {
    public int search(int[] nums, int target) {
        int left = 0;
        int right = nums.length - 1;
        while (left <= right) {
            int mid = left + ((right - left) >> 1);
            if (nums[mid] == target) return mid;
            else if (nums[mid] > target) {
                right = mid - 1;
            } else {
                left = mid + 1;
            }
        }
        return -1;
    }
}

```

## 2. Binary Search Left Boundary

```java
class Solution {
    public int search(int[] nums, int target) {
        int left = 0;
        int right = nums.length - 1;
        while (left < right) {
            int mid = left + (right - left) / 2;
            if (nums[mid] < target) {
                left = mid + 1;
            } else {
                right = mid;
            }
        }
        return nums[left] == target ? left : -1;
    }
}

```
### [Practice Fixed-Point](https://binarysearch.com/problems/Fixed-Point)

## 3. Binary Search Right Boundary

```java
class Solution {
    public int search(int[] nums, int target) {
        int left = 0;
        int right = nums.length - 1;
        while (left < right) {
            int mid = left + ((right - left) >> 1) + 1;
            if (nums[mid] > target) {
                right = mid - 1;
            } else {
                left = mid;
            }
        }
        return nums[right] == target ? right : -1;
    }
}

```
### [practice Guess-the-Root](https://binarysearch.com/problems/Guess-the-Root)

# Conclusion

|type|while|left update|right update|mid|return|
|---|---|---|---|---|---|
|standard|`left <= right`|`left = mid - 1`|`right = mid + 1`|`(left + right) / 2`|`-1 / mid`|
|left boundary|`left < right`|`left = mid - 1`|`right = mid`|`(left + right) / 2`|`-1 / left`|
|right boundary|`left < right`|`left = mid`|`right = mid - 1`|`(left + right) / 2 + 1`|`-1 / right`|
Using Constants in PostgreSQL queries
Tags: postgres, sql, tutorial, productivity
Published: 2021-12-01 10:13:59

#Introduction

Imagine we have a long query which has a lots of conditions, and many of the conditions has some kind of comparisions with literals instead of some other record value.

**Example:**

```sql
SELECT * FROM users u where (u.name='some name' or u.age=12 or u.email='qwe@qwe.qwe');
```

For example sake we are taking the name, age and email as constants.

Imagine these literal values used multiple times in the query. We will have very untidy query.

To make the query more readable and tidy we can use constants, like we do in normal programming languages where if some literal value is/will be used repeatedly then we define it as a constant.

## Solution

To achieve this we will be using the **`WITH`** Common Table Expression (CTE)

Common Table Expression are very powerful as they allow us to create temporary named result set which can be used within a SELECT, INSERT, UPDATE, DELETE query.

The result set is temporary and only limited to the scope of the query, it is not stored any where and exists only for the duration of the query. 

Thus we are not creating any garbage after our query has been executed.

Let's see how our new query will look like


```sql
WITH consts AS (
    SELECT 'some name' as temp_name, 12 as temp_age, 'qwe@qwe.qwe' as temp_email
)
SELECT * FROM users u, consts c where (u.name= c.temp_name or u.age=c.temp_age or u.email=c.temp_email);

```

Notice that we are using the result set **`consts`** as we use a table.

## Conclusion

Thus we have seen how we can use named constants and how helpful are the CTEs to write compact, readable and efficient queries.


I usually write on my git pages which you can reach from https://rajkumargosavi.github.io, from which this post was re-shared.
java programming
Published: 2021-12-01 10:11:27

What is Java?
Java is a popular programming language, created in 1995.

It is owned by Oracle, and more than 3 billion devices run Java.

It is used for:

Mobile applications (specially Android apps)
Desktop applications
Web applications
Web servers and application servers
Games
Database connection
And much, much more!
java syntax is similar to C/C++. But Java does not provide low-level programming functionalities like pointers. Also, Java codes are always written in the form of classes and objects.
When compared with C++, Java codes are generally more maintainable because Java does not allow many things which may lead to bad/inefficient programming if used incorrectly. For example, non-primitives are always references in Java. So we cannot pass large objects (like we can do in C++) to functions, we always pass references in Java. One more example, since there are no pointers, bad memory access is also not possible.

When compared with Python, Java kind of fits between C++ and Python. The programs are written in Java typically run faster than corresponding Python programs and slower than C++. Like C++, Java does static type checking, but Python does not.

Features of Java
Simple
Object-Oriented
Portable
Platform independent
Secured
Robust
Architecture neutral
Interpreted
High Performance
Multithreaded
Distributed
Dynamic
Types of Java Applications
There are mainly 4 types of applications that can be created using Java programming:

1) Standalone Application
Standalone applications are also known as desktop applications or window-based applications. These are traditional software that we need to install on every machine. Examples of standalone application are Media player, antivirus, etc. AWT and Swing are used in Java for creating standalone applications.

2) Web Application
An application that runs on the server side and creates a dynamic page is called a web application. Currently, Servlet, JSP, Struts, Spring, Hibernate, JSF, etc. technologies are used for creating web applications in Java.

3) Enterprise Application
An application that is distributed in nature, such as banking applications, etc. is called an enterprise application. It has advantages like high-level security, load balancing, and clustering. In Java, EJB is used for creating enterprise applications.

4) Mobile Application
An application which is created for mobile devices is called a mobile application. Currently, Android and Java ME are used for creating mobile application
📣 Get GitHub follower change notification
Tags: actionshackathon21, github, actionshackathon, javascript
Published: 2021-12-01 10:02:45

[Instructions]: # (To submit to the GitHub Actions x DEV Hackathon 2021, please fill out all sections.)


### My Workflow
As an active user of GitHub, I am always interested in new followers from GitHub, caring a lot about who they are, where are they from, what they do, etc. 

So I create a GitHub Action to email me daily, about my follower change events.

Here it is !

{% github https://github.com/Sorosliu1029/follower-change %}

[Note]: # (Please make sure the project links to the appropriate GitHub Actions repository, and includes [an open source license](https://choosealicense.com/) and README.)


### Submission Category: 

Wacky Wildcards

### Yaml File or Link to Code

This workflow composites my [follower-change](https://github.com/marketplace/actions/github-follower-change-event) action with [Send email](https://github.com/marketplace/actions/send-email) action

```yaml
name: follower notifier
on:
  schedule:
    - cron: '0 3 * * *' # in UTC time
  workflow_dispatch:
jobs:
  main:
    runs-on: ubuntu-latest
    steps:
      - name: get follower change
        id: followerChange
        uses: Sorosliu1029/follower-change@v2
        with:
          myToken: ${{ secrets.MY_TOKEN }}
          notifyUnFollowEvent: true
      - name: email me
        uses: dawidd6/action-send-mail@v3
        if: steps.followerChange.outputs.shouldNotify == 'true'
        with:
          server_address: smtp.qq.com
          server_port: 465
          username: ${{ secrets.MAIL_USERNAME }}
          password: ${{ secrets.MAIL_PASSWORD }}
          subject: GitHub Follower Change
          from: Follower Change Notifier
          to: ${{ secrets.TO_EMAIL_ADDRESS }}
          html_body: file://${{ steps.followerChange.outputs.htmlFilePath }}
```

[Note]: # (Our markdown editor supports pretty embeds. Try this syntax: `{% github link_to_your_repo %}` to share a GitHub repository)


### Additional Resources / Info

Here is how the email looks like, hope you receive it everyday !

![Email Screenshot](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/utz8ju3rw0p5nf466rzl.png)
How to use context in Svelte?
Tags: svelte, javascript, beginners, programming
Published: 2021-12-01 10:09:57

Let's think of a scenario where we have three components A, B, and C. We want to define a variable or an object in `Component A`. And we want, It to be accessible from `Component C`. In our previous articles, we discussed different methods to pass the props data to the parent component. In this article, we'll discuss the context method in svelte.

Svelte passes parent component data to its child components. The `getContext` and `setContext` functions can access associated data with a key on the context.  Changes made to context values are only valid for the current child component. Parent component values are intact. 

Let's say a user logged in and, in another component, we want to show the user details (the email and login status in another child component). In this, it is a good idea to use the Context API instead of passing the props. (Probably a store will be more appropriate but, it is out of scope for this article).

In the `App.svelte`

```javascript
<script>

    import { setContext } from 'svelte'

    const userDetails = { username: 'abc@example.com', islogin: 'yes' };

    setContext('user-details', userDetails )

    import ContextComponent from "./ContextComponent.svelte";

</script>

<main>
    <p> Context Example. </p>
    <hr/>

    <div>
        <br />
        <ContextComponent />
    </div>

</main>

<style>
	main {
		text-align: center;
		padding: 1em;
		max-width: 240px;
		margin: 0 auto;
	}


	@media (min-width: 640px) {
		main {
			max-width: none;
		}
	}
</style>
```

If we check the `setContext{}` function, we'll see something similar `export declare function setContext<T>(key: any, context: T): void;`

The `setContext` function accept two arguments:

- Context Key
- Value or variable or an object that we want to send all of the child application components.

`setContext('user-details', userDetails )` we set the context key as `user-details` and pass `userDetails` object as second argument.

Svelte provides `getContext` function to retrieve the `setContext` key. Create another component `ContextComponent.svelte` and add the following code:

```javascript
<script>
    import { getContext } from 'svelte'

    const userDetails = getContext('user-details')

</script>

<div>
    <div>
        <strong>User Name:</strong> { userDetails.username }
    </div>

    <div>
        <strong>User Login Status:</strong> { userDetails.islogin }
    </div>

</div>
```

`export declare function getContext<T>(key: any): T;` how the getContext function is defined in svelte. 

It only accepts one argument (key). That we defined in our `App` component( `user-details` ) in this case.

If you go to the web page, you'll see:

![img](https://ashutosh.dev/content/images/2021/11/Screenshot-2021-11-27-at-11.03.40-PM.png)

 Thats all about Context in Svelte. See you in the next article.
Python VS. C#
Tags: python, csharp, programming, dotnet
Published: 2021-12-01 10:07:40



## **Comparison of Python and C#**

 
**1. Dynamic vs. Static**

C# is an exceptional statically-typed language. Its compiler offers errors for wrong typescripts, but Python has a more dynamic type-casting that provides no variable declaration requirement. C# needs an additional compiling step that is not that pleasant for programmers. It affects the time needed for testing and productivity. On the contrary, the compiler in Python identifies errors before all the errors affect the development. Moreover, this process is faster and easier.

 
**2. Easy to Use**

C# has its root from object-oriented programming. One who has a strong background in Java or wants to develop apps for Microsoft can consider C# as an excellent choice. Python developers do not have to learn a lot of language constructions, and they can learn better in development. But the C# developers need knowledge on constructions like functions and classes. On the other hand, Python just needs one-line code.

 
**3. Performance**

The performance of both languages differs a lot. Python has interpreted language, so its speed is great and depends on the interpreter like PyPy, CPython, etc. In contrast, C# is compiled language that needs more effort and time in writing code but has more efficiency in performance. C# is speeder and has better performance due to the CLI framework.

 
**4. Application**

Both the languages are used, from game development, web apps to IoT. In machine learning, only they have differences. For machine learning, Python is the popular choice, which offers developers numerous videos, tutorials, and provides a multitude of choices like Apache Spark, SciPy, etc. C# has a limited choice like ML.NET.

 
**5. Development Speed**

Python aims to create quality code using less effort and has simpler syntax compared to C#. Programmers do not even have to complete each line with semicolons with easy readability.


Get to explore more here https://www.rlogical.com/blog/python-vs-c-sharp-a-detailed-comparison
Attempt to read property  "produits"on null
Tags: help
Published: 2021-12-01 09:59:57

I'm using Laravel 8 and, I want to add to the wishlist after I click add, I get an error. I believe that the way I want to access the product is wrong.
this is my controller
```
public function addToFavorie($id)
{
    $user = Auth::user();
    $product = produit::find($id);

    if (!$product || !$user) {
        abort(404);
    }

    // I believe this is the part responsible for the error
    $favorie = $user->favorie;
    $favprds = $favorie->produits;
    //

    for ($i = 0; $i < count($favprds); $i++) {
        if ($favprds[$i]->id == $id)
            return redirect()->back()
                ->with('error', 'produit deja dans votre favorie');
    }
    $favorie->produits()->attach($product->id);

    return redirect()->back()->with('info', 'produit ajoute a votre favorie');
}
```
i've tried this in my controller it return page 404
```
$user = Auth::user()->favorie;
$product = produit::find($id);

if (!$product || !$user) {
    abort(404);
}

$favprds = $favorie->produits;
```
this is my model i tried to change belongsToMany to hasMany same problem
```
public function user()
{
    return $this->belongsTo("App\Models\User");
}

public function produits()
{
    return $this->belongsToMany('App\Models\Produit', 'produits_favories');
}
```