teleren/devto huggingface dataset:
LeetCode 1011. Capacity To Ship Packages Within D Days
(javascript solution)
Tags: algorithms, javascript
Published: 2021-05-11 06:18:40

###Description:
A conveyor belt has packages that must be shipped from one port to another within D days.

The ith package on the conveyor belt has a weight of weights[i]. Each day, we load the ship with packages on the conveyor belt (in the order given by weights). We may not load more weight than the maximum weight capacity of the ship.

Return the least weight capacity of the ship that will result in all the packages on the conveyor belt being shipped within D days.

###Solution:
Time Complexity : O(n^2log(n))
Space Complexity: O(1)

```javascript
   // Binary search approach
var shipWithinDays = function(weights, D) {
    function getDays(capacity) {
        let days = 1, total = 0;
        
        // See how many days it will take to unload all the weights given the current capacity
        for(let n of weights) {
            total += n;
            // Increase days only when we will exceed the capacity
            if(total > capacity) {
                total = n;
                days++;
            }
        }
        return days;
    }
    
    // Start is the minimum capacity of one day which is the max of all the weights
    // End is the max capacity we could load on one day which is the sum of all the weights
    let start = Math.max(...weights), 
        end = weights.reduce((acc, cur) => acc + cur, 0);
    
    // The min cacpaity needed is between start and finish
    while(start < end) {
        const mid = Math.floor((end+start)/2);
        // See how many days it would take to unload all the weigths given mid as the current capacity
        const days = getDays(mid);
        // If capacity at mid took more than D days to load, then we can add more weigth on the ships each day which means we need to increase the daily capacity
        if(days > D) start = mid+1;
        // mid might be our answer so we cannot set end to mid-1
        else end = mid;
    }
    return end;
};
```
Google vs IBM Data Analyst Certificate- Which is Better?
Tags: datascience, analytics, analyst, python
Published: 2021-05-11 06:09:38

**Google Data Analytics and IBM Data Analyst** are the certification programs for Data Analysts. Both certification programs have their own identification and popularity. And many people get confused about which one to choose? 

That’s why I have written this article and compared Google Data Analytics and IBM Data Analyst in various aspects. So read this comparison- **Google Data Analytics Certification vs IBM Data Analyst** and then decide which one is better for you.

So, without any delay, let’s get started.

