teleren/devto huggingface dataset:
Do you need to be good at math to learn programming?
Tags: math, programming, learn
Published: 2020-09-20 05:07:02

It is a question often asked by people considering to learn a programming language. “Do I need to be good at math to learn Javascript, or C, Java, or any other language?” The reason they are most likely asking this question is because they’re either really good or bad at math so they want to know if this instantly disqualifies them or gives them an advantage. As a programmer with over 20 years experience, I’ve seen this asked and been personally asked this very question countless times and I’d love to say that my answer has been consistent but it hasn’t.

Programming is very hard, I don’t want it to sound easy, so when asked a question like this I have the urge to just say yes, to make it sound hard and make myself sound smart. If I were to say no, then I might be trivializing how hard my job is. I’m not alone on this, this question is asked constantly online and the answer almost always is “you should at least be able to calculate X times Y to be able to be a programmer”, or worse, “you should know this formula or that algorithm”.

The fact is that programming is not math, it’s a science. Anyone who says you need to be good at math is gatekeeping. Knowing how to multiply has nothing to do with programming. Though programming is not math, it does contain math sometimes. It’s clear that sometimes people who struggle in programming are really good at general math, and sometimes people who are good at programming are really bad at general math. Every combination of skillset exists in the field and they are perfectly capable of developing different types of software.

With that said, some types of software development do require a lot of math such as some types of 3d game design, graphics, simulators, etc. Also sometimes it can help you to write better code when you know a math formula that can be applied to save on data storage and performance. This is an issue I see from time to time with programmers who are senior level, they will use database tables and do all sorts of manual processing to achieve something that could have been solved by a simple algorithm. But the bottom line is they still managed to become senior programmers without being great at math because they get the job done, which is what matters most.

So the answer is no, you don’t need to be good at math to start learning to program. Knowing some math formulas can help you down the road to write better code or might be required to be able to do a task but you can learn that on the spot when you need it. Obviously, it’s more ideal to know math, you will have an advantage but in no way is it a limiting factor. It might even make you appreciate math more and want to be better at it, so please don’t see it as a limitation any more.

Medium link: https://medium.com/@andyware/do-you-need-to-be-good-at-math-to-learn-programming-c0b69caad853
Do you write tests when exploring a new idea?
Tags: discuss, tdd, testing
Published: 2020-09-20 07:51:45

---
title: Do you write tests when exploring a new idea?
published: true
description: A discussion on when to write tests when exploring a new project, prototype, or idea.
tags: discuss, tdd, testing
---

Hi!

I've been toying with a new project idea and have spent half a day doing [exploratory programming](https://wiki.c2.com/?ExploratoryProgramming) to see how the different components would come together. I did cover a lot of ground, and in fact I'm probably going to pursue this project after a few more rounds of exploration.

