teleren/devto huggingface dataset:
CS50 Problem Set 2 , Readability
Published: 2022-06-07 15:17:37


```
//CS50 Problem Set 2 (Fall 2022): Readability
//Author: Pranav Madhavan

#include <cs50.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <math.h>

int count_letters(string text, int str);
int count_words(string text, int str);
int count_sentences(string text, int str);

int main(void)
{
    //ask user for string and store in s
    string s = get_string("Text: ");
    //find length of a string using srlen function
    int strl = strlen(s);

    int letters = count_letters(s, strl);  //count of Letters
    int words = count_words(s, strl);  //count of Words
    int sentences = count_sentences(s, strl);  //count of sentences

    float L = 100 * (float) letters / (float) words;//Letters Per Hundred words
    float S = 100 * (float) sentences / (float) words; //Sentences Per Hundred Words

    int index = round(0.0588 * L - 0.296 * S - 15.8); //Coleman-Liau index


    //to print grade
    if (index < 1)
    {
        printf("Before Grade 1\n");
    }
    else if (index < 16)
    {
        printf("Grade %i\n", index);
    }
    else
    {
        printf("Grade 16+\n");
    }

}

//function to count number of letters.
int count_letters(string text, int str)
{

    //variable which stores no of Letters.
    int l = 0;

    for (int i = 0; i < str; i++)
    {

        if (isalpha(text[i]) != 0)
        {
            l++;
        }
    }
    return l;
}

int count_words(string text, int str)
{
    //count of spaces.
    int w = 0;

    for (int i = 0; i < str; i++)
    {
        if (isspace(text[i]) != 0)
        {
            w++;
        }
    }

    //no of words.
    w = w + 1;
    return w;
}

int count_sentences(string text, int str)
{
    //count of sentences
    int s = 0;
    //count of . ! and ?
    for (int i = 0; i < str ; i++)
    {
        if (text[i] == 33 || text[i] == 46 || text[i] == 63)
        {
            s++;
        }
    }

    return s;

}
```
Max Consecutive Ones
Tags: leetcode, dsa, theabbie
Published: 2022-06-07 15:00:46

Given a binary array `nums`, return _the maximum number of consecutive_ `1`_'s in the array_.

**Example 1:**

**Input:** nums = \[1,1,0,1,1,1\]
**Output:** 3
**Explanation:** The first two digits or the last three digits are consecutive 1s. The maximum number of consecutive 1s is 3.

**Example 2:**

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

**Constraints:**

*   `1 <= nums.length <= 105`
*   `nums[i]` is either `0` or `1`.

**SOLUTION:**

    class Solution:
        def findMaxConsecutiveOnes(self, nums: List[int]) -> int:
            nums.append(-1)
            maxOnes = 0
            curr = 0
            for num in nums:
                if num <= 0:
                    maxOnes = max(maxOnes, curr)
                    curr = 0
                else:
                    curr += 1
            return maxOnes
How I usually create a test plan. Step by step
Tags: testing, beginners, productivity, writing
Published: 2022-06-07 14:45:28

Great preparation does yield great results, and software quality assurance is no exception. Here are the steps I do every time I need to create a new test plan:

**Step 0: Analyse the product**
Ask the product owner about the launch and high priority features, since quality may have been sacrificed in favour of speed. Talk to the project manager to see if they have been facing recurring issues. Ask developers where technical debt risks turning into a point of failure. 

**Step 1: Define the scope**
You usually focus on the level of testing (e.g. unit or system testing) and may additionally limit yourself by the types of testing. Functional vs non-functional testing is often quite a distinction in itself.

**Step 2: List test criteria**
Once you know what to look for, it’s only logical to define what constitutes QA success and failure. Feel free to introduce benchmarks that are relevant to the scope. Some examples include defect rate percentage, test case pass rate, and threshold of severe open defects.

**Step 3: Map the environment**
Write down all the tools that your team uses for software testing. Evaluate whether this suite is enough for the scope. Research and add new solutions if necessary.

**Step 4: Create a schedule**
Knowing the schedule of product and developer teams is 90% of creating your own schedule. Make sure to account for potential missed deadlines on both your and their ends.

