teleren/devto huggingface dataset:
Amazon Elastic Compute Cloud(EC2)
Tags: aws, cloud, technology, learning
Published: 2022-06-13 04:01:19

Amazon Elastic Compute Cloud (EC2) is a virtual private server that allows users to rent virtual computers on which to run their own computer applications, and provides scalable computing capacity in the AWS cloud. EC2 encourages scalable development and deployment of applications by providing a web service through which a user can boot an AMI (Amazon Machine Image) to configure a virtual machine called an instance. As the term elastic explains, this instance permits a user to create, launch and terminate server instances as needed. Active servers pay for each second.

EC2, like S3 buckets, provides users with control over the geographical location of instances that allows for latency optimization and high levels of redundancy. 


## Instance Types

An EC2 instance is a virtual server in EC2 for running applications on the AWS infrastructure. These instances are created from Amazon Machine Images(AMI), where the images are like templates. They are configured with an operating system and other software which determine the user's operating environment. EC2 instances are classified into categories based on target application profiles.

1. **General purpose instances:** It is a virtual machine designated to handle a variety of workloads. Common use cases are webserver hosting and software development and testing.
2. **Compute optimized instances:** These instances are designed to run computational and data-intensive applications that require fast network performance, extensive availabilty and high I/O operations per second (IOPS). Examples of such instances include scientific and financial modeling and simulation, machine learning enterprise data warehousing and business intelligence.
3. **Graphics Processing Unit(GPU) instances:** They provide a way of running graphic-intensive software faster than with main EC2 instances. Systems that rely on GPUs include gaming and design work.
4. **Memory Optimized instances:** They use a high speed, solid state drive to provide ultra-fast access to data and deliver high performance, and are ideal for software that require more memory and less CPU power.
5. **Storage optimized instances:** Ideal instances for applications that require high I/O performance, and we are well suited for memory-intensive applications and are well suited for memory-intensive applications like data processing, analytics, workloads and log processing.
6. **Micro instances:** A micro instance is used for applications with low throughput. It may serve as a small database server, a platform for software testing or a web server that does not necessitate high rates of transaction.

Amazon charges about 0.0058 dollars per hour for the smallest nano instance virtual instance running the Linux or Windows OS. The EC2 price varies from $2.5 per month for nano instance with one vCPU and 0.5GB RAM on board to x large type of instances with 32 vCPU and 488GB RAM for $3997.19 per month.
Count of Smaller Numbers After Self
Tags: leetcode, dsa, theabbie
Published: 2022-06-13 04:00:46

You are given an integer array `nums` and you have to return a new `counts` array. The `counts` array has the property where `counts[i]` is the number of smaller elements to the right of `nums[i]`.

**Example 1:**

**Input:** nums = \[5,2,6,1\]
**Output:** \[2,1,1,0\]
**Explanation:**
To the right of 5 there are **2** smaller elements (2 and 1).
To the right of 2 there is only **1** smaller element (1).
To the right of 6 there is **1** smaller element (1).
To the right of 1 there is **0** smaller element.

**Example 2:**

**Input:** nums = \[-1\]
**Output:** \[0\]

**Example 3:**

**Input:** nums = \[-1,-1\]
**Output:** \[0,0\]

**Constraints:**

*   `1 <= nums.length <= 105`
*   `-104 <= nums[i] <= 104`

**SOLUTION:**

    import bisect
    
    class Solution:
        def countSmaller(self, nums: List[int]) -> List[int]:
            n = len(nums)
            smallers = []
            for i in range(n - 1, -1, -1):
                currctr = bisect.bisect_left(smallers, nums[i])
                bisect.insort(smallers, nums[i])
                nums[i] = currctr
            return nums
How to clone repo from Github
Tags: github, todayilearned
Published: 2022-06-13 03:48:27

In the last month, my office migrate the Repositories from Gitlab to Github. I try to write this article for sharing and as my documentation.

**_Disclaimer_** : I have account in Github before and I use mac Terminal

#### Step 1
For the first step, I am install Github via Terminal.

```
brew install gh
```

wait the process install until see the finished installation.

#### Step 2
Second step, authenticated with Github Account.

```
gh auth login
```
follow the instruction until authenticate with Github Account


