teleren/devto huggingface dataset:
Implementing Queue with 2 Stacks
Tags: tutorial, datastructure, java, javascript
Published: 2020-08-23 12:46:59

BEGIN:

I'm assuming you are familiar with the vocabulary of 
- Stack
> PUSH = Add to end
> POP = Get from end

- Queue
> ENQUEUE = Add to end
> DEQUEUE = Return from beginning 


Prerequisite: You only need to know this 
- In Java when you "ADD" to ArrayList, it adds in the end.
- Similarly, if you use Javascript, you "PUSH" to an array, it adds the value in the end of the array.

So, I came across this simple yet interesting topic of implementing a Simple Queue (FIFO) with 2 Stacks (LIFO)


Having done this program in university (where I used scratch implementation in C++),  I believe now more conciseness is required for interview preparations - and hence I'm using JAVA's native ArrayList to implement my own Stack and Queues.
 
```java

import java.util.ArrayList;
import java.util.List;

public class MyStack {

    private final List<Integer> stack = new ArrayList<>();

    void push(int item) {
        stack.add(item);
    }

    int pop() {
        if (!stack.isEmpty()) {
            return stack.remove(stack.size() - 1);
        }
        return -1;  // if nothing found
    }

    int size() {
        return stack.size();
    }

    boolean isEmpty() {
        return stack.isEmpty();
    }
}
```

So, now we have our Stack - it's that simple ;)

And here's our Queue
```java

public class MyQueueWithTwoStacks {

    private final MyStack firstStack;
    private final MyStack secondStack;

    public MyQueueWithTwoStacks() {
        this.firstStack = new MyStack();
        this.secondStack = new MyStack();
    }

    boolean isEmpty() {
        return firstStack.isEmpty() && secondStack.isEmpty();
    }

    int size() {
        return firstStack.size() + secondStack.size();
    }

    void enqueue(int item) {
        firstStack.push(item);
    }

    /**
     * We will use the second stack to out the values, if the second bucket is
     * empty that means we need to copy over all stack1 entries to it
     *
     * @return returns the value
     */
    int dequeue() {
        if (secondStack.isEmpty()) {
            while (!firstStack.isEmpty()) {
                secondStack.push(firstStack.pop());
            }
        }

        return secondStack.pop();
    }
}

```

Reference: 
- If you like theoretical overview, here's a super nice [Post by @jellybee](https://dev.to/jellybee/queue-using-stacks-stack-using-queues-ab0)



END.
First time with a Virtual Machine
Published: 2020-08-23 12:44:19

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/vrds85ubx7n77lyggg7m.png)
<br>
A few days ago, I started fiddling around on The Odin Project and was like “what the hey, let’s do some stuff here.” One thing I wanted to learn was Git and some commands in the terminal. The Odin Project offers some intro lessons on both, so I decided to start there.

For context, my two computers are 1. a Windows desktop, and 2. a work Macintosh laptop which is locked down pretty tight. For working on the terminal, I didn’t think my Mac would let me have enough access to do the lessons, and I have been told by many people (including The Odin Project) to stay away from the Windows command line. What to do?

