teleren/devto huggingface dataset:
Construct Binary Search Tree from Preorder Traversal - LeetCode
Tags: binarysearchtree, bst
Published: 2020-05-24 14:41:20

---
title: Construct Binary Search Tree from Preorder Traversal - LeetCode
published: true
description: Medium Problem
tags: binary-search-tree, bst
---

Return the root node of a binary search tree that matches the given preorder traversal.

So basically return a Binary Search Tree from an array of elements that are in preorder

For a binary search tree at any given nodeany descendant of `node.left < node.val` and any descendant of `node.right > node.val`

Algorithm:

1. Loop through each element
2. find the leaf node to insert
3. repeat

Code:

```js
/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
/**
 * @param {number[]} preorder
 * @return {TreeNode}
 */
var bstFromPreorder = function(preorder) {
	let root = new TreeNode(preorder[0])
	for(let i = 1; i < preorder.length; i++) {
		root = insert(root, preorder[i])
	}
	return root
};

var insert = function(node, elem) {
	if(!node) return new TreeNode(elem)
	if(node.val > elem) {
		node.left = insert(node.left, elem)
	} else {
		node.right = insert(node.right, elem)
	}
	return node
}
```
Introducing the 11ty Netlify Jumpstart
Tags: 11ty, netlify, webdev, showdev
Published: 2020-05-24 14:40:53

I'm pleased to share with you a template repo to help give you a jumpstart into using [11ty](https://11ty.dev)!

Quickly launch an 11ty-generated static site. Includes a minimal Sass framework, and generated sitemap, RSS feed, and social share preview images.