This is in contrast to my usual workflow where I follow rigorous [TDD](https://en.wikipedia.org/wiki/Test-driven_development). Now I find myself asking this question: when would be a good time to stop writing code, do some housekeeping, and start to build a test suite?

If you have had a similar experience before, I'm very curious on how you approached this scenario.

1. Do you follow TDD, perhaps a _lighter version_, when exploring new ideas?
2. If not, when do you start writing tests for the validated idea?
3. Either way, at what point of these kinds of projects do you start configuring the _"nice to haves"_ (linter config, coverage frameworks, pre-commit hooks etc)?

I'm really eager to hear your thoughts. Stay safe!
Redux에 custom hook으로  Computed value 달아주기
Tags: react, redux, javascript, typescript
Published: 2020-09-20 07:46:07

React를 쓰는 많은 분들이 프로젝트를 시작하기 전 첫 번째로 고민하게 되는 기술스택이 글로벌 상태관리 라이브러리 `redux` 와 `mobx` 중 어떤 것을 선택할까가 아닐까 합니다.
깃헙 스타수로 보면 리덕스의 인기가 좀 더 많은 것을 알 수 있습니다. 저도 리덕스를 주로 쓰지만 `mobx` 의 장점 중 하나는 데코레이터 문법과 computed value 에 있다고 생각합니다.

```javascript
@computed get discountedPrice() {
  return this.price * this.discount
}
```
이런식으로 `store`에 데코레이터 문법으로 getter를 달아주는 방식입니다. `redux`에는 api가 없지만 `reselect` 라는 라이브러리를 통해서 비슷한 방식을 구현할 수 있습니다.
이제 `react`에 훅이 도입되면서 추가 라이브러리 없이도 computed value를 쉽게 구현할 수 있게 되었습니다.

스토어 `fruitStore`에 서버로부터 과일의 할인율과 가격 데이터를 받아 저장되어 있다고 해보겠습니다.

```typescript
const initialState: FruitStore = {
  apple: { discount: 0.03, price: 1000 },
  orange: { discount: 0.12, price: 3000 },
  grape: { discount: 0.2, price: 8000 },
  ...
};
```

저장된 데이터는 `Tag` 컴포넌트에 3가지 방법으로 표현됩니다.
1. 할인된 가격을 표현해줍니다.
2. 할인이 적용된 최종 결제가격을 보여줍니다.
3. 할인율을 읽기 쉽게 %로 보여줍니다.

데이터를 view에 표현하기 위해서는 항상 아래와 같이 값을 변환해주어야 합니다.

```typescript
const discountedPrice: number = price * discount;
const billingPrice: number = price * (1 - discount);
const discountPercent: string = `${discount * 100} %`;
```

만약에 위의 데이터를 쓰는 컴포넌트가 여러개라면 각 컴포넌트마다 같은 코드를 복사/붙여넣기 해야 할 것이고 유지보수하기도 점점 어려워질 것입니다.
스토어에서 3가지 데이터를 모두 저장하는 것도 생각해볼 수 있습니다. 하지만 이런 경우에 nested 된 형태로 스토어를 관리해야 될 가능성이 높아지고, view의 형태가 다양해지면 복잡성이 기하급수적으로 커지게 됩니다.

커스텀훅과 `useMemo`를 조합해 computed value를 구현해보겠습니다.

```javascript
// custom hook
function useFruitTag(fruit: string) {
  const { discount, price } = useSelect(({ fruitStore }) => fruitStore[fruit]);

  const discountedPrice = useMemo(() => price * discount, [discount, price]);
  const billingPrice = useMemo(() => price * (1 - discount), [discount, price]);
  const discountPercent = useMemo(() => `${discount * 100} %`, [discount]);

  return {
    discountedPrice,
    billingPrice,
    discountPercent,
  };
}

// component
function AppleTag() {
  const { discountedPrice, billingPrice, discountPercent } = useFruitTag('apple');

  return (
    <div>
      <h1>Apple</h1>
      <p>{discountedPrice}</p>
      <p>{billingPrice}</p>
      <p>{discountPercent}</p>
    </div>
  );
}
```

이런 방식으로 `reselect`나 `@computed` 없이도 computed value를 쉽게 만들어 쓸 수 있습니다. `useMemo`를 이용해서 캐싱된 값을 쓰기도 쉽고, 과일의 종류가 늘어나거나 대응해야 하는 view가 늘어나더라도 쉽게 처리할 수 있습니다. 무엇보다 관심사별로 로직이 분리되면서 코드를 읽기 쉬워진다는 게 가장 큰 장점인 것 같습니다.


p.s
`useMemo`가 `reselect`를 완전히 대체한다는 뜻은 아닙니다. 관련된 내용은 <U>[여기](https://github.com/reduxjs/reselect/issues/386)</U> 에 잘 설명되어 있습니다.
A program of calc sum ➕ with new and smart code  in JavaScript 🔥.
Tags: javascript, functional, challenge
Published: 2020-09-20 07:20:18

# Create function in JavaScript that's takes single arguments and return sum of all previous arguments without using global variable.

## Here we always try to find short and smart 🏆 code for doing same task.

### First we try to do this task with simple approach then move forward.

> When we create diagram in mind first we think to take an global variable that store data for you, But that's always a bad idea for smart 😎 developer.

```javascript

function calc() {
    // creating private valriable
    let value = 0;
    // private function
    function changeBy(val) {
        value += val;
    }
    // returning an object
    return {
        // add method 
        add: function (i) {
            changeBy(i);
        },
        // return value
        value: function () {
            return value;
        }
    }
}

// making mycalc function with calc
let mycalc = calc()

// adding number.
mycalc.add(12)
mycalc.add(15)

// print to console
console.log(mycalc.value())

// output is 27

```

### Here we seem like we have long code, and also we don't have es-6 smart features, so let's begin 🎉.


```javascript


let calc = () => {
    // creating private valriable
    let value = 0;
    // private function
    let changeBy = val => value += val;
    // returning an object
    return {
        // add method 
        add: (i) => changeBy(i),
        // return value
        value: () => value
    }
}

// making mycalc function with calc
let mycalc = calc()

// adding number.
mycalc.add(12)
mycalc.add(15)

// print to console
console.log(mycalc.value())

// still output is 27 but with smart code.

```

### Now if see code, that's pretty short.

```javascript
let calc = () => {
    let value = 0;
    let changeVal = val => (value += val);
    return {
        add: (i) => changeVal(i)
    }
}
```

### But a thing is noticeable why we use private function 😋 let's remove it.

```javascript
let calc = () => {
    let value = 0;
    return {
        add: i => value += i
    }
}
```

### We removed many lined of code to making simpler, but still we have an issue with that code. We need a function that's take arguments every time and return sum of all previous and current arguments. But when use our function we feel like we using any class methods and it's properties, let's solve this issue.

> - To solving this issue we need to wrap calc function in () parenthesis, and change the name of function calc to sum and call 
that's function in sum function 😝.
- And replace object with function in return statement.

```javascript
let sum = (
    i => {
        let v = i;
        return i => v += i
    }
)(0);
```

### Here we change many things like we don't return a object return value only, Zero is starting value of sum function.


### Now our task is Completed 
```javascript
let sum = (i => { let v = i; return i => v += i })(0);

console.log(sum(14)) /* output --> 14 */
console.log(sum(13)) /* output --> 27 */
console.log(sum(10)) /* output --> 37 */
```

final result
```javascript 
let sum = (a => b => a += b )(0)
```

😁😁😁🎉
CORONA VIRUS SPREAD 2
Tags: computerscience, cpp, codenewbie
Published: 2020-09-20 07:20:05

Another problem editorial from <b>Codechef September Long Challenge</b>.

<b>PROBLEM STATEMENT:</b>

There are N athletes (numbered 1 through N) in a line. For each valid i, the i-th athlete starts at the position i and his speed is Vi, i.e. for any real number t≥0, the position of the i-th athlete at the time t is i+Vi⋅t.

Unfortunately, one of the athletes is infected with a virus at the time t=0. This virus only spreads from an infected athlete to another whenever their positions are the same at the same time. A newly infected athlete may then infect others as well.

We do not know which athlete is infected initially. Find the size of this set, i.e. the final number of infected people, in the best and worst possible scenario.

<b>LOGIC</b>
<b><i>Case 1:</i></b> If the speed of two athletes is the same, they will never meet. So, in that case, we have surety that the virus won't spread amongst them.  

<b><i>Case 2:</i></b> If the speed of an athlete at position 4 is greater than that of an athlete at position 2, then in that case also, they will never meet.

<b><i>Case 3:</i></b> If the speed of an athlete at position 4 is lesser than that of an athlete at position 2, then, in that case, they will meet.

<b><i>Time Calculation: </i></b> Time can be calculated by the formula, (pos1 - pos2)/(speed 2 - speed1)
Now, another main point in this question is, one athlete, can only spread COVID19 to another one, only after getting infected. Hence, we can use <i>Depth First Search</i>.


<b>CODE IMPLEMENTATION</b>

Firstly, we will make a 2D vector array and traverse through the given array of athletes and calculate time if they will meet or not, if it is negative, or 0, we will fill -1 in the 2D matrix, else will fill the calculated time.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/mkrz04xbv597d7ihmgok.png)

Now we will use Depth First Search Method in the following manner to find out the maximum and the minimum number of people who can get infected.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/0704soh0dyl7me8fe85c.png)

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/hkkb6tbc2aj20uzczncd.png)