![Screenshoot gh auth login](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bda9qi4a52wvo6u0ppo1.png)

#### Step 3
Third step, create `ssh-keygen` to set to Github Account so we can clone the repo.

```
ssh-keygen
```

The file will create in folder `/Users/yourname/.ssh/`. From this step will be generate 2 file `id_rsa` and `id_rsa.pub`

Copy text file from `id_rsa.pub` with command 

```
pbcopy < ~/.ssh/id_rsa.pub
```

Paste text info your account Github.

#### Last

After following all step, in the last step. I just clone the repo with command

```
git clone <repo link>
```

But, if you doing this in new computer which is the github/gitlab account didn't setting before. Check with

```
sss -T git@gitlab.com
```

---

### Source
- https://docs.github.com/en
Code Smell 140 - Short Circuit Evaluation
Tags: webdev, javascript, beginners, programming
Published: 2022-06-13 03:06:46

*We learn short circuits in our first programming courses. We need to remember why.*

> TL;DR: Be lazy when evaluating boolean conditions

# Problems

- Side effects

- Biyection Fault

- Performance issues

# Solutions

1. Use a short circuit instead of a complete evaluation

# Context

We learn booleans in our 101 computer courses.

Boolean's truth tables are great for mathematics, but we need to be more intelligent as software engineerings.

Short circuit evaluation helps us to be lazy and even build invalid full evaluations.  

# Sample Code

## Wrong

[Gist Url]: # (https://gist.github.com/mcsee/57e3cb3fc3c5e8c90a544834022f3ab8)
```php
<?

if (isOpen(file) & size(contents(file)) > 0)
  // Full evaluation 
  // Will fail since we cannot retrieve contents 
  // from not open file
```

## Right

[Gist Url]: # (https://gist.github.com/mcsee/c548b8d38d7ddfd3dc98aa799ef975c1)
```php
<?

if (isOpen(file) && size(contents(file)) > 0)
  // Short circuit evaluation 
  // If file is not open it will not get the contents  
```

# Detection

[X] Automatic 

We can warn our developers when they use full evaluation.

# Tags

- Boolean

# Exceptions

Don't use short-circuit as an IF alternative. 

if the operands have side effects, this is another code smell. 

# Conclusion

Most programming languages support short-circuits. 

Many of them have it as the only option.

We need to favor these kinds of expressions.

# Relations