> **Skip the chit chat** and [jump to it >](https://11ty-netlify-jumpstart.netlify.app/)

This jumpstart is intended to be just enough to be a functional site/blog using 11ty, and also to introduce essential 11ty features.

[Review the "Quick Start"](https://11ty-netlify-jumpstart.netlify.app/#quickstart) for how to get this starter up and running for your project.

I spent a decade creating WordPress themes and plugins then flipped to product development + leading development of a multi-platform enterprise design system. My intro to JAMstack was with Gatsby, but 11ty fills a special place that is so needed for truly static sites. I'm in love, and I think you will be, too.

> This jumpstart is based on my [HTML / Sass Jumpstart](https://5t3ph.github.io/html-sass-jumpstart/) which you might enjoy if you're not in need of 11ty.

{% twitter 1264016885839994880 %}

This jumpstart is an abstraction of my setup for [ModernCSS.dev](https://moderncss.dev) which was my first 11ty site.

## Is Netlify hosting required?

It's not required, but highly recommended, and is also how the build process is setup to run against.

---

I plan to do a screencast - possibly a live one? - explaining more about this jumpstart and why I'm so pro-11ty. Comment below if you have questions or would be interested in watching a live walkthrough ✨
What is the proxy design pattern?
Tags: javascript, java, webdev
Published: 2020-05-24 13:41:34

The object oriented Proxy Design Pattern is a structural design pattern which is concerned with how classes and objects compose to form larger structures. The proxy design pattern in java takes a similar approach by providing a proxy object that acts as a placeholder for another object. Commonly a proxy is a class that functions as an interface to something else. The proxy design pattern can be best understood with the help of a real-world example. In computer networks, we usually come across the term proxy server. It is a server application that acts as an intermediary for web requests from the clients. The client, instead of connecting directly to a server, directs its request to the proxy server which performs the intended filtration and other network transaction. The purpose of proxy server is to simplify and control the complexity of the requests by providing additional benefits such as privacy and security. Proxies have been designed to add structure and encapsulation to distributed systems in computer networks.

The Proxy Design Pattern has the same intent has the proxy servers in computer networks. In this article we will define what is proxy design pattern, walk through the implementation and also see what are the benefits of using the proxy design pattern in java.

Full Article Source: [What is Proxy Design Pattern](https://www.decipherzone.com/blog-detail/proxy-design-pattern-in-java)
Machine Learning - BIAS and VARIANCE
Tags: machinelearning, datascience
Published: 2020-05-24 14:01:08

Machine Learning is all how we train a model using the training data-set. So, the model we train should reflect our training data-set and that is most common challenging part, as the model should not be over-fitted as well as under-fitted. Let us discuss about over-fitting and under-fitting in a different blog, here we shall see what is a BIAS and VARIANCE in machine learning.

We build our machine learning model using our training data, but can we predict the future based on your training data alone or do we need to generalize its ways, patterns to better absorb new data?

This trade-off is captured in "Bias versus Variance".

BIAS : It is the gap between what the model predicted and the actual value.

VARIANCE : It describes how the data is being spread of the predictions.

Put together, bias and variance affect the model's prediction accuracy and can lead to problems with under-fitting and over-fitting.

I read a post in Instagram, which described the BIAS and VARIANCE using a shooting target. It made me to understand, what BIAS and VARIANCE will lead to our end results of the machine learning model we build.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/6g5x6u81rad1oqqsji0s.PNG)
Bilingual Devs What Language Are You Thinking  in? 
Tags: discuss
Published: 2020-05-24 13:50:29

I speak 5 languages fluently and often I get asked what language I am thinking in. Been in the states for 20 years I can say that most of my thinking is in English however from time to time I catch my self thinking in different languages even when I am working on some project. 

How about you ?
What is the proxy design pattern?
Tags: javascript, java, webdev
Published: 2020-05-24 13:46:20

The object oriented Proxy Design Pattern is a structural design pattern which is concerned with how classes and objects compose to form larger structures. The proxy design pattern in java takes a similar approach by providing a proxy object that acts as a placeholder for another object. Commonly a proxy is a class that functions as an interface to something else. The proxy design pattern can be best understood with the help of a real-world example. In computer networks, we usually come across the term proxy server. It is a server application that acts as an intermediary for web requests from the clients. The client, instead of connecting directly to a server, directs its request to the proxy server which performs the intended filtration and other network transaction. The purpose of proxy server is to simplify and control the complexity of the requests by providing additional benefits such as privacy and security. Proxies have been designed to add structure and encapsulation to distributed systems in computer networks.

The Proxy Design Pattern has the same intent has the proxy servers in computer networks. In this article we will define what is proxy design pattern, walk through the implementation and also see what are the benefits of using the proxy design pattern in java.

**Full Article Source: [What is Proxy Design Pattern](https://www.decipherzone.com/blog-detail/proxy-design-pattern-in-java)**
☸️ Kubernetes Primer Coming Soon...
Tags: kubernetes, opensource, devops, beginners
Published: 2020-05-24 13:43:59

- I have created a beginner-friendly course on Kubernetes

- The course name is **Kubernetes Primer**

- The course will be published on my YouTube channel [Developers Thought](https://bit.ly/DevelopersThought)

- The course comprises of 5 videos. Following is the agenda of all 5 videos
  - What is Deployment, Service, Secret, and ConfigMap?
  - What is Persistent Volume (PV) and Persistent Volume Claim (PVC)?
  - What is Ingress Controller?
  - What is the Readiness and Liveness probe?
  - How to deploy applications using Helm in Kubernetes?  

- I will publish one video every Saturday at 10 AM starting from next Saturday 31st May 2020

- In this course, I have covered all the basic concepts required to get started with Kubernetes

- Each video has step by step guide associated with it

- Subscribe **Developers Thought** @ https://bit.ly/DevelopersThought to learn more about Docker, OpenShift, and Kubernetes
Anti-patterns of automated software testing
Tags: testing, antipatterns
Published: 2020-05-24 13:06:35

[Sometimes it’s easier to learn from ‘what not to do’ rather than from ‘what to do’. So I wrote this article about stuff you should avoid in your tests. Hope you enjoy.](https://medium.com/swlh/anti-patterns-of-automated-software-testing-b396283a4cb6)
Deploy dockerized app in Aws ECS in existing vpc.
Tags: aws, devops, ecs, terraform
Published: 2020-05-24 12:53:54

After struggling for few days to deploy a dockerrized applicatin in ECS, found the solution & simplified into script, so that anyone can deploy easily simply replacing app folder.

To deploy your application in ECS,
1. Your docker container image needs to be push to ECR.
2. From ECR repo, application will deploy in ECS

####git location
https://github.com/rajeshkumarbehura/ecs-app-deploy

### Requirement an application to deploy in Aws ECS
1. Project must dockerized. In my repo, its demo-app folder which is nestjs based simple application.You can have java/nodejs/python any kind of project as long as it is dockerized.
2. aws cli & terraform cli must be available in your command line.      
      aws --version
      terraform --version 
3. aws details must be avaialble
     AWS_ACCESS_KEY_ID=XXXXXXXXXXXXXXXX
     AWS_SECRET_ACCESS_KEY=XXXXXXXXXXXXXXXXXXXXX
     AWS_REGION=ap-southeast-1
     AWS_PROFILE=dev
 
4. You should know, whats your existing vpc & public subnet name in aws account.

#### Steps to deploy
Clone the project in your local.
##### Update VPC details in terraform
Go to /deploy/terraform/network.tf and replace dev-data-stream-vpc name with your existing vpc name.

Replace dev-data-stream-public-subnet name, with your existing public subnet tied with your existing vpc name.

```
variable "existing_vpc_name" {
  description = "Existing VPC in your aws cloud"
  default     = "dev-data-stream-vpc"
}

variable "existing_vpc_public_subnet_name" {
  description = "public subnet name which tie up with existing vpc"
  default     = "dev-data-stream-public-subnet"
}

```
##### Application
1. go to deploy folder
2. update AWS parameters in create_repo_in_ecr.sh and run this file.
3. Above script will create a repo in your aws account and print that ecr repo link in your console.
4. Copy ecr link & update aws parameter in push_image_to_ecr_&_deploy_ecs.sh file.
5. finally run push_image_to_ecr_&_deploy_ecs.sh script on your console to deploy this application


##### Destroy in AWS
Cleaning or deleteing all resources in aws, use below command.
```
terraform destroy
```

Once you can deploy and destroy successfully, then you can change more parameter and play around terraform files to understand more.

#### How to deploy your own application 
1. Replace your application inside demo-app content & make sure your application working dockerized.
2. Create health check api - api/index 
   This is configured inside variable.tf file in terraform folder
3. Optional step- to create your all configuration with a new name, do a find all for "demoapp" text inside terraform folder and replace with ur own text. For example- replace "demoapp" text with "customerapp".
Then do terraform plan, and check all things are working or not. if any place, please rename according to your text.

Play with terraform, ecr & ecs to explore more.
二分ヒープの解説
Tags: binaryheap
Published: 2020-05-24 12:46:38

{% youtube dre8pED2yDc %}

参考のためDijkstraの際に使った最小ヒープのコード抜粋を下に貼ります。

```js
const MinHeap = function (n) {
  this.a = [...Array(n).keys()].map(v => [v, Number.MAX_SAFE_INTEGER]) // [vertex, weight]
  this.pos = [...Array(n).keys()].map(v => v)
  this.size = n
}

MinHeap.prototype.extractMin = function () {
  const [v, w] = this.a[0]
  this.swap(0, this.size - 1)
  this.size--
  this.popDown(0)
  return [v, w]
}

MinHeap.prototype.swap = function (i, j) {
  const vi = this.a[i][0], vj = this.a[j][0];
  [this.a[i], this.a[j]] = [this.a[j], this.a[i]];
  [this.pos[vi], this.pos[vj]] = [this.pos[vj], this.pos[vi]]
}

MinHeap.prototype.decreaseKey = function (v, val) {
  const i = this.pos[v]
  this.a[i][1] = val
  this.popUp(i)
}

// vertexが含まれているか
MinHeap.prototype.contains = function (v) {
  return this.pos[v] < this.size
}

// 適切な位置まで上げる
MinHeap.prototype.popUp = function (i) {
  let pi = parent(i)
  while (i > 0 && this.a[i][1] < this.a[pi][1]) { // 親が子より大きかったら交換
    this.swap(i, pi)
    i = pi
    pi = parent(i)
  }
}

// 値を取得
MinHeap.prototype.val = function (v) {
  return this.a[this.pos[v]][1]
}

// 適切な位置まで下げる
MinHeap.prototype.popDown = function (i) {
  const val = this.a[i][1]
  let candidate = null // 子供のほうが小さかったら交換
  const ri = rightChild(i)
  const li = leftChild(i)
  if (ri < this.size) { // right child exist
    if (this.a[ri][1] < val) {
      candidate = ri
    }
  }
  if (li < this.size) {
    if (candidate == null) {
      if (this.a[li][1] < val) {
        candidate = li
      }
    } else {
      if (this.a[li][1] < this.a[ri][1]) {
        candidate = li
      }
    }
  }
  if (candidate != null) {
    this.swap(i, candidate)
    this.popDown(candidate)
  }
}


```
Day 22 of #100DaysOfCode: Create Endpoints to Manipulate Resources for Django App
Tags: 100daysofcode, django, python, weddev
Published: 2020-05-24 12:45:31

## Introduction
We have to run two servers if we want to use React App as a SPA server and use Django app as an APIs server. What if we only want to launch one server on the machine?

The target for this week is to understand the process of creating endpoints in DRF (Django REST Framework).

## Details
Please refer to my article. It includes four parts.
1. Overview (models, serializers, views, and urls)
2. Serializers
3. Views and URLS: Type 1. Use APIview
4. Views and URLS: Type 2. Use viewsets.ModelViewSet

https://medium.com/a-layman/build-single-page-application-with-react-and-django-part-4-create-endpoints-to-manipulate-13aefa60625b

## Articles
There are some of my articles. Feel free to check if you like! 
* My blog-posts for software developing: https://medium.com/a-layman
* My web resume: https://jenhsuan.github.io/ALayman/cover.html
* Facebook page: https://www.facebook.com/imalayman
How do you work with pull requests at work?
Tags: github, productivity, sideprojects
Published: 2020-05-24 12:29:22

Hello friends,

I'm working on a small side-projects called PRBoard (https://prboard.dev). It's a dashboard for teams that host their repos on GitHub. I'm currently in the market-validation phase, and I think some of my assumptions on how this product can be helpful for teams are invalid. For this reason, I'm gathering different ways engineering teams work with pull requests.

For example, in my team, when someone creates a new pull request, they send a message on Slack about it. We rarely use GitHub's built-in "assignees" and "reviewers" features because usually, it's more than one person who can review a pull request. When someone picks a PR, they usually leave an emoji on the original slack message signalling that they're starting the review.

There's a couple of downsides to the described approach:
1. No clear picture of all currently open PRs from my team. We structure code as one big monorepo with multiple teams working on separate code paths. This makes using GitHub's pull requests page almost impossible.

2. No way to know when a pull request is ready to be reviewed. We have a CI pipeline running different checks for every PR. It makes little sense to review a pull request that hasn't passed all test yet since there might be failures and further changes to address them.

3. There's no way for PR author to know when their pull request is ready to be merged

How does this process work in your team and are you happy with it? What's the most annoying part of reviewing others pull requests?
Regards!
Daily Developer Jokes - Sunday, May 24, 2020
Tags: jokes, dailydeveloperjokes
Published: 2020-05-24 12:00:06

---
title: "Daily Developer Jokes - Sunday, May 24, 2020"
description: "Check out today's daily developer joke! (a project by Fred Adams at xtrp.io)"
series: "Daily Developer Jokes"
cover_image: "https://private.xtrp.io/projects/DailyDeveloperJokes/thumbnail_generator/?date=Sunday%2C%20May%2024%2C%202020"
published: true
tags: #jokes, #dailydeveloperjokes
---

Generated by Daily Developer Jokes, a project by [Fred Adams](https://xtrp.io/) ([@xtrp](https://dev.to/xtrp) on DEV)

___Read about Daily Developer Jokes on [this blog post](https://xtrp.io/blog/2020/01/12/daily-jokes-bot-release/), and check out the [Daily Developer Jokes Website](https://dailydeveloperjokes.github.io/).___
### Today's Joke is...
![Joke Image](https://private.xtrp.io/projects/DailyDeveloperJokes/public_image_server/images/5e12592f4bd15.png)

---
*Have a joke idea for a future post? Email ___[xtrp@xtrp.io](mailto:xtrp@xtrp.io)___ with your suggestions!*

*This joke comes from [Dad-Jokes GitHub Repo by Wes Bos](https://github.com/wesbos/dad-jokes) (thank you!), whose owner has given me permission to use this joke with credit.*

<!-- 
Joke text:
___Q:___ Why do Java developers wear glasses?

___A:___ Because they don't C#!
 -->
🌍Game: test your reactions (CSS + JS) [YouTube LIVE]!
Tags: javascript, tutorial, frontend, game
Published: 2020-05-24 11:54:15

⬇️In this video we will create a simple JS game using jquery. The scope of the game is to click the squares/circles as fast as you can!


###Useful links
- Codepen: https://codepen.io/EleftheriaBatsou
- Working project: https://codepen.io/EleftheriaBatsou/pen/BaobOma
- On youtube: https://youtu.be/aHP9Ks15TKs

###If you guys recreate this project send me a link to check it. 

************************************

👋Hello, I' m Eleftheria, an app developer, master student, public speaker, and chocolate lover.

🍩Would you care about buying me a coffee? You can do it here: [paypal.me/eleftheriabatsou](paypal.me/eleftheriabatsou) but If you can't that's ok too!

**************************************

🙏It would be nice to subscribe to my [Youtube](https://www.youtube.com/c/EleftheriaBatsou) channel. It’s free and it helps to create more content.

🌈[Youtube](https://www.youtube.com/c/EleftheriaBatsou) | [Codepen](https://codepen.io/EleftheriaBatsou) | [GitHub](https://github.com/EleftheriaBatsou) | [Twitter](https://twitter.com/BatsouElef) | [Site](http://eleftheriabatsou.com/) | [Instagram](https://www.instagram.com/eleftheriabatsou/)
Angular: Interaction between Component with Shared service
Tags: tutorial, javascript, webdev, angular
Published: 2020-05-24 11:52:46

---
title: Angular: Interaction between Component with Shared service
published: true
description: Angular: Interaction between Component with Shared service
tags: Tutorial, JavaScript, WebDev, Angular
---

In this video, We are going to learn how we can have interaction between components via shared service.

If you have not seen my first video about Interaction between Component with @Input and @Output in Angular and then I would highly recommend it to see that video. Following is a link to that video.

https://bit.ly/AngularComponentInteraction

In this video, I have created a shared service that has got a message source as behavior subject from rx.js which holds an observable. By default, I have initialized it as the default message. Then I have created a new method where I have created a method called "change message"  from where the user can change the message.

After that, I have injected this service into two different components and subscribe to current message observable. I have also created a button click event in both components which calls the  Change message method from shared service. As we have subscribed to both our message observable it will reflect in message change in both components.



{% youtube BwGuU1QNqcY%}


Source Code for this video is available on - https://github.com/JalpeshVadgama/AngularSharedService


If you like this video and wanted to see a similar kind of video then, please subscribe to my youtube channel at - https://bit.ly/codewithjv.
How to Use Google Calendar to Improve Productivity?
Tags: productivity
Published: 2020-05-24 11:46:43

I heard about this trick the first time from him:

[I tracked every minute of my life for 3 months.](https://youtu.be/LUjTvPy_UAg)

I think Matt made this sound a little bit harder than what it really is.

Simply the idea is to create new calendars for each project, hobby, etc. you have and some other things like freetime. Then you just mark stuff after you have done them to the calendar.

I track everything I do in 15 min accuracy. It means that if I do A for 12 minutes and B for 3 minutes I just mark A. I try to do this the whole awake time.

The thing is that I’m not always checking my calendar and updating but sometimes I just mark stuff later the same day. I don’t use too  specific descriptions but just rather create one bigger block and call it something like “coding the app” and then as it’s in certain calendar I know what app I’m talking about.

What benefit this gives to me?

First of all I have retrospective ([https://www.notion.so/lankinen/Retrospective-55b60057da9842f1af11dae17efd30bc](https://www.notion.so/lankinen/Retrospective-55b60057da9842f1af11dae17efd30bc)) in the end of every week and having a calendar that shows what I have done helps a lot. No one remembers what exactly they did on Monday noon. 

Then the second benefit is that I get pretty good overview of what I have done and can notice some time leaks. If I spend too much freetime there will be a lot of red (color of my freetime calendar) blocks everywhere and it motivates me to spend less freetime the next week.

Thirdly, I just like making journals and document stuff. I started documenting stuff some time ago because I just wanted to be available to look 50 years later what I did when I was 19 years old. Everyone gets really good feeling when they see some old pictures of themselves and that’s what I’m looking for. I also try to share most of my stuff so other people can learn from my mistakes and victories but right now at least I haven’t shared my calendar publicly. There shouldn’t bee anything too private so if you are interested you can try to get it by contacting me.

Props from the cover image to [Elle Cartier](https://unsplash.com/@ellecartier)