Then finally, iterate over that vector <b><i>v</i></b> and find out the maximum and minimum element which is the required answer.

That's all, Happy Coding :)
Live preview of react-app on mobile
Tags: react, webdev, beginners, codenewbie
Published: 2020-09-20 06:58:40

> Apps can be tested on browsers using the responsive view. The preview of the app can be observed from any width to any height. But to test it out on a real mobile, the app has to be deployed somewhere.  

**Note: This method would also work for apps created using other ways. I have used react hence the title.**  

---

### **The application running on your development machine can be tested out instantly on a mobile device.**

1. Both the computer and mobile device must be connected to the **same wifi network.**

2. Get the **local IP** address of the computer. My local IP address, in this case, is `192.168.29.217`
![Local IP address on Ubuntu](https://dev-to-uploads.s3.amazonaws.com/i/zaz66z389ecoqsyyzexi.png)
  I am using `ifconfig` to get the IP address on ubuntu.  
Search for Find local ip address for your specific os.

3. Get the port on which the react-app is running. ex., My app is running on **localhost:3000**

4. Go to the browser in the mobile device and enter **<local_ip>:<react_port>** For me, it would be `192.168.29.217:3000`

## **Done!**

--- 

**Thanks for reading 💙**  
Follow **@codedrops.tech** for daily posts.  
[Instagram](https://www.instagram.com/codedrops.tech/) ● [Twitter](https://twitter.com/codedrops_tech) ● [Facebook](https://www.facebook.com/codedrops.tech/)

Micro-Learning ● Web Development ● Javascript ● MERN stack ● Javascript  
**[codedrops.tech](https://www.codedrops.tech/)**
100DaysOfCode | Day 40
Tags: 100daysofcode, python, challenge, beginners
Published: 2020-09-20 06:36:44

▄█ █▀█ █▀█ █▀▄ ▄▀█ █▄█ █▀ █▀█ █▀▀ █▀▀ █▀█ █▀▄ █▀▀
░█ █▄█ █▄█ █▄▀ █▀█ ░█░ ▄█ █▄█ █▀░ █▄▄ █▄█ █▄▀ ██▄

Hey everyone, wassup?
I missed the dev community so much, I was so damn busy since 16th Sep.
I couldn't do my tasks and challenges correctly due to some problems.
You know what, something will happen in your journey that you can't expect and you need to face it and solve that problem anyway.
Sometimes it takes your energy and time, you may think that I'm not in my way anymore but that's wrong in my point of view, cause problems are part of every journey.
You'll lose your control but you try to have control again, that's what makes us stronger and wilder.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/5rj4p5ldcy8slyvpmww0.jpg)

Finally, I faced some challenges in my way but I'm still in my way and keep moving harder to achieve my fu*king goals.







#Keep Moving Forward ツ

##Enjoy Your Journey 👊

##Code with 💛

__🅑🅐🅝🅙🅘__
Designer PDF Viewer Explain - Solution | Javascript
Published: 2020-09-20 06:36:32

```javascript
function designerPdfViewer(h, word) {
  let max = 0;
  const wordSize = word.length;
  for (let i = 0; i < wordSize; i ++) {
    const current = word.charCodeAt(i);
    if (h[current-97] > max) max = h[current-97];
  }
  return max * wordSize;
}

```

```javascript
designerPdfViewer([1, 3, 1, 3, 1, 4, 1, 3, 2, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 7]
, 'zaba')
```

[Problem](https://www.hackerrank.com/challenges/designer-pdf-viewer/problem)
Fun vi shortcut to open a terminal in vi
Tags: vim, tutorial
Published: 2020-09-20 06:31:52

I prefer to use `tmux` for multiplexing terminals.  However, I just learned / figured out how to kind of make this work like I do with `tmux`.  Mind you not as flexible.

Add this snippet to `vimrc` or `init.vim` file
## init.vim
```
nmap <Leader>t :call Terminal()<CR>

function! Terminal()
  :set splitbelow
  :set splitright
  :10split
  :set laststatus=0
  :set scl=no
  :set nonu
  :term
endfunction

autocmd TermOpen * startinsert

tnoremap <Esc> <C-\><C-n> <bar> :call ExitTerminal()<CR>
function! ExitTerminal()
  :set nosplitbelow
  :set nosplitright
  :set laststatus=2
  :set scl=yes
  :set number
  :q!
endfunction

```

Now when you `<Leader>t` you will drop into a terminal in vi

## Notes
To exit use `<Esc>`
My Own Personal Website
Published: 2020-09-20 06:16:17

  So I made a personal website, [carter85.github.io](carter85.github.io). This is probably the 5th iteration of it, as I started over and over from writing it all from scratch, to finding and using using a boilerplate from [http://getskeleton.com/](getskeleton.com). I plan on learning Bootstrap later, but found skeleton to be very easy to get up and going.
  I built, deployed it to Github pages, experimented with it, found a few bugs, made a list, fixed a bug with the javascript in an offline file, copied fix to the live file, and pushed it out to the internet. And I know I've still got a long way to go, but man, it feels like I've accomplished something, it's fantastic.
Scraper API - Proxy API for Web Scraping
Tags: scraper, boxpiper, javascript, api
Published: 2020-09-20 06:09:00

[Scraper API](https://www.scraperapi.com/?fp_ref=box-piper-app) provides a proxy service designed for web scraping. With over 20 million residential IPs across 12 countries, software that can handle JavaScript rendering and solving CAPTCHAs, you can quickly complete large scraping jobs without ever having to worry about being blocked by any servers.

Implementation is extremely simple, and they offer unlimited bandwidth. Proxies are automatically rotated, but users can choose to maintain sessions if required. All you need to do is call the API with the URL that you want to scrape, and it will return the raw HTML. With Scraper API, you just focus on parsing the data, and they’ll handle the rest.

To continue reading, head over to [Box Piper](https://www.boxpiper.com/posts/scraper-api/) source.

To read more such interesting topics, follow and read <a href="https://boxpiper.com/">BoxPiper blog</a>.

Support my work and [buy me a Coffee](https://ko-fi.com/E1E72C2MM). It'll mean the world to me. 😇

<a href="https://ko-fi.com/E1E72C2MM"><img src="https://cdn.ko-fi.com/cdn/kofi1.png?v=2"/></a>
npm ci vs npm install
Tags: npm, javascript, packagemanager, boxpiper
Published: 2020-09-20 05:49:01

Starting MARCH 5, 2018, all npm users can take advantage of a new install command called `npm ci`.

**npm install** :- install new dependencies, or update existing dependencies (e.g. going from version 1 to version 2).

**npm ci** :- when you want to run continuous integration tools like Jenkins or GitLab, etc., it doesn't modify the package-lock.json file. It’s meant to be used in automated environments such as test platforms, continuous integration, and deployment – or any situation where you want to make sure you’re doing a clean install of your dependencies.

Essentially, `npm install` reads package.json to create a list of dependencies and uses package-lock.json to inform which versions of these dependencies to install. 
To continue reading, head over to [Box Piper](https://www.boxpiper.com/posts/npm-ci-vs-npm-install/) source.

To read more such interesting topics, follow and read <a href="https://boxpiper.com/">BoxPiper blog</a>.

Support my work and [buy me a Coffee](https://ko-fi.com/E1E72C2MM). It'll mean the world to me. 😇

<a href="https://ko-fi.com/E1E72C2MM"><img src="https://cdn.ko-fi.com/cdn/kofi1.png?v=2"/></a>
Divide And Conquer Algorithms With Python
Tags: algorithms, computerscience, programming
Published: 2020-09-20 05:45:33

Divide and Conquer(D&C) is a concept for data structures and algorithms that repeatedly cuts the input in half until we achieve our goal. Divide and Conquer algorithms are not too far off from dynamic programming. Where   they both recursively cut the input size in half, but the difference is if you need to calculate something and keeping track of that change, then using memoization in dynamic programming is preferred.

There are many Divide and Conquer Algorithms and we will check out when they should be used, and how they can be implemented.

##QuickSort
The QuickSort like its name suggests, is a sorting algorithm. It chooses a pivot point in which the rest of the input array gets sorted around. This pivot can be the first, last, or middle most element in the array. The runtime can vary greatly depending on what you choose your pivot point as.

python example from [GeeksForGeeks](https://www.geeksforgeeks.org/quick-sort/)
```python
def partition(arr,low,high): 
    i = ( low-1 )         # index of smaller element 
    pivot = arr[high]     # pivot 
  
    for j in range(low , high): 
  
        if   arr[j] < pivot: 
          
            i = i+1 
            arr[i],arr[j] = arr[j],arr[i] 
  
    arr[i+1],arr[high] = arr[high],arr[i+1] 
    return ( i+1 ) 

def quickSort(arr,low,high): 
    if low < high: 
  
        pi = partition(arr,low,high) 

        quickSort(arr, low, pi-1) 
        quickSort(arr, pi+1, high)
``` 

##Binary Search
This searching algorithm is the first algorithm I think of when I see Divide and Conquer. This algorithm only works if the input array is already sorted. We take in an input array and a desired number we are searching for. Then we compare to the middle most element in the array. If our desired element is less than the middle most element, then we chop off the top half of the array and repeat the process. If our element was bigger than the middle most element, then we do the opposite by only looking at the larger elements of the array.

pseudo example
```
def binarySearch(arr, desiredNum):
     mid = arr.length/2

     if(desiredNum > arr[mid])
          look at first half of array
          reset mid within scope of array
          repeat search
     else
          look at bigger half of array
          reset mid within scope of array
          repeat search
return index of element
```

##Merge Sort
Merge sort is a pretty cool sorting algorithm that splits the whole array into two until it is all split up, then slowly start sorting them together.

pseudo code from [GeeksForGeeks](https://www.geeksforgeeks.org/merge-sort/)
```
MergeSort(arr[], l,  r)
If r > l
     1. Find the middle point to divide the array into two halves:  
             middle m = (l+r)/2
     2. Call mergeSort for first half:   
             Call mergeSort(arr, l, m)
     3. Call mergeSort for second half:
             Call mergeSort(arr, m+1, r)
     4. Merge the two halves sorted in step 2 and 3:
             Call merge(arr, l, m, r)
```
Introduction, I Suppose
Published: 2020-09-20 05:20:18

    Hello! My name is Casey Carter. In 2020, I decided to move from Illinois back to my hometown in Texas, and knuckle-down and learn programming. Using [freeCodeCamp](http://freecodecamp.com) and [The Odin Project](www.theodinproject.com) as guides, so far I've learned HTML, CSS, JavaScript, Git, and a slew of other useful tricks and techniques, with a big ol' list of things still to learn.
    No promise as to how often I'll update this, but follow and when I do, well it won't be boring.
GitHub CLI 1.0
Tags: github, git, opensource
Published: 2020-09-20 05:19:59

GitHub CLI brings GitHub to your terminal. It reduces context switching, helps you focus, and enables you to more easily script and create your own workflows. 
With GitHub CLI 1.0, you can:

Run your entire GitHub workflow from the terminal, from issues through releases
Call the GitHub API to script nearly any action, and set a custom alias for any command
Connect to GitHub Enterprise Server in addition to GitHub.com
Want to know more visit the link:
https://github.blog/2020-09-17-github-cli-1-0-is-now-available/