{% post https://dev.to/mcsee/code-smell-101-comparison-against-booleans-3aic %}

{% post https://dev.to/mcsee/code-smell-69-big-bang-javascript-ridiculous-castings-49ij %}

# More Info

- [Wikipedia](https://en.wikipedia.org/wiki/Short-circuit_evaluation)

* * *

> Writing a class without its contract would be similar to producing an engineering component (electrical circuit, VLSI (Very Large Scale Integration) chip, bridge, engine...) without a spec. No professional engineer would even consider the idea.

_Bertrand Meyer_
 
{% post https://dev.to/mcsee/software-engineering-great-quotes-26ci %}

* * *

This article is part of the CodeSmell Series.

{% post https://dev.to/mcsee/how-to-find-the-stinky-parts-of-your-code-1dbc %}
Laravel Eloquent Relationships
Tags: laravel, php, relationship, beginners
Published: 2022-06-13 03:31:53

In this article, we will see laravel eloquent relationships. laravel provides many relationships like laravel hasmany, laravel belongsto, wherehas laravel, many to many relationships laravel, eloquent relationships, one to many relationships laravel, one to one relationship laravel, here we will see all relationship with example.

There are 3 types of relationships in laravel:

- One to one relationship
- One to many relationship
- Many to many relationship

---

**_[Read More : Laravel Eloquent Relationships](https://techsolutionstuff.com/post/laravel-eloquent-relationships)_**
Assign Cookies
Tags: leetcode, dsa, theabbie
Published: 2022-06-13 03:30:49

Assume you are an awesome parent and want to give your children some cookies. But, you should give each child at most one cookie.

Each child `i` has a greed factor `g[i]`, which is the minimum size of a cookie that the child will be content with; and each cookie `j` has a size `s[j]`. If `s[j] >= g[i]`, we can assign the cookie `j` to the child `i`, and the child `i` will be content. Your goal is to maximize the number of your content children and output the maximum number.

**Example 1:**

**Input:** g = \[1,2,3\], s = \[1,1\]
**Output:** 1
**Explanation:** You have 3 children and 2 cookies. The greed factors of 3 children are 1, 2, 3. 
And even though you have 2 cookies, since their size is both 1, you could only make the child whose greed factor is 1 content.
You need to output 1.

**Example 2:**

**Input:** g = \[1,2\], s = \[1,2,3\]
**Output:** 2
**Explanation:** You have 2 children and 3 cookies. The greed factors of 2 children are 1, 2. 
You have 3 cookies and their sizes are big enough to gratify all of the children, 
You need to output 2.

**Constraints:**

*   `1 <= g.length <= 3 * 104`
*   `0 <= s.length <= 3 * 104`
*   `1 <= g[i], s[j] <= 231 - 1`

**SOLUTION:**

    class Solution:
        def findContentChildren(self, g: List[int], s: List[int]) -> int:
            g.sort()
            s.sort()
            n = len(s)
            ctr = 0
            for greed in g:
                for i in range(n):
                    if s[i] != None:
                        if s[i] >= greed:
                            s[i] = None
                            ctr += 1
                            break
            return ctr
Deep Insights into JavaScript Frameworks
Tags: javascript, github, opensource
Published: 2022-06-13 03:24:39

In this chapter, we will share with you some of the top JavaScript Framework repos(JSF repos) on GitHub in 2021 measured by different metrics including the number of stars, PRs, contributors, countries, regions and so on.

Note:

1. You can move your cursor onto any of the repository bars/lines on the chart and get the exact number.
2. The SQL commands above each chart are what we use on our TiDB Cloud to get the analytical results. Try those SQL commands by yourselves on TiDB Cloud with this 10-minute tutorial.

## Star history of top JavaScript Framework repos since 2011
The number of stars is often thought of as a measure of whether a github repository is popular or not. We sort all JavaScript framework repositories from github by the total number of historical stars since 2011. For visualizing the results more intuitively, we show the top 10 open source databases by using an interactive line chart.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r4j5mj830zumlksr45es.png)
https://api.ossinsight.io/share/0375d838-7f7f-4649-90e7-6ec78ab5fb48

## Top 10 most starred JSF repos in 2021 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9rtkp9oqcv2utszz5gwb.png)
https://api.ossinsight.io/share/739d4930-57b0-4960-b577-39b535d25839

## Top 10 JSF repos with the most PRs in 2021 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7qnomqwj8qvs0zyanvn0.png)
https://api.ossinsight.io/share/87287eb6-b909-4c82-872a-bdb32358e6d7

## Top 10 JSF repos with the highest YoY growth rate of stars in 2021 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1ulwdabodioi5oiyhzxh.png)
https://api.ossinsight.io/share/9cbfbdf6-66db-42dd-9b5a-0b6257b827d7

## Top 10 JSF repos with the lowest YoY growth rate of stars in 2021
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/stwmmtxkqhcbat9upb7g.png)
https://api.ossinsight.io/share/c60ad913-11f1-42d9-bf1c-d52312e36890

## Top 10 most used programming languages in JSF repos in 2021
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/47hpp5a4irzgqjc9s433.png)
https://api.ossinsight.io/share/9d4b3dbe-e9f4-44f9-b4a1-a9bd2280df48

## Top 10 countries/regions contributing the most to JSF repos in 2021
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vu7o6or8qmkfvu31wkg1.png)
https://api.ossinsight.io/share/741e94ce-8b84-4003-8491-9a2537c10922

## The Rankings of JSF repos measured by Z-score in 2021 
The analytical results displayed above are generated based on just one single metric of these three: stars, PRs, or contributors. Now, we will use the Z-score method to rank the JSF repos on GitHub.

This is the comprehensive ranking calculated by z-score:
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uv57bhvktcu9mpgws8ps.png)
https://api.ossinsight.io/share/64c7ac0a-1a4b-4fcc-85b7-da523097ac3e

https://ossinsight.io/blog/deep-insight-into-js-framework-2021
Remove Duplicates from Sorted Array
Tags: leetcode, dsa, theabbie
Published: 2022-06-13 03:00:43

Given an integer array `nums` sorted in **non-decreasing order**, remove the duplicates [**in-place**](https://en.wikipedia.org/wiki/In-place_algorithm) such that each unique element appears only **once**. The **relative order** of the elements should be kept the **same**.

Since it is impossible to change the length of the array in some languages, you must instead have the result be placed in the **first part** of the array `nums`. More formally, if there are `k` elements after removing the duplicates, then the first `k` elements of `nums` should hold the final result. It does not matter what you leave beyond the first `k` elements.

Return `k` _after placing the final result in the first_ `k` _slots of_ `nums`.

Do **not** allocate extra space for another array. You must do this by **modifying the input array [in-place](https://en.wikipedia.org/wiki/In-place_algorithm)** with O(1) extra memory.

**Custom Judge:**

The judge will test your solution with the following code:

int\[\] nums = \[...\]; // Input array
int\[\] expectedNums = \[...\]; // The expected answer with correct length

int k = removeDuplicates(nums); // Calls your implementation

assert k == expectedNums.length;
for (int i = 0; i < k; i++) {
    assert nums\[i\] == expectedNums\[i\];
}

If all assertions pass, then your solution will be **accepted**.

**Example 1:**

**Input:** nums = \[1,1,2\]
**Output:** 2, nums = \[1,2,\_\]
**Explanation:** Your function should return k = 2, with the first two elements of nums being 1 and 2 respectively.
It does not matter what you leave beyond the returned k (hence they are underscores).

**Example 2:**

**Input:** nums = \[0,0,1,1,1,2,2,3,3,4\]
**Output:** 5, nums = \[0,1,2,3,4,\_,\_,\_,\_,\_\]
**Explanation:** Your function should return k = 5, with the first five elements of nums being 0, 1, 2, 3, and 4 respectively.
It does not matter what you leave beyond the returned k (hence they are underscores).

**Constraints:**

*   `1 <= nums.length <= 3 * 104`
*   `-100 <= nums[i] <= 100`
*   `nums` is sorted in **non-decreasing** order.

**SOLUTION:**

    class Solution:
        def removeDuplicates(self, nums: List[int]) -> int:
            n = len(nums)
            i = 0
            for j in range(n):
                if j > 0 and nums[j] != nums[j - 1]:
                    i += 1
                    nums[i] = nums[j]
            return i + 1
How I Connect Firebase with Flutter in just 2 minutes!
Tags: flutter, programming, firebase, tutorial
Published: 2022-06-13 02:55:36

Firebase just came out with an awesome new way to connect to Flutter Quickly.

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

---

# Why should I use new method to connect Flutter with Firebase?
There are **Three main** reasons for which you should switch to the new method -:
**- Much Easier to Integrate**
**- No need to add files in Xcode and Android folder**
**- Saves a bunch of Time**

---

# How can I Integrate this new way?
It is **Easy and Simple** and you just need to **follow these steps -**

# 1. Go To Your Firebase Console and Create a New Project

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

# 2. Give a Title to your new Project

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

# 3. Create and Click the new Flutter Icon

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

# 4. Download Firebase Cli
_- Open Terminal_
_- Paste This Command_
_- Press Enter_

```
curl -sL https://firebase.tools | bash
```

# 5. Login Through Terminal
_Paste This Command_
_Login through your Firebase Account_

```
firebase login
```

# 6. Open your Flutter project
_Paste and Run this Command in Terminal of your project_
**1.**

```
dart pub global activate flutterfire_cli

```
**2.**

```
export PATH="$PATH":"$HOME/.pub-cache/bin"
```

# 7. Enter Command to Configure your Project

```
flutterfire configure --project=$your firebase project Id
```
_Now Select platforms you want to configure firebase for…_

# 8. Add Latest Version of Firebase_Core as a dependency to Pubspec.yaml

---

> Congratulations!!
> You Integrated Firebase into you Flutter Project in just 2 mins
> I Hope You Enjoyed the Process 😄

---

**_Follow Me For More Such Content_**
Maximum Consecutive Floors Without Special Floors
Tags: leetcode, dsa, theabbie
Published: 2022-06-13 02:30:46

Alice manages a company and has rented some floors of a building as office space. Alice has decided some of these floors should be **special floors**, used for relaxation only.

You are given two integers `bottom` and `top`, which denote that Alice has rented all the floors from `bottom` to `top` (**inclusive**). You are also given the integer array `special`, where `special[i]` denotes a special floor that Alice has designated for relaxation.

Return _the **maximum** number of consecutive floors without a special floor_.

**Example 1:**

**Input:** bottom = 2, top = 9, special = \[4,6\]
**Output:** 3
**Explanation:** The following are the ranges (inclusive) of consecutive floors without a special floor:
- (2, 3) with a total amount of 2 floors.
- (5, 5) with a total amount of 1 floor.
- (7, 9) with a total amount of 3 floors.
Therefore, we return the maximum number which is 3 floors.

**Example 2:**

**Input:** bottom = 6, top = 8, special = \[7,6,8\]
**Output:** 0
**Explanation:** Every floor rented is a special floor, so we return 0.

**Constraints:**

*   `1 <= special.length <= 105`
*   `1 <= bottom <= special[i] <= top <= 109`
*   All the values of `special` are **unique**.

**SOLUTION:**

    class Solution:
        def maxConsecutive(self, bottom: int, top: int, special: List[int]) -> int:
            points = sorted([bottom - 1] + special + [top + 1])
            mgap = 0
            n = len(points)
            for i in range(n - 1):
                mgap = max(mgap, points[i+1] - points[i] - 1)
            return mgap
Getting started with TypeScript and React Native
Tags: reactnative, typescript
Published: 2022-06-13 02:19:31

Hola hola,

Using TypeScript in your React Native (RN) projects can seem like a daunting task - and it definitely can be. I would recommend experimenting/practicing in a fresh RN project before updating your production app to TypeScript.

#### Getting Started

[Here](https://github.com/trouthouse-tech/codewiththt-ts-getting-started) is a fresh repo created using the the command found [here](https://reactnative.dev/docs/typescript#getting-started-with-typescript).

#### JSX
One good thing about this endeavor is that our JSX (the stuff between the `return ()`) won't change much.

#### JavaScript Component (.js)
Let's take a look at a very simple JS component that accepts in a text prop and displays that inside of a simple `<Text>` component.

```
const MyTextComponent = (props) => {
  const {text} = props;

  return (
    <Text>{text}</Text>
  );
}
```

#### TypeScript Component (.tsx)
Here's the same exact component but using TS. You'll notice that not much has changed within the actual component.

```
type Props = {
 text: string;
};

const MyTextComponent = (props: Props) => {
  const {text} = props;

  return (
    <Text>{text}</Text>
  );
}
```
All we're doing differently is saying that the props passed to `MyTextComponent` should contain only one property called `text` and that prop should be a `string`. 

This set of _rules_ will let us know that there is an issue if we try to do the following:

`<MyTextComponent text={5} />`

Will the above crash? No. But, it will alert us right away.

#### TypeScript With Local State
Here is how we can update our local state ([useState](https://reactjs.org/docs/hooks-state.html)) to utilize TypeScript.

```
import {TextInput, TouchableOpacity} from 'react-native';

const MyTextInputComponent = () => {
  // const [text, setText] = useState(''); // JS version
  const [text, setText] = useState<string>(''); // TS version

  const incrementText = () => {
    setText(oldVal => oldVal + 1); // TS will yell at us here
  };

  return (
    <>
      <TextInput onChangeText={setText} value={text} />
      <TouchableOpacity onPress={incrementText}>
        <Text>Increment Text</Text>
      </TouchableOpacity>
    </>
  );
}
```
In the above example, we set a type for our local state by using the angle bracket notation to say that this `text` value should only be a `string`. 

<u>_Why would TS yell at us for the `incrementText()` button?_</u>
TS knows that the `text` prop is a `string`. When we write code like `setText(oldVal => oldVal + 1);` which is adding 1 to the old `text` value TS will warn us that we cannot add a `Number` and a `string`. 

#### `.ts` vs `.tsx`
You'll see both of these files. `.ts` files are used for non-UI logic (i.e., stuff not within a `return()` statement). In order to display a UI component (like `<View>, <Text>, and etc` you need to make sure that you are in a `.tsx` file.

#### Summary
- I don't recommend adding TypeScript to a production app if it's your first time
- Your JSX will mostly stay the same
- TypeScript is your friend

Happy coding!

- Matt