**Step 5: Write down deliverables**
All that’s left now is to formalise the expected output. The test plan that you may be writing right now is a deliverable as well. So are the new test cases that your team will make as well as any fruits of the automation labour.

Learn more about each step in my [article](https://aqua-cloud.io/create-software-testing-plan/) dedicated to that.
Obstacles to Web3 Mass Adoption, and How to Solve Them👇
Tags: web3, webdev, opensource, blockchain
Published: 2022-06-07 14:37:17

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

Most decentralized applications (dApps) in web3 are built on congested public blockchains where they're forced to compete against others for bandwidth. The result: slow transactions and high fees needed to process those transactions — challenges that keep internet users (and their digital identities) under the ownership of web2 centralized platforms. 
 
Web3 development also requires devs to learn new programming languages and skills — further stalling mass adoption and resulting in the poor UX common to many web3 dApps.
 
In order for web3 mass adoption to occur, we as an industry must provide a better UX than web2. This UX needs to be more accessible, cheaper, and (quite honestly) prettier. Until this occurs, web3 will remain a largely immature market, fueled by speculative investing and full of volatility.
 
Only with genuine usability and mass adoption will the market conditions of the crypto industry stabilize.
 
With this in mind, our #1 goal should be to facilitate web3 development. Good, efficient, profound development. To start, we need to knock down the barriers in place.
 
First, we must enable developers to build their dApps using the frameworks, skills, and languages they prefer and know best. That's how we'll see the best projects get developed.
 
Second, we must create blockchain infrastructure that enables these new dApps to scale and succeed. We need to alleviate the network congestion that makes web3 slow and expensive.
 
Application-Specific Chains aka "App Chains" — dedicated blockchains that house and serve a single dApp, represent a viable solution to these challenges. They enable developers to enjoy maximum customizability and remove the need to compete with neighboring dApps for network traffic.
 
That said, creating an App Chain can be a daunting task, especially for web2 companies looking to join web3. [Ankr App Chain](https://www.ankr.com/app-chains/) infrastructure bridges this gap and makes App Chain development as easy and accessible as possible. My goal is to empower developers with plug-and-play tools to build their own custom blockchains, no longer forcing them to compete for servicing traffic. 
 
My vision for Ankr App Chain Infrastructure is to be the underlying battery that supercharges web3 mass adoption. As a result, developers will quickly deploy high-quality games, financial products, and other dApps with superior UX's—subsequently empowering web2 consumers to enter the web3 world. This new world being the updated version of the current internet, which will bring digital human rights away from centralized authorities and back to the people.
Find Triangular Sum of an Array
Tags: leetcode, dsa, theabbie
Published: 2022-06-07 14:30:46

You are given a **0-indexed** integer array `nums`, where `nums[i]` is a digit between `0` and `9` (**inclusive**).

The **triangular sum** of `nums` is the value of the only element present in `nums` after the following process terminates:

1.  Let `nums` comprise of `n` elements. If `n == 1`, **end** the process. Otherwise, **create** a new **0-indexed** integer array `newNums` of length `n - 1`.
2.  For each index `i`, where `0 <= i < n - 1`, **assign** the value of `newNums[i]` as `(nums[i] + nums[i+1]) % 10`, where `%` denotes modulo operator.
3.  **Replace** the array `nums` with `newNums`.
4.  **Repeat** the entire process starting from step 1.

Return _the triangular sum of_ `nums`.

**Example 1:**

![](https://assets.leetcode.com/uploads/2022/02/22/ex1drawio.png)

**Input:** nums = \[1,2,3,4,5\]
**Output:** 8
**Explanation:**
The above diagram depicts the process from which we obtain the triangular sum of the array.

**Example 2:**

**Input:** nums = \[5\]
**Output:** 5
**Explanation:**
Since there is only one element in nums, the triangular sum is the value of that element itself.

**Constraints:**

*   `1 <= nums.length <= 1000`
*   `0 <= nums[i] <= 9`

**SOLUTION:**

    class Solution:
        def triangularSum(self, nums: List[int]) -> int:
            k = len(nums)
            curr = [1]
            n = 1
            for i in range(k - 1):
                curr = [0] + curr
                n += 1
                for i in range(n - 1):
                    curr[i] = curr[i] + curr[i + 1]
            total = 0
            for i in range(k):
                total += nums[i] * curr[i]
            return total % 10
What are some math-heavy jobs in software engineering?
Tags: anonymous, discuss, career
Published: 2022-06-07 14:29:36

_This is an anonymous post sent in by a member who does not want their name disclosed. Please be thoughtful with your responses, as these are usually tough posts to write. Email sloan@dev.to if you'd like to leave an anonymous comment or if you want to ask your own anonymous question._ 

***


Next year, I'm going to graduate from university with a B.S. in Mathematics. I've been more and more interested in applying math to computer science in the past year. Are there any software engineering jobs that are math-specific or math-focused? I can't change my major or anything, but it would be cool to know if I can still use this degree and get a job as a developer with my background in math.
I made an admin template for React based on the latest UI trends! Use it for free!
Tags: webdev, showdev, react, opensource
Published: 2022-06-07 14:26:59

Hey guys,
I made an admin template for React & Chakra UI based on the latest UI trends! Use it for free!

- Presentation: https://horizon-ui.com/
- Live demo: https://horizon-ui.com/horizon-ui-chakra/
- Download on Github: https://github.com/horizon-ui/horizon-ui-chakra
Reactjs NodeJS Cors Request Not Succeeded Errors
Tags: react, node, linux
Published: 2022-06-07 11:56:59

My reactjs website runs on https and my NodeJS server is https but I got error calling the NodeJS api from reactjs website. Both ReactJS website and NodeJS api deployed on the same linux VPS server, my database is on a remote but the connection is fine as I am not getting database connection error but i got cors errors like below:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://localhost:8184/api/v1/signin. (Reason: CORS request did not succeed). Status code: (null).

My NodeJS that started the https server enable cors and it allowed cross origin. See my NodeJS

```
const cors = require('cors')({
   origin: 'https://mydomaindotcom'
});


const allowCrossDomain = function (req, res, next) {
    res.header('Access-Control-Allow-Origin', '*');
    res.header('Access-Control-Allow-Methods', 'POST, GET, PUT,PATCH, DELETE, OPTIONS, ');
    res.header('Access-Control-Allow-Credentials', false);
    res.header('Access-Control-Max-Age', '86400');
    res.header('Access-Control-Allow-Headers', 'Authorization, X-Requested-With, X-HTTP-Method-Override, Content-Type, Accept');
    next();
};
app.use(allowCrossDomain);
// Error logger
app.use(logger('dev', {
    skip: function (req, res) { return res.statusCode < 400 },
    stream: fileWriter
}))
app.use(logger('dev'));
app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.json());
app.use(cors);
app.use(fileUpload());
app.use("/api/v1", routes);
```

In my ReactJS package.json file i have my domain as homepage like below:

```
"homepage": "https://mydomain",
"Hostname": "https://mydomain",
```

Please help on this cors errors, it has taken enough sweat on my face.
Developer #MOBILE FLUTTER na TQI
Tags: flutter, mobile
Published: 2022-06-07 14:22:41

Vagaaa de hoje 

⚡ Developer #MOBILE FLUTTER na TQI ⚡

🎯Requisitos:
 
- Experiência em Flutter e Dart
- Integração FE x BE 
- Atuação com HttpClients do Flutter 
- Gerencia de estado

💻 100% remoto
💵 Modelo de contratação: PJ
🤝Pretensão Salarial + Benefícios

 #flutter
Leetcode 88. Merge Sorted Array
Tags: programming, career, computerscience, algorithms
Published: 2022-06-07 14:17:34

## Problem Statement:

You are given two integer arrays nums1 and nums2, sorted in non-decreasing order, and two integers m and n, representing the number of elements in nums1 and nums2 respectively.

Merge nums1 and nums2 into a single array sorted in non-decreasing order.

The final sorted array should not be returned by the function, but instead be stored inside the array nums1. To accommodate this, nums1 has a length of m + n, where the first m elements denote the elements that should be merged, and the last n elements are set to 0 and should be ignored. nums2 has a length of n.

## Test Cases:

### Example 1:

Input: nums1 = [1,2,3,0,0,0], m = 3, nums2 = [2,5,6], n = 3
Output: [1,2,2,3,5,6]
Explanation: The arrays we are merging are [1,2,3] and [2,5,6].
The result of the merge is [1,2,2,3,5,6] with the underlined elements coming from nums1.
Example 2:

Input: nums1 = [1], m = 1, nums2 = [], n = 0
Output: [1]
Explanation: The arrays we are merging are [1] and [].
The result of the merge is [1].
Example 3:

Input: nums1 = [0], m = 0, nums2 = [1], n = 1
Output: [1]
Explanation: The arrays we are merging are [] and [1].
The result of the merge is [1].
Note that because m = 0, there are no elements in nums1. The 0 is only there to ensure the merge result can fit in nums1.


## Constraints:
* nums1.length == m + n
* nums2.length == n
* 0 <= m, n <= 200
* 1 <= m + n <= 200
* -10^9 <= nums1[i], nums2[j] <= 10^9


## Approach

From the given constraints, we can say one thing which is length of nums1 is greater than length of nums2.
So one of the straight forward approach will be to store all the elements to an extra space like ArrayList, sort that ArrayList and then put back all the elements to nums1. In this case, we are actually applying sorting which makes **NlogN **complexity where N = m + n.
But let us again recheck, do we actually need an extra space and do additional sorting as we already have 2 sorted array.
More optimised way will be to use 3 variables say i, j, k where
```
i = m - 1
j = n - 1
k = m + n - 1
```
Now just have a traversal until i greater than or equal to 0 and j greater than or equal to 0 and do a check for the following :

```
-> if nums1[i] is greater than nums2[j], store nums1[i] to nums1[k] and decrease i and k.
-> else store nums2[j] to nums1[k] and decrease j and k.
```
There can be cases where there are some left out elements in nums2. So just make sure we cover all elements with an extra while loop until j ≥ 0 and store those elements to nums[k] as those will be the largest numbers that are remaining with us to be merged.

## Time and Space Complexity

Here we are traversing through the arrays of length m and n. So our time complexity will be **O(m + n)**.

We are not making use of any extra space. So our space complexity will be **O(1)**.

> Please correct me if I made any mistake.

## Code


![Java Code](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zy3f3wiw7vdgsh003xl9.png)

{% embed https://github.com/Rohithv07/LeetCodeTopInterviewQuestions %}
Culture Map: Why we still need to talk about diversity
Published: 2022-06-07 14:12:40

I thought I was getting sick and tired of all the talk of diversity in tech.

I now think we have not even started the conversation about the REAL diversity, with cultural differences being a prime example of it.

Someone's cultural background will have a HUGE impact on the way they communicate, share feedback, make decisions, treat hierarchies and view deadlines. One would think EVERYONE would be studying this in order to create highly functional teams and profitable businesses. 

One would be wrong.

Watch this video to learn why you (and your manager) should read "The Culture Map" by Erin Meyer.

{% embed https://youtu.be/bSdm4sd5sh4 %}
Solving For Binary Gap Using JavaScript
Tags: javascript, webdev, tutorial, codility
Published: 2022-06-07 14:04:40

Here's a step by step solution to solving the binary gap challenge on codility. Hope it helps!

**QUESTION**


A binary gap within a positive integer N is any maximal sequence of consecutive zeros that is surrounded by ones at both ends in the binary representation of N.

For example, number 9 has binary representation 1001 and contains a binary gap of length 2. The number 529 has binary representation 1000010001 and contains two binary gaps: one of length 4 and one of length 3. The number 20 has binary representation 10100 and contains one binary gap of length 1. The number 15 has binary representation 1111 and has no binary gaps. The number 32 has binary representation 100000 and has no binary gaps.

Write a function:

function solution(N);

that, given a positive integer N, returns the length of its longest binary gap. The function should return 0 if N doesn't contain a binary gap.

For example, given N = 1041 the function should return 5, because N has binary representation 10000010001 and so its longest binary gap is of length 5. Given N = 32 the function should return 0, because N has binary representation '100000' and thus no binary gaps.

Write an efficient algorithm for the following assumptions:

N is an integer within the range [1..2,147,483,647].

**BREAKDOWN**
Our example here is the number 10041
To solve this we need to have pointers i and j which will help us count the number of 0's.

After that we need to :
1. Convert the binary number 10041 to string
2. Initiate pointers i & j
3. Set pointers i & j to 0
4. Increment j until it hits a 1
5. When j hits a 1, set the value of i to be equal to j (i=j)
6. Store the value of (j-i-1) which is the value of the count of the first set of 0's
7. Repeat for the entire array

**SOLUTION CODE**
Here's the code solution from the breakdown above:
```
function solution(N){

    
    let binaryN = (N >>>0).toString(2);  //Changes the binary number to string 
    
    let maxGap = 0;                     //sets the maximum number of binary gaps to 0

    for(let i = 0; i<binaryN.length; i++){                //sets the counter i to zero and loops through the entire binary length while incrementing by 1 
        
        for(let j=i; j<binaryN.length; j++){             //sets the counter j to i and loops through the entire binary length while incrementing by 1 
            
            if(binaryN[i] == 1 && binaryN[j] && i!=j){  //checks whether both i and j are equal to 1 but not equal to each other
                
                if(maxGap< j-i-1){                     //Calculates the maximum gap
                    
                    maxGap = j-i-1;
                }
                i=j;
            }
        }
    }
    return maxGap;
}
```
Number of Segments in a String
Tags: leetcode, dsa, theabbie
Published: 2022-06-07 14:00:45

Given a string `s`, return _the number of segments in the string_.

A **segment** is defined to be a contiguous sequence of **non-space characters**.

**Example 1:**

**Input:** s = "Hello, my name is John"
**Output:** 5
**Explanation:** The five segments are \["Hello,", "my", "name", "is", "John"\]

**Example 2:**

**Input:** s = "Hello"
**Output:** 1

**Constraints:**

*   `0 <= s.length <= 300`
*   `s` consists of lowercase and uppercase English letters, digits, or one of the following characters `"!@#$%^&*()_+-=',.:"`.
*   The only space character in `s` is `' '`.

**SOLUTION:**

    class Solution:
        def countSegments(self, s: str) -> int:
            prev = None
            ctr = 0
            for c in s:
                if (prev == None or prev == " ") and c != " ":
                    ctr += 1
                prev = c
            return ctr
I Have Made A Free Reactjs Waitlist Template With Light and Dark Theme
Tags: react, frontend, template, free
Published: 2022-06-07 13:56:42

---
title: I Have Made A Free Reactjs Waitlist Template With Light and Dark Theme
published: true
description: Free reactjs Waitlist Template with light and dark theme, Styled Components for styling, Structural and cleaner code
tags: reactjs, frontend, template, free
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8m76mpw20stx6et43ab7.png---

[GitHub](https://github.com/AbdulBasit313/waitlist-templates)

[Live Preview](https://waitlist-templates.web.app/)

### Current Version

- Styled Components for styling
- Structural and cleaner code
- Isolated components, most of them can be used in any of your projects
- No hard-coded color, we are using a theme file for colors
- We used `site data` or `dummy data` folder for `navbar`, `footer`, and other components data

### Future Updates

- I am working on one more variant of the template
- I may also add `backend` soon, so users can track who signup

If this template helps you in any way, please consider giving it a star on `GitHub`.

I would appreciate your feedback.
Como "fatiar" ("chunk") Lists ou Enumerable em pedaços menores em C#
Tags: csharp, programming
Published: 2022-06-07 13:48:36

Hoje vou compartilhar um pequeno trecho de código em C# que permite que você "fatie"  ou (crie um "chunk" de) uma lista em n listas menores utilizando Linq. 

O código "fatia" um  Enumerable em C# em um tamanho especificado, se a lista dada não puder ser dividida uniformemente, o pedaço final conterá os elementos restantes.

```
using System.Collections.Generic;
using System.Linq;

public static class ListHelper{
  public static List<List<T>> ChunkList<T>(IEnumerable<T> data, int size)
  {
    return data
      .Select((x, i) => new { Index = i, Value = x })
      .GroupBy(x => x.Index / size)
      .Select(x => x.Select(v => v.Value).ToList())
      .ToList();
  }
}

//Exemplo
List<int> numList = new List<int> { 1, 2, 3, 4, 5 }; 
ListHelper.ChunkList(numList, 3); // { {1, 2, 3}, {4, 5} }
```