Before going into details, let’s have a quick comparison between both certification programs-
**[Click to continue reading...](https://www.mltut.com/google-data-analytics-certification-vs-ibm-data-analyst/)**
อาร์เรย์ golang 
Tags: go, array
Published: 2021-05-11 05:57:08

#อาร์เรย์คืออะไร
ถ้าคิดไม่ออกให้นึกถึงห้องแถวที่เรียงต่อกัน แต่ละห้องคืออาร์เรย์หนึ่งช่องเอาไว้เก็บของหนึ่งชิ้น และเราจะเริ่มนับห้องแรกเป็นตำแหน่งที่ 0 (ไม่ใช่ 1 นะ) ถ้าเรามีห้องแถวสิบห้อง แสดงว่าเรามีตำแหน่งเก็บของตั้งแต่ 0 ถึงตำแหน่งสุดท้ายคือ 9 รวมเป็นสิบตำแหน่ง

# การประกาศอาร์เรย์
ตัวแปรอาร์เรย์ในโกใช้วงเล็บก้ามปู `[n]type` คล้ายในภาษาส่วนใหญ่
แน่นอนว่าตัวแปรอาร์เรย์ต้องระบุขนาด `n` ด้วยว่าจะให้อาร์เรย์มีขนาดเท่าไร

```go
var langs [3]string    // อาร์เรย์ langs เก็บของเป็น string ขนาด 3 ช่อง
var ages [5]int        // อาร์เรย์ ages เก็บของเป็น int ขนาด 5 ช่อง
```

ถ้าเรามี type อื่นๆก็สามารถประกาศเป็นอาร์เรย์ได้เหมือนกัน

```go
type User struct {
    Name string
    Age  int
}
```

ประการอาร์เรย์ของ User 
```go
var u [10]User
```
**อาร์เรย์ในโกประกาศแล้วพร้อมใช้งานเลยนะ**
อ่านค่าในอาร์เรย์สามารถระบุตำแหน่งที่อยากจะอ่านค่าภายในเครื่องหมาย `[]` 
เช่นอยากอ่าน อยากรู้ว่าในห้องแถวห้องแรกเก็บค่าอะไรไว้ (อาร์เรย์ช่องแรก)
```go
var langs [3]string 
n := langs[0]
fmt.Printf("ค่าที่เก็บอยู่ในอาร์เรย์ช่องแรกคือ %q\n", n)
```
อาร์เรย์ในโกจะทำการใส่ค่าเริ่มต้น ([zero value](https://tour.golang.org/basics/12)) ให้กับอาร์เรย์ทุกช่องโดยอัตโนมัติจึงทำให้อาร์เรย์พร้อมใช้งาน (ค่าเริ่มต้นของ string คือ "" empty string)


ใส่ค่าหรือเปลี่ยนแปลงค่าในอาร์เรย์
```go
langs[0] = "gopher" // เอาคำว่า "gopher" ไปเก็บในอาร์เรย์ช่องที่หนึ่ง
n := langs[0]       // อ่านค่าจากอาร์เรย์ช่องที่หนึ่ง
fmt.Printf("ค่าที่เก็บอยู่ในอาร์เรย์ช่องแรกคือ %q\n", n)
```

### กำหนดค่าเริ่มต้นตอนประกาศได้ด้วย
โดยใช้เครื่องหมาย `=` แล้วใส่ค่าที่เราต้องการเข้าไป โดยการใส่ชื่อ type แล้วตามด้วย ปีกกา `{}` เราสามารถใส่ค่าเข้าไปในปีกกา คั่นด้วย `,` คอมม่า
```go
var langs [3]string 
langs = [3]string{"gopher", "Pythonistas", "F#"}
```

##หาขนาดของอาร์เรย์
เราสามารถใช้คำสั่ง `len` เพื่อหาขนาดของอาร์เรย์ได้เช่นกัน

```go
l := len(langs)
fmt.Println("อาร์เรย์ langs มีขนาด", l)
```

#สำคัญ
ในโกขนาดของอาร์เรย์ถือว่าเป็นคุณสมบัติของ type ด้วย
หมายความว่าอาร์เรย์ที่เก็บของชนิดเดียวกันแต่คนละขนาดถือว่าเป็นคนละ type กัน
(ซึ่งทำให้ array ใน โก ปลอดภัยในการใช้งานมากๆ) เช่นถ้าเรามีฟังก์ชั่นชื่อว่า Dubnaew (ดับแนว) รับอาร์เรย์ที่เก็บสตริงขนาด 3

```go
func Dubnaew(ns [3]string) {
	fmt.Println(ns)
}
```

```go
langs := [3]string{}
Dubnaew(langs)

cords := [5]string{}
Dubnaew(cords) // compile error : cannot use cords (type [5]string) as type [3]string in argument to Dubnaew
```


#โบนัส
ใช้ for loop กับ array ก็ได้นะ 

```go
for i := 0; i < len(langs); i++ {  // วนลูปด้วย index (ตำแหน่ง)
      val := langs[i]
      fmt.Println(val)
}
```

```go
for i, val := range langs {  // วนลูปด้วย for range เอาทั้ง index และ ค่าที่อยู่ใน index นั้น
	fmt.Println(i, val)
}
```

```go
for _, val := range langs {  // วนลูปด้วย for range เอาแค่ค่าของแต่ละช่อง
	fmt.Println(val)
}
```

```go
for i := range langs {  // วนลูปด้วย for range เอาแค่ index
      val := langs[i]
      fmt.Println(i, val)
}
```
window manager (i3wm) screen share solution
Tags: linux
Published: 2021-05-11 04:43:39

With a desktop manager like windows and macOS, you can choose specific windows to share. But that is not an option in windows manager like i3. There is an advanced sharing option on zoom to only share part of the screen. Currently it is not working in my linux distro. So is there a way to work around this without second screen or complicated config?

Window managers usually have a notion of workspace that refers to windows groupings. You can only show the programs you need in a standalone workspace if you don't want to show your entire desktop. This is essentially equivalent to showing only one windows. In i3wm, all you need is to send the the current window to a certain workspace you are prepared to share. In i3, you can add the following command to you `config` file:
```
bindsym $mod+Shift+1 move container to workspace 1
bindsym $mod+Shift+2 move container to workspace 2
```
This will allow you to send the current window to a designated workspace.

However, if you have a larger monitor, font size could be a problem. If you want to share cli program, changing the terminal font is the most convenient option. Most terminal have commands for this functionality. In gui program, this should be more straight forward. 

So when you need to share screen, first create an empty workspace, then send the windows to the new workspace, finally adjust the font size for the audience to see more clearly.
Cara Memberi Warna Code Pada GitHub Markdown
Tags: github, markdown, trivial
Published: 2021-05-11 04:32:04

TL;DR 
Pakai syntax berikut ini.

![alt text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8jwatixmok5nn9l72xq5.png)


Tadi pagi sehabis sahur saya iseng-iseng kontribusi repo orang, nggak banyak sih yang saya ubah, cuma meng _improve_ penjelasan di README aja yang cukup membingungkan. 


Lalu saya lihat ada potongan kode aneh pada markdown nya, pasti kalian taulah apa itu markdown, saya nulis postingan ini juga pake markdown hehe. In case aja nih kalau ada yang nggak tau markdown.

> *Markdown is a lightweight markup language for creating formatted text using a plain-text editor. John Gruber and Aaron Swartz created Markdown in 2004 as a markup language that is appealing to human readers in its source code form.* 

Intinya fungsi markdown adalah menggantikan kode2 seperti HTML agar mudah dibaca orang awam.

Anyway, balik lagi ke cara mewarnai kodingan, 
langsung saja saya kasih syntaxnya kurang lebih seperti ini.

![alt text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ph2m6jm9doj95uwzo0qx.png)
 
Kalian juga bisa mengganti `javascript` dengan bahasa pemrograman apapun, bisa juga dengan `console`, `python`, dan lain-lain.

Maka markdown github akan langsung mengenali syntax javascript, hasil dari syntax tersebut akan berwarna seperti ini.


![alt text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vt95j7ksigr3fissyqfl.png)
Remove automatic zoomIn of inputs on IOS
Published: 2021-05-11 04:28:55

Hello, First post here.

I decided to use this platform to write reminders for myself, and quick tips to help everyone during daily development.

Today I had to face a problem on IOS where Safari decides to auto zoom on inputs when user click on them.

This happens when the font-size is considered too small by Apple (because yes, they decide what they want for you always right ?) which is apparently 16px.

Anyway, after searching over the internet for quite some times, and finding posts ranging from 2014 to today, I ended up with this simple solution.

```
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
    <script>
      const el = document.querySelector('meta[name=viewport]');
      const isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !('MSStream' in window);
      if (isIOS) {
        const metaViewport = document.querySelector('meta[name=viewport]');
        metaViewport.content =
          'width=device-width, initial-scale=1, shrink-to-fit=no, minimum-scale=1, maximum-scale=1';
      }
    </script>
  </head>
```

The important part is to add `minimum-scale=1, maximum-scale=1` **ONLY** for IOS. This will allow your users on desktop/android/iOs to correctly use the app without affecting their ability to manually zoom. And remove only the automatic zoom behavior of Apple devices.

Hope this helps

You can find a lot of ideas on this SO post (included the answer I followed)

https://stackoverflow.com/questions/2989263/disable-auto-zoom-in-input-text-tag-safari-on-iphone
49 Days of Ruby: Day 45 -- Intro to Testing
Tags: ruby
Published: 2021-05-11 04:20:47

---
title: 49 Days of Ruby: Day 45 -- Intro to Testing
published: true
description: Join us on a 49 day learning journey through Ruby!
series: 49 Days of Ruby
tags: #ruby
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/9m73qaetuse3nm3y3it8.png
---

**Welcome to day 45 of the 49 Days of Ruby! 🎉**

For the past 44 days, we have discussed writing code. Today, we will discuss testing your code!

Over the next several days we will look at different ways to test your code in Ruby.

However, before we start discussing *how*, it's important to discuss *why*. Why should you test your code?

This question gets asked a lot because especially when you first start writing tests, the writing of the tests can often take longer than the writing of the code! It can seem like a big use of your time and for not a lot of immediate benefit.

## Why Test Your Code

The most fundamental reason why you should test your code is no one is perfect.

You are not perfect.

The writers of gems your code relies upon are not perfect.

The API engineers of the external APIs your code relies upon are not perfect.

No one is perfect.

That means that while you may think you got everything down right, you may have missed one letter in a variable, or forgot to put a semicolon. Perhaps, an API engineer released a new version of an API endpoint and unintentionally broke your code.

How do you know when a mistake happens? Well, you could know when you run the code and something breaks.

However, depending on running the code means that you will often put things out there that don't work, and you want to avoid that. Hence, building tests.

Tests give you confidence that your code, at least at the time of writing the test, works. 

## What kind of tests?

Typically, when you are going to write tests you want to test a couple of different things:

* Success Routes
* Failure Routes

A success route is what you expect to happen when things go well. If method A does something with input X and returns an output of Y, I want to test that those are the case.

A failure route is what you expect to happen when things go wrong. A user puts in the wrong input. The API returned an error code, etc. 

It is important to test both routes because you want your code to be able to handle both circumstances.

Now that we have a sense of why you should test, tomorrow we'll start looking at Ruby testing frameworks!

**Come back tomorrow for the next installment of 49 Days of Ruby! You can join the conversation on Twitter with the hashtag [#49daysofruby](https://twitter.com/hashtag/49daysofruby).**
Iterating Through All an Array's Items Using For Loops
Tags: javascript, devops, tutorial, beginners
Published: 2021-05-11 04:10:32

* Sometimes when working with arrays, it is very handy to be able to iterate through each item to find one or more elements that we might need, or to manipulate an array based on which data items meet a certain set of criteria. The technique which is most flexible and offers us the greatest amount of control is a simple for loop.
* Ex: I have defined a function, `filteredArray`, which takes `arr`, a nested array, and `elem` as arguments, and returns a new array. `elem` represents an element that may or may not be present on one or more of the arrays nested within `arr`. Let's modify the function, using a for loop, to return a filtered version of the passed array such that any array nested within `arr` containing `elem` has been removed.
```
function filteredArray(arr, elem) {
  let newArr = [];
  // Only change code below this line

  // Only change code above this line
  return newArr;
}

console.log(filteredArray([[3, 2, 3], [1, 6, 3], [3, 13, 26], [19, 3, 9]], 3));
```
* Answer:
```
function filteredArray(arr, elem) {
  let newArr = [];

for (let i = 0; i < arr.length; i++) {
  let outer = arr[i];
  if (outer.indexOf(elem) === -1) { 
     //Checks every parameter for the element and if is NOT there continues the code
    newArr.push(outer); //Inserts the element of the array in the new filtered array
  }
}
  return newArr;
}
```
```
console.log(filteredArray([[10, 8, 3], [14, 6, 23], [3, 18, 6]], 18)); will display [[10, 8, 3], [14, 6, 23]]
```
Exploring Data in Pandas Using GroupBy
Tags: python, datascience
Published: 2021-05-11 04:05:38

#Importing and Parsing
>>>Import pandas as pd
df = pd.read_csv('file_name.csv')

#Checking the mean of all attributes (columns) in a data set
>>>df.mean()

#Finding the mean of attributes when holding one attribute as an index
_I.e: Here, I want to find the mean of all the other attributes with each occurence of the petal length attribute._
>>>df.groupby('petal_length').mean()

#We can even add multiple entries to hold as an index
>>>df.groupby(['petal_length', 'color']).mean()

#If we don't want the attributes we choose to be made as an index, we can use as_index=false:
>>>df.groupby(['petal_length', 'color'], as_index=False).mean()

#And finally, if we are interested in only one attribute (column) we can index it as follows:
>>>df.groupby(['petal_length', 'color'], as_index=False)['petal_width'].mean()
Node.js : Scopes and repositories
Tags: node, npm, webdev, javascript
Published: 2021-05-11 04:02:11

Set the repository for the scope "myscope"
```
npm config set @myscope:registry http://registry.corporation.com
```

Login at a repository and associate it with the scope "myscope"
```
npm adduser --registry=http://registry.corporation.com --scope=@myscope
```

Install a package "mylib" from the scope "myscope"
```
npm install @myscope/mylib
```

All together will be -
```
# Set the repository for the scope "myscope"
npm config set @myscope:registry http://registry.corporation.com
# Login at a repository and associate it with the scope "myscope"
npm adduser --registry=http://registry.corporation.com --scope=@myscope
# Install a package "mylib" from the scope "myscope"
npm install @myscope/mylib
```

If the name of your own package starts with @myscope and the scope "myscope" is associated with a different repository, `npm publish` will upload your package to that repository instead.

You can also persist these settings in a `.npmrc` file:
```
@myscope:registry=http://registry.corporation.com
//registry.corporation.com/:_authToken=xxxxxxxx-xxxx-xxxx-xxxxxxxxxxxxxxx
```
This is useful when automating the build on a CI server

<a href="https://www.buymeacoffee.com/rkycom" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" style="height: 60px !important;width: 217px !important;" ></a>

With all that being said, I highly recommend you keep learning!

Thank you for reading this article. Please feel free to connect with me on [LinkedIn](https://www.linkedin.com/in/www-rajeshkumaryadav-com/) and [Twitter](https://twitter.com/rky_com).
Group Video Chat: ReactJS & WebRTC
Tags: react, webrtc, socketio, peer
Published: 2021-05-11 04:00:13

Recently did some POC's around WebRTC for video calling purpose.

Here's a working demo hosted on heroku https://videocall-reactjs-webrtc.herokuapp.com/

Here's the code https://github.com/harshalrj25/VideoCall-ReactJS-WebRTC

The demo is created using P2P MESH communication architecture hence beyond 4 users the solution won't scale properly.

There are other WebRTC architecture's like SFU which requires a media server.

Exploring further will try and implement an SFU architecture for better understanding of WebRTC.
Node.js : Updating NPM and packages
Tags: node, webdev, devops, programming
Published: 2021-05-11 03:51:45

Since npm itself is a Node.js module, it can be updated using itself.
If OS is Windows must be running command prompt as Admin
```
npm install -g npm@latest
```
If you want to check for updated versions you can do:
```
npm outdated
```

In order to update a specific package:
```
npm update <package name>
```
This will update the package to the latest version according to the restrictions in `package.json`

In case you also want to lock the updated version in `package.json`:
```
npm update <package name> --save
```

<a href="https://www.buymeacoffee.com/rkycom" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" style="height: 60px !important;width: 217px !important;" ></a>

With all that being said, I highly recommend you keep learning!

Thank you for reading this article. Please feel free to connect with me on [LinkedIn](https://www.linkedin.com/in/www-rajeshkumaryadav-com/) and [Twitter](https://twitter.com/rky_com).
Check For The Presence of an Element With indexOf()
Published: 2021-05-11 03:48:16

* Since arrays can be changed, or mutated, at any time, there's no guarantee about where a particular piece of data will be on a given array, or if that element even still exists. Luckily, JavaScript provides us with another built-in method, `indexOf()`, that allows us to quickly and easily check for the presence of an element on an array. `indexOf()` takes an element as a parameter, and when called, it returns the position, or index, of that element, or `-1` if the element does not exist on the array.
* Let's say for example, I have defined a function, `quickCheck`, that takes an array and an element as arguments. Modify the function using `indexOf()` so that it returns `true` if the passed element exists on the array, and `false` if it does not. `indexOf()` can be incredibly useful for quickly checking for the presence of an element on an array.
```
function quickCheck(arr, elem) {
  // Only change code below this line

  // Only change code above this line
}

console.log(quickCheck(['squash', 'onions', 'shallots'], 'mushrooms'));
```
* Answer:
```
function quickCheck(arr, elem) {
  if (arr.indexOf(elem) === -1) {
    return false;
  } else {
    return true;
  }
}

console.log(quickCheck(["onions", "squash", "shallots"], "onions")); will display true because 'onions` is found in the arr
```
Node.js: Listing currently installed NPM packages
Tags: node, npm, webdev, developer
Published: 2021-05-11 03:47:07

To generate a list (tree view) of currently installed packages, use
```
npm list
```
`ls`, `la` and `ll` are aliases of list command. `la` and `ll` commands shows extended information like description and repository.

# Options
The response format can be changed by passing options.
```
npm list --json
```
* `json` - Shows information in json format
* `long` - Shows extended information
* `parseable` - Shows parseable list instead of tree
* `global` - Shows globally installed packages
* `depth` - Maximum display depth of dependency tree
* `dev/development` - Shows devDependencies
* `prod/production` - Shows dependencies

If you want, you can also go to the package's home page.
```
npm home <package name>
```
<a href="https://www.buymeacoffee.com/rkycom" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" style="height: 60px !important;width: 217px !important;" ></a>

With all that being said, I highly recommend you keep learning!

Thank you for reading this article. Please feel free to connect with me on [LinkedIn](https://www.linkedin.com/in/www-rajeshkumaryadav-com/) and [Twitter](https://twitter.com/rky_com).
Codeforces Tracker
Tags: codeforces, competitveprogramming, productivity
Published: 2021-05-11 03:43:21

# What is this site?
[cf-tracker][cf-tracker] is a website for monitoring progress on [codeforces.com][codeforces] in terms on which questions were solved in contests. 
There are two types of questions to keep track on:
- The ones that were solved during the contest.
- The ones that were not solved during or after the contest[problems to upsolve later].

It also provides feature to filter contests based on division[div1, div2, div3, Educational Rounds], and is pretty damn quick about it.

![cf-tracker website](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/69lz2ssqsjk8hwomic9f.png)

# How can one use it?
- To upsolve problems.
- To find contests that you haven't participated in before and practice on them.
- Filter contests based on divisions for practice.

# How is this site built?
- The site is built entirely using [Vue.js][vue-js].
- It uses [codeforces api][codeforces-api] for fetching information.
- The contests information is statically stored as a `json` file, for improving the speed. 
- To update the contests information there is python script written.
- The site is hosted using [Github Pages][github-pages].

# Can I look at the source code?
Sure, the site is completely open-source. You can find it [here][github-cftracker].

# What features are coming next on it?
- To keep the search and filter bar of the top steady if when you scroll down.
- Refresh button to get latest data on problems solved by the user.
- Proper error message for user, in case the codeforces website is down.
- Improve the UI.
- Pagination of problems.

Suggestions to improve the website are always welcome. If any issues found please raise it on the github repository.

Thank you! Enjoy the site!


[cf-tracker]: https://cf-tracker.tech
[codeforces]: https://codeforces.com
[vue-js]: https://vuejs.org/
[github-pages]: https://pages.github.com/
[codeforces-api]: https://codeforces.com/apiHelp
[github-cftracker]: https://github.com/geekypandey/cf_tracker