teleren/devto huggingface dataset:
Method Chaining in PHP
Tags: php
Published: 2020-06-14 11:48:39

In this tutorial, we’ll take a look at Method Chaining in PHP. Method Chaining is nothing but the concatenation of multiple methods to increase readability of code and avoid putting all the code in the single function.

One of the major changes between PHP4 and PHP5 is that in PHP5 method can return objects. We will first see the basics of method chaining and then we’ll look into examples with explanation.

Method Chaining is mainly used to implement Fluent Interface in an object-oriented API to achieve code readability. The term Fluent Interface was first invented by Eric Evans and Martin Fowler back in 2005. Note that method chaining is not Fluent Interface. Rather Fluent Interface uses method chaining.

Using Fluent Interface, now we can allow multiple methods to be called on the same object using $this variable.

https://programmingdive.com/method-chaining-in-php/
Paseto example with Graphql(Lighthouse Laravel)
Tags: help, php, laravel, graphql
Published: 2020-06-14 11:43:06

Hi everyone,

Update: I create a request for paseto implementation in PHP Lighthouse, if you like this idea please give a thumbs up so that this request can get noticed and implemented. Thank you, the request is [here](https://github.com/nuwave/lighthouse/issues/1430)

Update 2: I will try to create a passeto option for laravel 7 to auth and authroize following the specs but I will need the help of  security experts and laravel devs to create this under MIT.
If somebody is interested let me know.

I am looking for a paseto example with Graphql(Lighthouse Laravel) or how to create paseto's for each resource using the user roles and types. Or how to restrict access to only specific resources.

I only found this:

- [Paseto presentation Okta](https://www.youtube.com/watch?v=Ai7PVLl4Wng)

- [Paseto docs](https://github.com/paragonie/paseto/tree/master/docs/02-PHP-Library)


- [Paseto Lumen Example](https://github.com/mstaack/lumen-api-starter/blob/master/app/Extensions/Authentication/PasetoAuthGuard.php)

Thanks in advance for any direction or info
Node.js on port 80 in AWS
Tags: aws, webdev, node
Published: 2020-06-14 11:38:24

###First step to AWS

You'll get the fresh machine after register with AWS.
But they provide a user that does not have the power of root. You can write root command with 'sudo su' but launching Node.js process on 80 port is difficult it always gives you The EACCESS Error. Because of Security reasons (For a Reason).

But as a single/Minimal team, you have a handful and trusted people. So you can make that bet on to get access with root with few adjustments at root level.

**:Caution:**
**Take a backup of every file that you change mostly in /etc folder.**


###Install Node.js
After installing node.js you'll notice that 80 port already occupied either from Nginx/Apache WebServer.


###Steps to configure Node.js on 80 port

1. Open ssh to ubuntu(AWS) with ssh key(Old one)

2. Write command "sudo su" to gain sudo power

3. Write command "nano etc/ssh/sshd_config"

4. look for PasswordAuthentication tag and change its value 'yes'

5. Login to root and password (If this is first time set new password with passwd)

6. Generate new public and private key in putty generator and keep Public-key ssh-header locally.

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

7. Paste (Public-Key:ssh-header) from PuttyGen to /root/.ssh/authorized_keys

8. Keep Private and Public key safe for login via public-key from "ssh-client" such as putty : 
{Username:root,Method:Public-key} Add/Import your openSSH private key to your SSH-Client's Client-Key-Manager.
  
     ![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/yomjtmqsn4viuv1uhzwd.png)

9. **sudo service sshd restart**

10. Login with ssh now

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


11. You may disable the password login and only allow ssh key again. By setting **"PasswordAuthentication no" (Recommended)** or you may still allow root access with password(Not recommended).


###Stop preoccupied service on port 80
Before executing node.js process need to kill occupied 80 port process.

**sudo fuser -k 80/tcp**

###Go Ahead
Go-Ahead run Node.js on port 80 it will work.

###Tip:
Use Node.js for APIs.Static assets should serve via NginX.Keep use  Multiple database layer for smooth operation.
Standard input for AtCoder Contest (Python3)
Tags: python, atcoder, programmingcontest
Published: 2020-06-14 11:34:29

---
title: Standard input for AtCoder Contest (Python3) 
published: true
tags: Python, AtCoder, ProgrammingContest
---

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

https://atcoder.jp

## String

```python
# ex: hello
s = input()
print(s) # => "hello"
```

## Number

```python
# ex: 10
n = int(input())
print(n + 1) # => 11
```

## Multiple String

```python
# ex: hello world
s1, s2 = input().split()
print(s1) # => "hello"
print(s2) # => "world"
```

## Multiple Number

```python
# ex: 2 3
a, b = map(int, input().split())
print(a * b) # => 6
```

```python
# ex: 1 2 3 4 5 6 7 8 9 10
l = [ int(x) for x in input().split() ]
print(sum(l)) # => 55
```
Is it a good practice to get all the data in Single call, when designing REST API for mobile App ?
Tags: api, android, ios, discuss
Published: 2020-06-14 11:27:48

---
title: Is it a good practice to get all the data in Single call, when designing REST API for mobile App ?
published: true
description: 
tags: #api,#android,#ios,#discuss
//cover_image: https://direct_url_to_image.jpg
---

Hi Everyone ,

I have a question regarding designing the REST API for mobile application.

Assuming I am designing a REST API for dashboard screen in mobile app.which fetches data from multiple tables in the database.

In this case, what is the ideal approach?

1. One rest API to fetch all the data at once.
2. Multiple rest API that fetches data from each database table.which may involve the second API to be called after the success of the first API.

Considering clean code practices like 
1. Separation of code concerns  
2. CPU usage/ and User experience  on the app

Please share your experience on what should be the approach in such cases.

Thank you
Pick colors: LIKE A BOSS
Tags: webdev
Published: 2020-06-14 11:21:21

**Disclaimer**: Windows only  

As a front-end developer, one of the most important work is to get the design right. Now there are times when the client is a bit low on budget and cannot provide a professionally designed app with colors-scheme and shit!

There are times when you are asked to do a hot-fix for a production ready app wherein you just have to match the color according to the design.

So, whenever I am developing on Windows, and there is a need to pick colors from an image, browser, website, practically ANYTHING, my go-to tool is: [COLORCOP](http://colorcop.net/)  

## Color from a desktop icon  
Picking color from the Winamp logo
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/wuo1zfd7gcvgbdxcd2nc.png)  

## Color from browser  
Picking Purple color from the Broswer – RegEx text  
 ![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/c6flyddcl10x47w0ak81.png)  

With Colorcop, you can pick colors off any surface, literally ANY SURFACE. As you can see in the image above, we are picking colors off of an icon – a fucking icon! Now, how cool is this shit!  

***  

# In an alternate universe…  
For MacOS or Linux users, stick to Chrome/Firefox extensions like [ColorZilla](https://chrome.google.com/webstore/detail/colorzilla/bhlhnicpbhignbdhedgjhgdocnmhomnp). But obviously, just Google ColorCop alternatives for MacOS or Linux and if you do stumble on anything concrete, ping me here!  

***

Originally published at [adityatyagi.com](https://adityatyagi.com/index.php/2020/06/11/pick-colors-like-a-boss/)
Lotus Audio: Create and share virtual environments from the browser
Tags: gftwhackathon
Published: 2020-06-14 11:06:55

## What I built

![Lotus Audio](https://dev-to-uploads.s3.amazonaws.com/i/1x6vdas7xjb16hblrww9.png)

[Lotus Audio](https://lotusaudio.herokuapp.com) is a web app to create and share virtual music environments from the browser. The environments can respond to music so it behaves like a 3D music visualizer that you can get immersed in with virtual reality(VR) devices.

Artists can create scripts which act as plugins into the LotusAudio engine.
The engine processes and passes byte information about any accompanying audio file to the scripts and designers can use this to update their environments in whatever way they choose.
The results of the scripts are rendered as virtual environments compatible with VR devices.

Artists can choose to monetize their creations with Web Monetization. If they have it enabled users would be able to access their virtual worlds of art only with payment enabled. It is a research and explorations into this medium for creative expressions. I work with a community of livecoders and digital performers and excited to show this to them.

### Submission Category: 
Creative Catalyst

## Demo
- [Main Page](https://lotusaudio.herokuapp.com)
- [Running Demo](https://lotusaudio.herokuapp.com/view/5ee4fe4610a0ec114483fd4e)
- [Video](https://youtu.be/obxwEXdzNnE)

## Link to Code
- [Github](https://github.com/amitlzkpa/lotusaudio)

## How I built it 
The 3D environments are created using [threejs](http://threejs.org/) and uses the WebAudio API to parse audio. The environments are WebXR compatible which makes sure they can be accessed through VR devices. The platform is maintained as a web-app running on MEVN stack. In the future I would like to make the full app infrastructure completely decentralized.

## Additional Resources/Info 
I am pretty excited about this project. I would like extend it by adding support for multi-user experiences using WebRTC. That way several people can get together for virtual algoraves where we party within our creations.
Add new columns to table in PostgreSQL
Tags: postgres, sql, database
Published: 2020-06-14 10:57:21

---
title: Add new columns to table in PostgreSQL
published: true
description: Learn how to add new columns to the table in PostgreSQL.
tags: PostgreSQL,SQL,database
---


## Adding columns
We can combine `ALTER TABLE` & `ADD COLUMN` to add new columns to an existing table.

```sql
ALTER TABLE table_name
ADD COLUMN  column_name1 data_type,
ADD COLUMN  column_name1 data_type,
Constraints;
```
Let's say we have a table `user `, with `name` and `age` , Now we need to add a new column `phone_number`.
```sql
alter table user
add column phone_number bigint;
```
## Adding multiple columns
Consider we need to add two more columns, `salary` and `nickname`
```sql
ALTER TABLE user
ADD COLUMN salary int,
ADD COLUMN nickname varchar;
```
## Add Column if not present
With Postgres 9.6 this can be done using the option if not exists
```sql
ALTER TABLE table_name
ADD COLUMN IF NOT EXISTS column_name data_type;
```
## Adding with constraints
```sql
ALTER TABLE table_name
ADD COLUMN column_name datatype
constraints;
```
Let's say we need to add a default value to a column.
```sql
Alter table user
add column isAlive boolean default true;
```

To add a not null constraint you need to set `default value` because, When you add new column PostgreSQL takes the `NULL` as column value for the existing row, which violates the `NOT NULL` constraint.

```sql
Alter table user
add column isAlive boolean not null default true;
```
If you don't want the default value
* Add a column with the default value constraint 

```sql
Alter table user
add column isAlive boolean not null default true;
Then remove the default value constraint
```

* Then remove the default value constraint

```sql
ALTER TABLE user
ALTER COLUMN isAlive
DROP DEFAULT;
```
Thanks for reading.
CSS Text Shadow
Tags: beginners, css, webdev, html
Published: 2020-06-14 10:37:05

<!-- wp:paragraph -->
<p>With CSS3 you can create two types of shadows: text-shadow (adds shadow to text) and box-shadow (adds shadow to other elements).</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>In this section we will be checking how can we create text shadow.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3>CSS3 Text Shadow</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>The text-shadow CSS property adds shadows to text. It accepts a comma-separated list of shadows to be applied to the text and any of its decorations</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><span style="text-decoration: underline;">Syntax:</span></p>
<!-- /wp:paragraph -->

```css
text-shadow: horizontal-offset vertical-offset blur-radius color;
```

<!-- wp:paragraph -->
<p>Example:</p>
<!-- /wp:paragraph -->


```css
text-shadow: 1px 1px 2px white;
```

<!-- wp:paragraph -->
<p>Below I am going to add few examples to check how text-shadow works where we include Hard Shadow, Double shadow , etc.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>You can find the code in<a href="https://codepen.io/suprabhasupi/pen/mdVPywz" target="_blank" rel="noreferrer noopener"> codepen</a></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Thanks for reading this article ♥️</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>If you have any question, please feel free to ping me on <strong><a href="https://twitter.com/suprabhasupi">@suprabhasupi</a> 😋</strong></p>
<!-- /wp:paragraph -->

<table>
  <tbody>
    <tr>
      <td>
        🌟 <a href="https://twitter.com/suprabhasupi"> Twitter</a>
      </td>
      <td>
        👩🏻‍💻 <a href="https://www.suprabha.me/"> Suprabha.me</a>
      </td>
<td>
        🌟 <a href="https://www.instagram.com/suprabhasupi/"> Instagram</a>
      </td>
    </tr>
  </tbody>
</table>
Road to Genius: beginner #13
Tags: beginners, javascript, computerscience
Published: 2020-06-14 10:28:17

Each day I solve several challenges and puzzles from Codr's ranked mode. The goal is to reach genius rank, along the way I explain how I solve them. You do not need any programming background to get started, but you will learn a ton of new and interesting things as you go.

![programming challenge](https://dev-to-uploads.s3.amazonaws.com/i/tuuwl59grnupuwv0nb8v.png)

We are approaching the upgrade from "beginner" to "smart" rank, just a few more problems left. I am excited about this new challenge. We have seen this code before in a slightly different version. We need to fix two bugs 🐼 and 😈. The first one appears to be an initial value for variable `N`, which is used as a condition in the for-loop. Inside the loop we are filling the array with numbers under the condition that `i % 3 == 0`. This means that if we divide `i` by 3, the remainder should be zero, in other words the division should result in a whole number. Whole number divisions for 3 are: 0, 3, 6, 9, ... The challenge states at the end that `R = 5`, since R hasn't been declared before then 😈 is most likely going to be `R`. If we take a peek at the possible answers for 🐼, we see `0, 5 and 13`. The first two are incorrect because those conditions will not generate enough numbers for the array to contain 5 items (indicated by `R`). The only valid answer is 13 and we can prove it: 0, 3, 6, 9 and 12 are the five numbers that are divisible by 3 (whose remainder is 0).

![programming challenge answer](https://dev-to-uploads.s3.amazonaws.com/i/5p26ymlek0jz5wcng7nj.png)

---

If you feel inspired and motivated to upgrade your coding + debugging skills, join me on the Road to Genius at https://nevolin.be/codr/
Rating Algorithm + Example written in JS, PHP, and Go
Tags: algorithms, javascript, go, php
Published: 2020-06-14 10:09:29

As we know **Rating** are used to make a feedback between developer and user or something similar, i thinks that was the best way to ask people about how the feel do you experience when using the product, it's simple and easy to understand for both devs & user.

### Math

The logic behind rating system is quite simple as this:

```
rating = quantity / sum total
```

For more explanation i have create some condition to simulate the rating usage in real life;

**Example**: There is a guy who sell a *fried rice*, he want to ask his customer about the food taste, he take a survey for 10 of his customer to rate between 1 to 5 point.

Then the result is:

```
4 3 3 4 2 5 2 3 5 1 
```

Then we can get the rating result by counting like this;

```
A = 4 + 3 + 3 + 4 + 2 + 5 + 2 + 3 + 5 + 1
B = 10
rating = A / B
```

*Explain*: **A** is addition of each rate quantity, so in this case **A** will have value `32` while **B** is a rate quantity itself then the value is `10`, and **rating** value are the result of divided value of **A** and **B** which is give a result `3.2`.

### Just Show Me The Code

Ok, don't waste your time by reading my ~shit~ explanation while you're getting more understand with just reading the code. :)

JavaScript:

``` javascript
const rates = [4, 3, 3, 4, 2, 5, 2, 3, 5, 1]

let total = 0
rates.forEach(data => {
  total += data
})

const qty = rates.length
const rating = total / qty

console.log("Rating Result:", rating) // Rating Result: 3.2
```

PHP:

``` php
$rates = array(4, 3, 3, 4, 2, 5, 2, 3, 5, 1);

$total = 0;
foreach ($rates as $data) {
  $total += $data;
}

$qty = count($rates);
$rating = $total / $qty;

echo 'Rating Result: ' . $rating; // Rating Result: 3.2
```

Go:

``` go
package main

import "fmt"

var rates = []int{4, 3, 3, 4, 2, 5, 2, 3, 5, 1}

func main() {

	var total int = 0
	for _, data := range rates {
		total += data
	}

	var qty int = len(rates)

	// The function float64() is needed
	// to convert decimal number of result 
	var rating float64 = float64(total) / float64(qty)

	fmt.Printf("Rating Result: %.1f\n", rating) // Rating Result: 3.2
}
```
Sushant Singh Rajput Upcoming Movies List 2020, 2021 - BollywoodCat death
Tags: sushantsinghrajput
Published: 2020-06-14 09:52:20

Sushant Singh Rajput has established himself as a successful actor and has paved his way towards glory and popularity. The actor started his journey as [...] bad news more info.https://www.bollywoodcat.com/sushant-singh-rajput-upcoming-movies-list/
100 Days of SwiftUI — Day 24
Tags: 100daysofswiftui
Published: 2020-06-14 11:16:34

---
title: 100 Days of SwiftUI — Day 24
published: true
date: 2020-06-14 09:34:00 UTC
tags: 100daysofswiftui
canonical_url: https://zeitschlag.net/100-days-of-swiftui-day-24/
---

Day 24, or as Paul says: [Project 3, part 2](https://www.hackingwithswift.com/100/swiftui/24). There were some challenges, in which I had to change the former projects to use a view composition, conditional modifiers and I had also to create a custom `ViewModifier` next a `View`-extension. I figured, that I'm still learning and I will need some more practice, especially with `ViewModifiers`, but that's okay.
Deno + JWT
Tags: deno, jwt, rest
Published: 2020-06-14 09:31:24

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

In this application, I am going to create simple JWT encode and decode functions.

First of all, we need to import two libraries or JWT from Deno's 3rd party packages

{% gist https://gist.github.com/badalkhatri/bd3d9ed42f6634f5689180c34dd66bac %}

- validateJwt — it will be used to validate our JWT token
- makeJwt— it will convert our payload into JWT token
- Jose — it indicates algorithm and type
- Payload— it is interface for our Payload or Data

**Encode**

{% gist https://gist.github.com/badalkhatri/1c2acbf5344c192e875078b09447241e %}

- First of all we will put our data which into payload by using Payload interface (it is mandatory).
- Then we will define our header which will contains algorithm and type.
- Now we will pass header, payload and key (for simplicity I have put this key in same file but it should be placed in Environment Variable)

This function will return Promise that will contains our JWT token, we can also put expiration time in our payload.

**Decode**

{% gist https://gist.github.com/badalkhatri/542d36f8d627fc24e8d8f3e8fb57573d %}

In this function we will simply take the JWT string and pass it into validateJwt function with the key.

We will extract our payload from the return data.

Using this functions I have made simple REST API /encode and /decode.

You can checkout the code for more from my repository here {% github https://github.com/badal-khatri-blogs/deno-jwt %}

Happy coding :)

Thank you
K-fold cross validation คืออะไร
Tags: machinelearning, kfoldcrossvalidation
Published: 2020-06-14 09:30:17

K-fold cross validation
คือวิธีการในการคาดเดาค่าความผิดพลาดของแบบจำลอง (model) โดยจะเริ่มจากการแบ่งชุดข้อมูล training set ออกเป็นส่วนๆ ทั้งหมด K ส่วนเท่าๆ กันและทำการคำนวณค่าความผิดพลาดทั้งหมด K รอบ โดยแต่ละรอบคำนวณข้อมูลชุดหนึ่งจากข้อมูล K ชุด เลือกออกมาเพื่อเป็นข้อมูลทดสอบและเหลือข้อมูลอีก K-1 ชุดจะถูกใช้เป็นข้อมูลสำหรับการเรียนรู้

โดยปกติในงานวิจัย นิยมใช้ K-fold cross validation ใช้ K=10 ทั้งนี้ก็ขึ้นอยู่กับข้อมูลในงานวิจัยนั้นๆ ด้วย

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


https://www.researchgate.net/figure/Diagram-of-k-fold-cross-validation-with-k-10-Image-from-Karl-Rosaen-Log_fig1_332370436
Markdown-friendly template engines, with full power of HTML?
Tags: markdown, webdev, discuss
Published: 2020-06-14 09:29:24

I think it is highly missing, but one of them is Pug. And probably other indentation-based template engines, e.g. HAML.

With [proper settings](https://dev.to/patarapolw/pug-with-markdown-is-magic-yet-underrated-4dla), you can do things like

```markdown
# Hello World

![Workload of this image is lightened by Markdown renderer](https://img.url/name.png)

!!!pug
center
  web-component-one
    markdown:
      [Again, This link is safen by the Markdown renderer by adding rel's.](http://potentially.dangero.us)

      ## Header of content

      !!!pug
      div(style="color: red; text-align: right;")
        web-component-two
          markdown:
            ![alt text](image embedded inside web component)
      !!!
!!!
```

Sadly, [Pug when run directly on the browser is quite large](https://github.com/pugjs/pug#browser-support), and you might have to resort to couple of AJAX requests instead, so I created a leaner package.

{% github patarapolw/hyperpug no-readme %}

Seriously, Markdown compatible template engines are missing, or should I rather ask for non-indentation-based alternatives to Markdown?
K-fold cross validation คืออะไร
Tags: machinelearning, kfoldcrossvalidation
Published: 2020-06-14 09:25:37

K-fold cross validation 
คือวิธีการในการคาดเดาค่าความผิดพลาดของแบบจำลอง (model) โดยจะเริ่มจากการแบ่งชุดข้อมูล training set ออกเป็นส่วนๆ ทั้งหมด K ส่วนเท่าๆ กันและทำการคำนวณค่าความผิดพลาดทั้งหมด K รอบ โดยแต่ละรอบคำนวณข้อมูลชุดหนึ่งจากข้อมูล K ชุด เลือกออกมาเพื่อเป็นข้อมูลทดสอบและเหลือข้อมูลอีก K-1 ชุดจะถูกใช้เป็นข้อมูลสำหรับการเรียนรู้

โดยปกติในงานวิจัย นิยมใช้ K-fold cross validation ใช้ K=10 ทั้งนี้ก็ขึ้นอยู่กับข้อมูลในงานวิจัยนั้นๆ ด้วย

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


https://www.researchgate.net/figure/Diagram-of-k-fold-cross-validation-with-k-10-Image-from-Karl-Rosaen-Log_fig1_332370436