teleren/devto huggingface dataset:
Data Structure & Algorithms - Tree Traversal
Published: 2021-05-14 04:59:13

Traversal is a process to visit all the nodes of a tree and may print their values too. Because, all nodes are connected via edges (links) we always start from the root (head) node. That is, we cannot randomly access a node in a tree. There are three ways which we use to traverse a tree −

In-order Traversal
Pre-order Traversal
Post-order Traversal
we traverse a tree to search or locate a given item or key in the tree or to print all the values it contains.

In-order Traversal
In this traversal method, the left subtree is visited first, then the root and later the right sub-tree. We should always remember that every node may represent a subtree itself.

If a binary tree is traversed in-order, the output will produce sorted key values in an ascending order.

Algorithm
Until all nodes are traversed −
Step 1 − Recursively traverse left subtree.
Step 2 − Visit root node.
Step 3 − Recursively traverse right subtree.

Pre-order Traversal
In this traversal method, the root node is visited first, then the left subtree and finally the right subtree.

Algorithm
Until all nodes are traversed −
Step 1 − Visit root node.
Step 2 − Recursively traverse left subtree.
Step 3 − Recursively traverse right subtree.

Post-order Traversal
In this traversal method, the root node is visited last, hence the name. First we traverse the left subtree, then the right subtree and finally the root node.

Algorithm
Until all nodes are traversed −
Step 1 − Recursively traverse left subtree.
Step 2 − Recursively traverse right subtree.
Step 3 − Visit root node.
Anyone know of a build tool to grab pieces from different places and assemble it all together?
Tags: devops, npm, aws, github
Published: 2021-05-14 04:45:56

For instance, I might have a serverless file saved as a Gist, a docker-compose.yml in an S3 bucket, a few github repos to clone,ect..

I would like to specify my build asset targets, keys, and whatever else I need and run a cli command and put it all together locally. 

Chef might work but seems like overkill. 

Thanks in advance.
GitHub Community: your place to learn, discuss, and ask questions
Tags: github, devops, codenewbie, community
Published: 2021-05-14 04:14:07