The answer was to create a virtual machine on my computer. I didn’t know how, however The Odin Project was pretty helpful with their walkthrough (which you can find [here](https://www.theodinproject.com/courses/web-development-101/lessons/prerequisites)). Because I didn’t know too much about virtual machines, I went with the recommendation to use Xubuntu, a lightweight operating system based off Linux. Here are the steps I took:

1.  Downloaded Oracle’s [VirtualBox](https://www.virtualbox.org/wiki/Downloads) (which after doing some research was listed as one of the best virtual machine programs out there)

2.  Downloaded Xubuntu from The Odin Project’s site

3.  Added Xubuntu to Virtual box per the [directions in the walkthrough](https://www.theodinproject.com/courses/web-development-101/lessons/prerequisites)

4.  Booted it up for the first time and explored!

This took me probably an hour and a half total to do, since I was also looking up stuff on the side and had to trouble shoot how to allow my computer to add a second CPU (hint: it’s in the BIOS). Once I got that sorted and logged in, I was pretty excited to check it out.

I have never had a Linux computer before, so I’m pretty excited to work with it. After having it for a few days, it works really well. I use the terminal for my Git lessons, and it came preloaded with Firefox, which I use now too. And if I want to switch back to Windows for some gaming or for work, it’s super easy to shut down Linux. As a note, Windows continues to run the whole time I’m in Linux since it’s the host OS, however apparently Xubuntu doesn’t take up a lot of space or resources to run.

If you are looking at doing a virtual machine at some point, let me know! And also, if you have any Linux/Xubuntu tips, also please drop those in the comments.
Splice in JavaScript
Tags: javascript, webdev, tutorial, beginners
Published: 2020-08-23 12:34:15

The splice method changes the content of the array in place and can be used to add or remove items from the array.

```js
const arr = ["🌼", "🌴", "🌹", "🌵", "🍄"];
arr.splice(2,3); // ["🌹", "🌵", "🍄"]
console.log(myArr); // ["🌼", "🌴"]
```

<u>Syntax:</u>

```js
let arrDeletedItems = array.splice(start[, deleteCount[, item1[, item2[, ...]]]])
```

`start` specifies index at which to start changing the array.

If `start` is greater than the length of the array, then `start` will be set to the length of the array. i.e no element will be deleted.

If `start` is negative, it will begin that many elements from the end of the array.

In `deleteCount`, The number of items you want to remove.

In `item`,  The number you want to add(*If you're removing, you can just leave this blank).*

<mark>NOTE</mark>: Splice always return an array containing the deleted elements.

🌚 When only one argument is provided, all the items after the provided starting index are removed from the array:

```js
const arr = ["🌼", "🌴", "🌹", "🌵", "🍄"];
arr.splice(2); // ["🌹", "🌵", "🍄"]
console.log(myArr); // ["🌼", "🌴"]
```

🌚 Remove 1 element at index 3:

```js
const arr = ["🌼", "🌴", "🌹", "🌵", "🍄"];
arr.splice(3, 1); // ["🌵"]
console.log(myArr); // ["🌼", "🌴", "🌹", "🍄"]
```

🌚 An arbitrary amount of additional arguments can be passed-in and will be added to the array:

```js
const arr = ["🌼", "🌴", "🌹", "🌵", "🍄"];
arr.splice(2, 1, "⭐️", "💥"); // ["🌹"]
console.log(myArr); // ["🌼", "🌴", "⭐️", "💥", "🌵", "🍄"]
```

🌚 Remove 1 element from index -2:

```js
const arr = ["🌼", "🌴", "🌹", "🌵", "🍄"];
arr.splice(-2, 1); // ["🌵"]
console.log(myArr); // ["🌼", "🌴", "🌹", "🍄"]
```

🌚 You can specify 0 as the number of items to remove to simply add new items at the specified location in the array:

```js
const arr = ["🌼", "🌴", "🌹", "🌵", "🍄"];
arr.splice(2, 0, "⭐️", "💥"); // []
console.log(myArr); // ["🌼", "🌴", "⭐️", "💥", "🌹", "🌵", "🍄"]
```

🌚 Add few items at the end of array:

```js
const arr = ["🌼", "🌴", "🌹", "🌵", "🍄"];
arr.splice(arr.length, 0, "🌕", "🌞", "🌦"); // []
console.log(myArr); // ["🌼", "🌴", "🌹", "🌵", "🍄", "🌕", "🌞", "🌦"]
```

## Reference 🧐

<a href='https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice'>Splice MDN</a>

<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>
Docker Basics
Tags: docker, webdev, beginners
Published: 2020-08-23 12:16:30

As a newbie the first question that comes to mind is What is Docker ?
So, A docker is a command line program, a background daemon and set of remote services that simplifies installation, running, publishing or removing software.

Docker is NOT virtualization.

Running docker means running two programs : docker CLI and docker daemon.
Docker containers are isolated with 8 aspects:
1 . PID namespace : process identifiers and capabilities
2 . UTS namespace : host and domain space
3 . MNT namespace : File system access and structure
4 . IPC namespace : Process communication over shared memory
5 . NET namespace : Network access and structure
6 . USR namespace : User name and identifiers
7 . chroot() : controls location of file system root
8 . cgroups : Resource protection

What are Images ?
A bundled snapshot of all the files that should be available to a program running inside a container.

What is container ?
It is a running or stopped instance of some image.

We can create as many container from an image but containers that are created from same image don't share changes to their file systems.
Here are few basic commands to run :

1 . docker run hello-world
You will get output as :
**Hello from Docker!
This message shows that your installation appears to be working correctly.**

2 . **docker run --detach --name web nginx : latest**
 or 
**docker run -d --name web nginx : latest**
where -d or --detach  will start the program in background

3 . To check currently running containers : 
**docker ps**
This will only display running containers but if you want to see all including those in exited state then :
**docker ps -a**

4 . To check docker logs :
**docker logs** 
 
5 . To continue watching logs :
**docker logs --follow**

These are few very basics of the docker. Hope it helps !!!
Domain Name Server: Give me the IP address.
Tags: codenewbie, devops, computerscience
Published: 2020-08-23 12:05:07

In the real world as humans we feel comfortable identifying everything around us with specific names whether it be other humans,animals or any object we associate its identification with various names but while on the internet computers/servers are identified with numbers also know as IP addresses.These IP addresses are the reason we are able to communicate with various computers all over the world with the help of internet.

As we feel comfortable with names but the computers on the network use numbers for their identification there tends to arise a problem where we find it hard to memorize these long numeric addresses to communicate with computers so as a result to resolve this and help people use the internet and communicate with various servers were made easy with the introduction to DNS also know as Domain Name System.
Domain Name System is the bridge which translates IP addresses to domain names.For examples these are various domain names with their IP addresses.

* Name: facebook.com
Address: 157.240.198.35(IP V4)
Name: facebook.com
Address: 2a03:2880:f144:82:face:b00c:0:25de(IP V6)
* Name: google.com
Address: 172.217.160.174(IP V4)
Name: google.com
Address: 2404:6800:4009:80a::200e(IP V6)
* Name: linkedin.com
Address: 108.174.10.10(IP V4)
Name: linkedin.com
Address: 2620:109:c002::6cae:a0a(IP V6)

**You could copy and paste the IP V4 addresses which will automatically redirect you to their respective domain names.**

## THE PROCESS

* As our machine could not resolve the domain’s IP address within our machine it sends a query to your ISP’s server where if our ISP’s server has the IP address cached it will provide it to us then our machine could request for the results to the particular server with the help of the IP address provided by our ISP.

* If our ISP does not have the IP address we were looking for it sends a request to the ROOT SERVER.There are 13 sets of root servers around the world which are handled by 12 different organizations of the world.The root server then redirects the request to TLD servers also know as TOP LEVEL DOMAIN.These TLD servers are supposed to have addresses information for top level domains such as .com,.net,.org etc.But the TLD will still not have the IP address of our domain so it redirects us to Authoritative Name Server.

* Authoritative Name Servers are the ones who are supposed to have all the information regarding the domain.Then as the request reaches the authoritative name server it will have the desired IP address of the domain and then sends it back to our machine so that we can access the information we require via the web using the ip addresses associated with our query.

> As technology is just a tool to help us live a better and easier life DNS is also a tool which helps us browse the web in a easy and fast way so we could concentrate more on the information we seek rather than spending time trying to figure out the way get information from the internet with very confusing and long numeric addresses.
Scaffold your GitHub actions with Yeoman generator 🚀
Tags: showdev, javascript, webdev
Published: 2020-08-23 12:00:53

I created a Yeoman generator to easily scaffold your javascript-based Github actions. 

{% github https://github.com/RocktimSaikia/generator-github-action %}

Since the `#actionshackathon` is going on, there are going to be lots of forking and templating boilerplates. So I sat down and decided to create a Generator for this specific task so that you don't have to fork boilerplates every time you want to create a new Github Action.

Here is the Installation process followed by the Usage steps:

## Installation
```bash
npm install -g yo
npm install -g generator-github-action
```
> If you already have `yo` installed globally then skip the first step. Install the `generator` only.

## Example usage
```bash
yo github-action
```
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/abqxcp03rzlrhw0l0fhb.png)

That will present a prompt asking a few questions about your project name and description etc. After that, It will generate a minimal set up for you to work on a javascript based Github action. 

The generator will also install the bare minimum dependencies too so you don't have to worry about installion. You can just focus on writing your code for the action.

#### That's all :unicorn: :unicorn: :unicorn:

If you want to contribute to the project you can do that too. You can also leave star :zap: if you find this tool helpful that helps on keeping me motivated to keep creating these types of tools and modules.
Daily Developer Jokes - Sunday, Aug 23, 2020
Tags: jokes, dailydeveloperjokes
Published: 2020-08-23 12:00:19

---
title: "Daily Developer Jokes - Sunday, Aug 23, 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%20Aug%2023%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/5e1258a63bab5.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:___ What did the array say after it was extended?

___A:___ Stop objectifying me.
 -->
Leetcode 1299: Replace Elements with Greatest Element on Right Side
Tags: javascript, algorithms, leetcode, array
Published: 2020-08-23 11:45:49

This problem is part of [the Introduction to Data Structures Arrays-101 section](https://leetcode.com/explore/learn/card/fun-with-arrays/511/in-place-operations) in LeetCode.

## Problem Statement

Given an array `arr`, replace every element in that array with the greatest element among the elements to its right, and replace the last element with `1`.

After doing so, return the array.

**Example 1:**
```javascript
Input: arr = [17,18,5,4,6,1]
Output: [18,6,6,6,1,-1]
```

**Constraints:**
* 1 <= arr.length <= 10^4
* 1 <= arr[i] <= 10^5

## Solution 1: two loops
```javascript
var replaceElements = function(arr) {
    let newArr = []
    for(let i=0; i<arr.length; i++){    
        let max = arr[i+1]
        for(let j=i+1;j<arr.length;j++){
            let value = arr[j+1]
	    max = value > max? value: max
        }
        newArr.push(max)
    }
    newArr[arr.length-1] = -1
    return newArr
};
```

**Time complexity** : O(n²)
**Space complexity** : O(n)

## Solution 2: One loop

With last index as -1, we can start from the rightmost element, move to the left side one by one, and keep track of the maximum element. Replace every element with the maximum element.

For example:

let arr = [17,18,5,4,6,1]

and as we know: 

1. newArr[5] is -1 
2. newArr[4] is equal to arr[5]
3. newArr[3] is equal to the maximum number among arr[4] to arr[5]. This is also equal to the maximum number among arr[4] to newArr[4]

To simplify the logic, we can describe like this: 
```
newArr[0] = max(arr[1:5]) = max(arr[1], newArr[1])
newArr[1] = max(arr[2:5]) = max(arr[2], newArr[2])
newArr[2] = max(arr[3:5]) = max(arr[3], newArr[3])
newArr[3] = max(arr[4:5]) = max(arr[4], newArr[4])
newArr[4] = arr[5]
newArr[5] = -1
```
And the solution will be:

```javascript
var replaceElements = function(arr) {
    let newArr = [];
    newArr[arr.length-1] = -1;
    for (i = arr.length-2; i >= 0; i--) {
        newArr[i] = Math.max(newArr[i+1],arr[i+1]);
    }
    return newArr;
};
```
**Time complexity** : O(n)
**Space complexity** : O(n)
How to Make Your Own 1000 Calorie Diet
Published: 2020-08-23 11:13:04

<p>if you are trying to lose weight, a <a href="https://www.nutritionnew.com/the-1000-calorie-diet-plan-for-weight-loss/" target="_blank" rel="noopener">1000 calorie diet weight loss</a> can help you to cut down on calories and get the body of your dreams. I will show you in this article how much and what you have to eat to follow a 1000 calories a day diet. Here are the different food groups you have to eat and how much off to help get you started.</p>
<p><strong>Milk group</strong></p>
<p>Milk helps to speed up weight loss. If you don't like/can't drink milk give soy or rice milk a go.</p>
<p><strong>Units allowed</strong></p>
<p>For a 1000 calorie a day diet, you are allowed 2 units a day. Stick to fat free or low fat milk.</p>
<p><strong>Examples</strong></p>
<p>Good examples of milk products are milk, cheeses and yogurt.</p>
<p><strong>Fat group</strong></p>
<p>Fats are important,as they help to keep us full. Make sure that you stick to the healthier fats - the unsaturated ones.</p>
<p><strong>Units allowed</strong></p>
<p>To help you lose weight on a 1000 calorie meal plan, stick to no more than 4 units of fat.</p>
<p><strong>Examples</strong></p>
<p>Good examples of healthy fats are olives, avos, light mayonnaise, low fat margarine and butter and olive oil.</p>
<p><strong>Fruit group</strong></p>
<p><strong>Units allowed</strong></p>
<p>You are allowed 4 units of fruit while on the 1000 calories a day diet.</p>
<p><strong>Examples</strong></p>
<p>You can eat any type of fruit, whatever you like. And with so many choices, you will never be bored.</p>
<p><strong>Vegetable group</strong></p>
<p><strong>Units allowed</strong></p>
<p>Veggies are free on <a href="https://en.wikipedia.org/wiki/Dieting">easy 1000 calorie diet</a> - you can eat as much as you like.</p>
<p><strong>Examples</strong></p>
<p>Any veg is good for you, as long as you prepare them the healthy way. Steaming, grilling, roasting and boiling are all good preparation methods.</p>
<p><strong>Protein group</strong></p>
<p>Protein are vital for a healthy body and it helps you to burn fat and build muscle.</p>
<p><strong>Units allowed</strong></p>
<p>You may have 5 units of protein a day if you want to lose weight.</p>
<p><strong>Examples</strong></p>
<p>Stick to the healthier, lower fat proteins to cut back on calories and fat. Good examples are chicken, fish and lean red meat.</p>
<p>Carb group</p>
<p>Carbs supply the body with vital energy, so its better not to avoid all carbs.</p>
<p>Units allowed</p>
<p>You are allowed to have 4 units of carbs on a 1000 calorie meal plan.</p>
<p>Examples</p>
<p>Stick to the healthy carbs as they will give you longer lasting energy while also keeping you full. Good examples are baby and sweet potatoes and whole-wheat/grain products like couscous, rice and pasta.</p>
<p>Base your 1000 calorie a day diet around these foods and stick to the right portion sizes and you will lose weight</p>
Sobrevivir a las entrevistas
Tags: beginners, javascript
Published: 2020-08-23 10:31:10

_Llega el momento en la vida de cualquier dev, en que debe tener entrevistas. A veces puede ser un poco difícil controlar los nervios, la ansiedad. Les voy a contar mis experiencias y, quizás, les pueda servir a ustedes también._


Mi primer experiencia laboral fue a raíz de un bootcamp, entonces se podría decir que no tuve una primer entrevista en mi primer trabajo.
Antes solo tenía entrevistas con las empresas en las cuales me gustaría trabajar, por lo que la presión y los nervios eran siempre grandes. Porque yo quería verdaderamente quedar seleccionado.
Luego de ser rechazado varias veces decidí que tenía que cambiar el enfoque y se me ocurrió tener entrevista con cada oferta que me llegue. De esta forma
1. _"entrenaba"_ el ser entrevistado y lo naturalizaba.
2. Quizás encuentre muy buenas ofertas en empresas que no se me hubiese ocurrido.

**En un mes he tenido mas de 15 entrevistas**. Tanto las de recursos humanos, como técnicas. Y con esto, logré no ponerme nervioso y evitar errores, que solo por eso podían jugarme en contra.
Por eso, les recomiendo tener entrevistas seguido. Aunque no cumplan el 100% de los requisitos, apliquen igual. La idea es que les entrevisten y naturalizar el proceso.
Incluso pueden anotar que puntos tienen flojos para fortalecerlos y, en el mejor de los casos, encontrar ese trabajo o primer trabajo que nos ayude a crecer en nuestra carrera.

Espero que les sirva mi experiencia y me gustaría también saber que sienten ustedes cuando les entrevistan, como llevan los nervios, si intentaron el consejo que les di.
Pueden escribirlo en comentarios o hablarlo por [Twitter](https://twitter.com/ElSeraa).
¡Saludos!