The [GitHub Community](https://github.community) is the place where you can talk and find answers about GitHub, DevOps, Programming languages, and much more!

I've teamed up with [Mickey Gousset](https://www.youtube.com/MickeyGousset) (DevOps Architect @ GitHub) to bring you all the information you need on what it is, how to use it, and what you can find there.

Watch the full video here 🤓
{% youtube 8SS6I63LCW0 %}

> Full link: [https://youtu.be/8SS6I63LCW0](https://youtu.be/8SS6I63LCW0)

__Like, share and follow me__ 🚀 for more content:

📽 [YouTube](https://www.youtube.com/CoderDave)
☕ [Buy me a coffee](https://buymeacoffee.com/CoderDave)
💖 [Patreon](https://patreon.com/CoderDave)
👕 [Merch](https://geni.us/cdmerch)
👦🏻 [Facebook page](https://www.facebook.com/CoderDaveYT)
🐱‍💻 [GitHub](https://github.com/n3wt0n)
👲🏻 [Twitter](https://www.twitter.com/davide.benvegnu)
👴🏻 [LinkedIn](https://www.linkedin.com/in/davidebenvegnu/)
🔉 [Podcast](https://geni.us/cdpodcast)
Angular : How to use *ngIf else? [Including NgIf, ngIfThen and ngIfElse with Live Demo]
Tags: angular, javascript, programming, webdev
Published: 2021-05-14 04:10:36

Simple form with shorthand syntax:
```javascript
<div *ngIf="condition">Content to render when condition is true.</div>
```

Simple form with expanded syntax:
```javascript
<ng-template [ngIf]="condition"><div>Content to render when condition is
true.</div></ng-template>
```

Form with an "else" block:
```javascript
<div *ngIf="condition; else elseBlock">Content to render when condition is true.</div>
<ng-template #elseBlock>Content to render when condition is false.</ng-template>
```

Shorthand form with "then" and "else" blocks:
```javascript
<div *ngIf="condition; then thenBlock else elseBlock"></div>
<ng-template #thenBlock>Content to render when condition is true.</ng-template>
<ng-template #elseBlock>Content to render when condition is false.</ng-template>
```

Form with storing the value locally:
```javascript
<div *ngIf="condition as value; else elseBlock">{{value}}</div>
<ng-template #elseBlock>Content to render when value is null.</ng-template>
```

For case if with else, we can use `ngIf` and `ngIfElse`:
```javascript
<ng-template [ngIf]="condition" [ngIfElse]="elseBlock">
  Content to render when condition is true.
</ng-template>
<ng-template #elseBlock>
  Content to render when condition is false.
</ng-template>
```

For case if with then, we can use `ngIf` and `ngIfThen`:
```javascript
<ng-template [ngIf]="condition" [ngIfThen]="thenBlock">
  This content is never showing
</ng-template>
<ng-template #thenBlock>
  Content to render when condition is true.
</ng-template>
```

For case if with then and else, we can use `ngIf`, `ngIfThen`, and `ngIfElse`:
```javascript
<ng-template [ngIf]="condition" [ngIfThen]="thenBlock" [ngIfElse]="elseBlock">
  This content is never showing
</ng-template>
<ng-template #thenBlock>
  Content to render when condition is true.
</ng-template>
<ng-template #elseBlock>
  Content to render when condition is false.
</ng-template>
```

{% stackblitz angular-ivy-gzfafh file=src%2Fapp%2Fapp.component.html %}

<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).
Node.js : Asynchronously Read from Files
Tags: node, programming, webdev, javascript
Published: 2021-05-14 03:54:10

Use the filesystem module for all file operations:
```javascript
const fs = require('fs');
```
# With Encoding
In this example, read `hello.txt` from the directory /tmp. This operation will be completed in the background and the callback occurs on completion or failure:
```javascript
fs.readFile('/tmp/hello.txt', { encoding: 'utf8' }, (err, content) => {
 // If an error occurred, output it and return
 if(err) return console.error(err);
 // No error occurred, content is a string
 console.log(content);
});
```

# Without Encoding
Read the binary file `binary.txt` from the current directory, asynchronously in the background. Note that we do not set the 'encoding' option - this prevents Node.js from decoding the contents into a string:
```javascript
fs.readFile('binary', (err, binaryContent) => {
 // If an error occurred, output it and return
 if(err) return console.error(err);
 // No error occurred, content is a Buffer, output it in
 // hexadecimal representation.
 console.log(content.toString('hex'));
});
```

# Relative paths
Keep in mind that, in general case, your script could be run with an arbitrary current working directory. To address
a file relative to the current script, use `__dirname` or `__filename`:
```javascript
fs.readFile(path.resolve(__dirname, 'someFile'), (err, binaryContent) => {
 //Rest of code
}
```

<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).
49 Days of Ruby: Day 48 -- Ruby Community
Tags: ruby
Published: 2021-05-14 03:51:05

---
title: 49 Days of Ruby: Day 48 -- Ruby Community
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 48 of the 49 Days of Ruby! 🎉**

You are almost there! After tomorrow, you will have finished 49 days of Ruby adventure!

Today, we are going to take a step back from code and talk about community.

The thing that makes Ruby so special, beyond its syntax, its readability, its usefulness, is its community.

Ruby is surrounded by caring people across the globe. People from all different experience levels come together to learn and to share. Ruby is one of the friendliest language communities for new developers.

How do you get involved in the Ruby community?

While, this past year of 2020 and continuing into 2021, there has been a real challenge with meetups because of the global Coronavirus crisis, meetups are generally a great way to get connected.

In fact, many Ruby meetups continue to meet despite social distancing and lockdowns via the web. That means you could attend a meetup without needing to put on any shoes!

There are Ruby meetups worldwide. [This list](https://planetruby.github.io/meetups/) provides a good breakdown of meetups by region. Find one that is near you. If there are none near you, look at others, especially since many are meeting online nowadays.

In addition to meetups, there are all many annual Ruby conferences.

The biggest one is [RubyConf](http://rubyconf.org/), which happens in North America every year *(during the pandemic, it happened online exclusively)*. There are also regional conferences in different parts of the world like [Ruby Fuza](http://www.rubyfuza.org/) in South Africa, [Euruko](https://euruko2021.org/) in Europe, [Ruby Kaigi](https://rubykaigi.org/2021-takeout) in Japan and many others.

There is a lot of [past conferences](https://rubyconferences.org/past/) that could be a helpful place to start looking.

If you are new to Ruby, RubyConf runs a scholars program that is really worthwhile. The program will pair you with a mentor, someone who has been in the community for a bit. They will help you navigate the sessions, introduce you to people, and be your overall guide for the experience.

Your challenge for today is to explore the Ruby community, and find a way to get involved! See you tomorrow for our last day of the journey.

**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).**
Dynamic Dev.to Blog Posts On GitHub
Tags: github, githunt, showdev, tutorial
Published: 2021-05-14 03:39:59

## What is this?
Want to show dynamic posts that update with the posts that you right on dev.to? This post is going to share a simple yet easy way to add dev.to posts dynamically to your github profile. Here is a example as well:

![Example](https://user-images.githubusercontent.com/8397274/88047382-29b8b280-cb6f-11ea-9efb-2af2b10f3e0c.png)

## How to use?
- Leave some reactions to this repository :wink:
- Create a repository with the same name as your username
  For example if my username is **AttentiveAryan** the repo will be **AttentiveAryan/AttentiveAryan**
  ![Message To Verify](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qrpke1gwfniouk234mdd.png)
- Create a readme.md file
  ```md
   <h1 align="center">Hi 👋🏻, I'm Aryan Gupta</h1>
  <h3 align="center">A passionate learner from India</h3>
  <p align="center"> <a href="https://twitter.com/attentivearyan" 
target="blank"><img 
src="https://img.shields.io/twitter/follow/attentivearyan? 
logo=twitter&style=for-the-badge" alt="attentivearyan" /></a> 
  </p>

  - 🔭 I’m currently working on [learning html & css](https://freecodecamp.org/)

  - 💻 All of my projects are available at [attentivearyan.github.io](https://attentivearyan.github.io)

  - 📝 I regularly write articles on [attentivearyan.github.io/blog/](https://attentivearyan.github.io/blog/)

  - 📫 How to reach me **attentivearyan@gmail.com**

  - 📄 Know about my experiences [attentivearyan.github.io/resume/](https://attentivearyan.github.io/resume/)

  ### Blogs posts
  <!-- BLOG-POST-LIST:START -->
  <!-- BLOG-POST-LIST:END -->
  ```
  **Make sure to include the comment tag cause the post will be placed in this**
  ```md
  <!-- BLOG-POST-LIST:START -->
  <!-- BLOG-POST-LIST:END -->
  ```
- Now let us come to the logic, We are going to use blog-post-workflow action:
  {% github gautamkrishnar/blog-post-workflow no-readme %}
- For that create a file in `.github/workflows/` called `blog-post-workflow.yml`
  ```yml
name: Latest blog post workflow
on:
  schedule: # Run workflow automatically
    - cron: '0 * * * *' # Runs every hour, on the hour
  workflow_dispatch: # Run workflow manually (without waiting for the cron to be called), through the Github Actions Workflow page directly
jobs:
  update-readme-with-blog:
    name: Update this repo's README with latest blog posts
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: gautamkrishnar/blog-post-workflow@master
        with:
          feed_list: "https://dev.to/feed/{username}"
  ```
  **Replace {username} with your username**
- Check the repo for more configuration options:
  {% github gautamkrishnar/blog-post-workflow %}


Happy Coding! If you face any issues comment here down below! Make sure to link your profile repo once you're done!

Thanks to @krishdevdb for this article
A new Password Rule object from Laravel 8.39
Tags: laravel, php, webdev
Published: 2021-05-14 03:38:42

In previous versions, to define a custom validation rule, you must to implement the `Illuminate\Contracts\Validation\Rule` interface or use a Closure.

As below code, a custom rule `StrongPassword` like so.

```php
namespace App\Rules;

use Illuminate\Contracts\Validation\Rule;

class StrongPassword implements Rule
{
    public function passes($attribute, $value)
    {
        return preg_match("/^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@()$%^&*=_{}[\]:;\"'|\\<>,.\/~`±§+-]).{12,30}$/", $value);
    }

    public function message()
    {
        return 'The :attribute must be 12–30 characters, and include a number, a symbol, a lower and a upper case letter';
    }
}
```

And use it in your controller or request validation.

```php
namespace App\Http\Requests;

use App\Rules\StrongPassword;
use Illuminate\Foundation\Http\FormRequest;

class AccountRequest extends FormRequest
{
    public function authorize()
    {
        return true;
    }

    public function rules()
    {
        return [
            'password' => [
                'required',
                'confirmed',
                new StrongPassword(),
            ],
        ];
    }
}
```

From version 8.39, Nuno Maduro created a new Password Rule object in this framework with below methods:

`min()`: Makes minimum size of the password.
`mixedCase()`: Makes the password require at least one uppercase and one lowercase letter.
`letters()`: Makes the password require at least one letter.
`numbers()`: Makes the password require at least one number.
`symbols()`: Makes the password require at least one symbol.
`uncompromised()`: Ensures the password has not been compromised by checking the password against a verification API to see if the password appears in data leaks.

```php
$request->validate([
    'password' =>  ['required', 'confirmed', Password::min(8)->mixedCase()],
    'password' =>  ['required', 'confirmed', Password::min(8)->letters()],
    'password' =>  ['required', 'confirmed', Password::min(8)->numbers()],
    'password' =>  ['required', 'confirmed', Password::min(8)->symbols()],
    'password' =>  ['required', 'confirmed', Password::min(8)->uncompromised()],
]);
```

Or you can use them all combined like so.

```php
$request->validate([
    'password' => ['required', 'confirmed', Password::min(8)
            ->mixedCase()
            ->letters()
            ->numbers()
            ->symbols()
            ->uncompromised(),
    ],
]);
```

Thanks Nuno Maduro.

Reference: https://github.com/laravel/framework/pull/36960
How to transfer data from your Existing Server to Aws S3
Tags: devops, linux, aws, s3
Published: 2021-05-14 03:34:56

Amazon S3 is a pretty good and inexpensive choice for website data storage. You can save a lot of money uploading website data such as user uploads to S3 instead of your hosting server.

I found it a little difficult to understand how s3 migration works and did not find any simple tutorial on that. So here I am sharing the steps that can help you to migrate data to the S3 bucket.

Steps:
1. Install Aws Cli on your existing Server
```sh
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
```
Reference: https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2-linux.html

2. Go to the IAM section in your AWS console and create a user will full administration access. Note down the Access Key Id and Access key secret provided to you after creating the user account.

2. Configure the Aws Cli on your Server using 
```sh
aws configure
```
 command, and provide Access Key Id and secret that you created before.

3. run `aws s3 list` to see the list of s3 buckets created inside your account( create one if you haven't done so).

4. Run the following command to copy the files to s3 bucket

```sh
aws s3 cp directory-to-be-uploaded s3://bucket-name-here --recursive
```

Thanks for reading.
In Memory of Hiny Umoren - a podcast episode on security
Tags: motivation, security, watercooler
Published: 2021-05-14 03:30:15

I'm hurt. I'm sorry guys if today I'm not posting anything related to codding. I feel hurt and bad about the recent happenings in Nigeria. Although not peculiar to Nigeria only. So I've decided to write instead about security. Please follow up with the podcast link below.
The security situation in the country is getting worse. In a world were the devil and his cohorts are in control we can not expect any less. Meanwhile, we must endeavor to take responsibility for our safety. What can we do? Listen.
https://anchor.fm/dami-okoro/episodes/RAPED-AND-MURDERED-in-memory-of-Hiny-Umoren-e10rj7q
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nqbxw7rt7s0jcyfh0y3b.jpg)
5/13 TIL: Go & JS hashmap
Tags: todayilearned
Published: 2021-05-14 03:28:13

- hashmap improves run time complexities
- hashMap equivalent in Javascript
```javascript
let map = new Map()
map.set(key, value)
map.has(key) // true or false
map.get(key)
map.delete(key)
```
- hashMap equivalent in Go
```go
m = make(map[int]int)
// map types are reference types so simply doing 'var m map[int]int' will not point to an initialized map and it will be nil
m[key] // set value
result := m[key] // get value
_, ok := m[key] // returns true or false in the second param
delete(m, key)
```
- discrete math intro
    - set-roster vs. set-builder notation
    - set-builder example: { x ∈ reals | x ≥ 2 and x ≤ 6 }
Promises Cheat Sheet
Tags: promises, cheatsheet
Published: 2021-05-14 03:13:21


### [Reference] Converting other promises

```js
return Promise.resolve('result')
return Promise.resolve(promise)
return Promise.resolve(thenable)

return Promise.reject('reason')

Promise.resolve(result).then(() => {
  /* ... */
})
```

`Promise.resolve(val)` will return a promise that resolves to the value given to it.
### [Reference] Multiple promises

```js
const promises = [promise1(), promise2() /* ... */]
```

```js
// Succeeds when all succeed
Promise.all(promises).then((results) => {
  /* ... */
})
```

```js
// Succeeds when one finishes first
Promise.race(promises).then((result) => {
  /* ... */
})
```

### [Reference] Consuming promises

```js
promise
  .then((result) => {
    /* success */
  })
  .catch((error) => {
    /* failure */
  })
```

[then()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then) runs a function when a promise resolves. [catch()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch) runs when a promise fails.

### [Reference] Creating promises

```js
new Promise((resolve, reject) => {
  doStuff(() => {
    if (success) {
      resolve('good')
    } else {
      reject(new Error('oops'))
    }
  })
})
```

Use [new Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise#Contstructor) to create new promises.

### [Reference] Introduction
Intro: A quick reference to the JavaScript [Promise API](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise).

*   [Using Promises guide](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises) _(developer.mozilla.org)_
*   [Promise documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) _(developer.mozilla.org)_
* [Promises Cheat Sheet](https://cheatsheetmaker.com/promises) - [Cheat Sheet Maker](https://cheatsheetmaker.com)
Bookshelf.Js Cheat Sheet
Tags: bookshelfjs, cheatsheet
Published: 2021-05-14 03:05:17


### CRUD

```js
Book.create({ title: '..' }).save()
new Book({ title: '..' }).save()

new Book({ id: 1 }).fetch()

Book.where({ id: 1 }).fetch()
Book.where('favorite_color', 'red').fetch()
Book.where('favorite_color', '<>', 'red').fetch()
Book
  .query((q) => q.orderBy('updated_at')
```
### Associations

```js
Summary = bookshelf.Model.extend({
  book () {
    return this.belongsTo(Book)
  },
  author () {
    return this.hasOne(Author)
  }
  // belongsToMany
  // hasMany
  // hasMany().through()
})
```

### Reference
* [Bookshelf.Js Cheat Sheet](https://cheatsheetmaker.com/bookshelfjs) - [Cheat Sheet Maker](https://cheatsheetmaker.com)