teleren/devto huggingface dataset:
Stack Data Structure in Python
Tags: python, datastructure, stack
Published: 2021-04-09 06:35:41

**A great analogy we can utilize is stacking a heap of books. We tend to ceaselessly keep a shiny new book on top and take away the top most book**

## What is a stack ?
Stack is a linear data structure which stores items using `Last In, First Out(LIFO)`strategy. Whenever a new element is added to a stack, it is added to the highest point of the stack, and the top element is taken out first from the stack.

**Stack in Python can be executed in following ways:**

- List
- collections.deque
- queue.LifoQueue

**Some of the functions related with stack are:**
- push():When this function is called, new element is added at the top of the stack
- pop():This function removes the top most element of the stack
- empty():Return True if the stack is empty else returns False
- peek(): This function returns the top element of the stack

**Implementation of Stack**
```
class Stack():
    def __init__(self):
        self.items = []
    def push(self, item):
        self.items.append(item)
    def pop(self):
        return self.items.pop()
    def is_empty(self):
        return self.items == []
    def peek(self):
        if not self.is_empty():
            return self.items[-1]        
    def get_stack(self):
        return self.items
s=Stack()
print("Stack is Empty:",s.is_empty())
s.push("A")
s.push("B")
s.push("C")
s.push("D")
s.push("E")
s.push("F")
print("Stack after appending =",s.get_stack())
s.pop()
s.pop()
print("Stack after removing elements =",s.get_stack())
print("Peek element =",s.peek())
```

**Output:**
``` 
Stack is Empty: True
Stack after appending = ['A', 'B', 'C', 'D', 'E', 'F']
Stack after removing elements = ['A', 'B', 'C', 'D']
Peek element = D 
```
JavaScript assignments - 2
Tags: javascript, practice, begginer
Published: 2021-04-09 10:26:20

---
title: JavaScript assignments - 2
published: true
description: 
tags: javascript, practice, begginer 
//cover_image: https://direct_url_to_image.jpg
---
This blog posts introduce another simple JavaScript assignment and solution for it.

This assignment is great to practice JavaScript and develop problem solving thinking.

As usual, if you have a another solution, please write it in the comment section.


**Assignment:**
Write a JavaScript program to get the current date.

Expected output: 
mm-dd-yyyy, mm/dd/yyyy or dd-mm-yyyy, dd/mm/yyyy 

```const dateFormat = (date = new Date()) {
const days  = date.getDate();
const months = date.getMonths() + 1; 
//because months are 0 based (January is number 0)
const years = date.GetFullYears();
   return `${months}-${days}-${years}`
}`
console.log(dateFormat());
//4-9-2021
Simple trapping rainwater
Tags: javascript, algorithms
Published: 2021-04-09 10:24:23

This is a fast and simple solution for the trapping rainwater problem. We just use two pointers, for the start and end of the list. Then keep track of the highest columns so far from the start `sMax` and the end `eMax`.

``` javascript
        sMax = Math.max(sMax, height[str])
        eMax = Math.max(eMax, height[end])
```

Then, the pointer that is higher stays in its position, and the other moves. 

``` javascript
        if(sMax < eMax){ // move start pointer
            water+= sMax - height[str++]
            // highest left yet, minus current 
        }else{ // move end pointer
            water+= eMax - height[end--]
            // highest right yet, minus current
        }
```

This allows calculating the water by subtracting the current height from the max height. 

![by Inge Maria in Unsplash](https://images.unsplash.com/photo-1438449805896-28a666819a20?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=1350&q=80)

``` javascript

// [0,1,0,2,1,0,1,3,2,1,2,1] result: 6
// [4,2,0,3,2,5] result : 9

// calculate the water between the columns of height -> height[current]

const trapRainWater = (height) => {
    let str = 0, 
    end = height.length - 1, 
    water = 0, 
    sMax = 0, 
    eMax = 0;

    while(str<=end){
        sMax = Math.max(sMax, height[str])
        eMax = Math.max(eMax, height[end])

        if(sMax < eMax){ // move start pointer
            water+= sMax - height[str++]
            // highest left yet, minus current 
        }else{ // move end pointer
            water+= eMax - height[end--]
            // highest right yet, minus current
        }
    }
    return water
}

```

Feel more than welcome to reach out with any ideas/comments at [Linkedin](https://www.linkedin.com/in/santiago-salazar-pavajeau/) or [Twitter](https://twitter.com/santispavajeau), and check out my [portfolio!](https://www.santiagosalazarpavajeau.live).
Rock , Paper & Scissors - Day 13
Published: 2021-04-09 10:23:12

Created a rock, paper and scissors game using JavaScript, it was an awesome experience as I learnt about using event listeners, and how to load it on window, felt awesome and is a must do project for beginners, thank you for your time. 

For demo and resources, visit my LinkedIn profile: https://www.linkedin.com/posts/ashutoshyadav3465_100daysofcode-javascript-python-activity-6786146315081392128-ngJM

Hope you guyzz like it !!!
How to use Java 8 Stream Reduce Examples with List and Array
Tags: java8, stream, reduce
Published: 2021-04-09 10:13:29

https://grokonez.com/java/java-8/how-to-use-java-8-stream-reduce-examples-with-list-and-array


How to use Java 8 Stream Reduce Examples with List and Array


Java 8 provides an extremely powerful abstract concept Stream with many useful mechanics for consuming and processing data in Java Collection. In the tutorial, We will do lots of examples to explore more the helpful of Stream API with reduction operation on the specific topic: "Java 8 Stream Reduce Collection”.

What will we do?
<ul>
<li>Explain how Java 8 Stream Reduce work?</li>
<li>Apply Stream Reduction on Java List, Array</li>
</ul>
Now let’s do examples for more details!

Related posts:
- <a href="https://grokonez.com/java/java-8/how-to-use-java-8-stream-flatmap-examples-with-list-array">Java 8 Stream FlatMap Examples</a>
- <a href="https://grokonez.com/java/java-8/java-how-to-use-stream-filter-in-java-8-with-list-array-examples">Stream Filter in Java 8</a>

<!--more-->
<h2>Java Stream Reduce</h2>
Java Stream Reduction is a terminal operation that aggregates a Java Stream then returns one value by combining the contents of a stream. 

Many reduction operations perform a specific task such as: <code>average</code>, <code>sum</code>, <code>min</code>, <code>max</code>, and <code>count</code>.

- <strong>Examples</strong>: 

+ Initial Java List:

<pre><code class="language-java">List&lt;Integer&gt; intLst = Arrays.asList(1, 3, 5, 2, 9, 8, 15, 12);</code></pre>

+ How to <strong>sum</strong> all Element of a Stream?

<pre><code class="language-java">int totalOpt = intLst.stream().mapToInt(i-&gt;i).sum();
System.out.println(totalOpt);
// 55</code></pre>

+ How to get <strong>average</strong> value of an Integer List?

<pre><code class="language-java">
OptionalDouble averageOpt = intLst.stream().mapToInt(i->i).average();
averageOpt.ifPresent(System.out::println);
// 6.875</code></pre>

+ How to get Min/Max value of an Integer List?

<pre><code class="language-java">
/* Get Min Value */
OptionalInt minOpt = intLst.stream().mapToInt(i->i).min();
minOpt.ifPresent(System.out::println);
// 1

/* Get Max value */
OptionalInt maxOpt = intLst.stream().mapToInt(i->i).max();
maxOpt.ifPresent(System.out::println);
// 15
</code></pre>


More:

https://grokonez.com/java/java-8/how-to-use-java-8-stream-reduce-examples-with-list-and-array
Windmill - Open-source React Dashboard
Tags: react, webdev, dashboards
Published: 2021-04-09 10:07:43

Hello Coders,

This article presents an open-source accessibility-first **[React Dashboard](https://dev.to/sm0ke/react-dashboards-open-source-apps-1c7j)** available for download from the official product page (no account required). **Windmill Dashboard** comes with a blazing fast UI styled with Tailwind, PWA support and integrations for Charts.js and Heroicons.  For newcomers, **React** is an open-source library for coding UI interfaces actively versioned and supported by Facebook.

---

- [React Dashboard Windmill](https://windmillui.com/dashboard-react) - product page
- [Windmill Demo](https://windmill-dashboard-react.vercel.app/) - LIVE deployment of this modern React Dashboard

---

![React Dashboard - Windmill, free dashboard template.](https://raw.githubusercontent.com/admin-dashboards/windmill-dashboard-react/master/media/windmill-dashboard-react-intro.gif)

---

## Product Description

Windmill Dashboard is not a lifeless template. This is a complete application, built on top of  React, with all tiny details taken care of so you just need to bring the data to feed it.


**Accessibility-first** -  the product was developed listening to real screen readers, focus traps and keyboard navigation are available everywhere.


**UI Kit** - Windmill Dashboard React is built on top of Windmill React UI - open-source component library based on Tailwind CSS.

---

## Product Features

- 🦮 Throughly accessible (developed using screen readers)
- 🌗 Dark theme enabled (load even different images based on theme)
- 🧩 Multiple (custom) components
- ⚡ Code splitting
- UI: Tailwind CSS, Windmill React UI (components library)
- Routes coded on top of React Router
- Plugins: Heroicons, Chart.js
- PWA-ready: delivering offline-first and app-like experience

---

> **Windmill React** - Product Page

![Windmill React - product Page.](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4yabsarg2vgjryj1fn7n.png)

---

> **Windmill React** - UI Cards

![Windmill React - UI Cards.](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mpl9xh4sdustq4nvoyz0.png)

---

> Windmill React - Dark Mode On

![Windmill React - Dark Mode Active.](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qcyjg6mad51ijymly3tn.png)

---

> Windmill React - Login Page

![Windmill React](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uu213a8rxirk88pfjiec.png)

---

> **Thanks for reading!** For more resources, please access:

---
 
- [Estevan Maito](https://twitter.com/estevanmaito) (twitter page) - the creator of this modern React Dashboard
- More **[React Dashboards](https://dev.to/sm0ke/react-dashboards-open-source-apps-1c7j)** - a curated list published on Dev.to
A tool to download attachments from Gmail
Tags: showdev, go
Published: 2021-04-09 10:03:16

Hi I'm Mirko.
Some months ago I have started learning Go in my free time, because I'm very interesting about it.

The best way I know to learn a new programming language is to use it into a tiny but real and useful (at least for me) project.

This is the story behind [gmail-downloader](https://github.com/mirkoperillo/gmail-downloader).

## What is it ?

It's a cli tool that permits to download all email attachments selecting a particular label from Gmail.
It uses the official google go sdk for gmail.

It's my first experiment using Go and it is released on Github with GPLv3 license.
Every feedback about the code or the features is very welcome 🙏🏻
Java 8 Stream.collect() - Stream.Collectors APIs Examples
Tags: java8, stream, collectors
Published: 2021-04-09 09:55:41

https://grokonez.com/java/java-8/java-8-stream-collect-stream-collectors-apis-examples

Java 8 Stream.collect() - Stream.Collectors APIs Examples

[no_toc]
Java 8 provides an extremely powerful abstract concept Stream with many useful mechanics for consuming and processing data in Java Collection. In the tutorial, We will do lots of examples to explore more the helpful of Stream API with Collectors operation on the specific topic: "Java 8 Stream Collector".

What will we do?

<ul>
<li>Explore Stream Collect Method signatures</li>
<li>Apply Stream Collectors Util with Examples</li>
</ul>

Now let’s do more details!

Related posts:
- <a href="https://grokonez.com/java/java-8/how-to-use-java-8-stream-reduce-examples-with-list-and-array">Java 8 Stream Reduce Examples</a>
- <a href="https://grokonez.com/java/java-8/how-to-use-java-8-stream-flatmap-examples-with-list-array">Java 8 Stream FlatMap Examples</a>

<!--more-->
<h2>Java Stream.collector()</h2>


More:

https://grokonez.com/java/java-8/java-8-stream-collect-stream-collectors-apis-examples
How to improve your code: tips and reflections
Tags: codequality, webdev, productivity, beginners
Published: 2021-04-09 09:40:07

---
title: How to improve your code: tips and reflections
published: true
description: There are several ways to achieve the same result, some are much better, others are more context-appropriate.
tags: codequality, webdev, productivity, beginners
cover_image: https://images.unsplash.com/14/unsplash_5243e9ef164a5_1.JPG?ixlib=rb-1.2.1&ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&auto=format&fit=crop&w=1500&q=80
---

In my experience I have learned, with difficulty and by imposing humility on my pride, that often one's code can be improved.

> There are several ways to achieve the same result, some are much better, others are more context-appropriate.

Some advices:

- Analyze the context and purpose

- Take your time for analysis

- It can help you write down on paper or represent the situation schematically

- You have to be far-sighted in the solution, it will have to work even in 10 years with new technologies

- *Dividi et impera*: granulate your code, simplify it into sub-tasks

- Take breaks where you think about other things and then look at what you have written critically: "How or where can I improve?"

- Compare yourself to other devs! When I am stuck, by exposing the problem I find the solution or I am provided with points of reflection.

- Details matters: it is precisely the details that give that sense of quality; without these the evaluation could be *good* or *very good*, while paying attention to the details the evaluation will be *excellent*.
Js While Loop - Help ! (Solved)
Tags: javascript, webdev
Published: 2021-04-09 09:37:00

Hello dear! Hope you're all doing well !
I'm newbie with js and I've written the code below but it doesn't work the way I expected it to do. Need help !
The thing is, I want the loop to continue until "numberToGuess = guessNumber" but unfortunately, it breaks at second loop; even if numberToGuess is not equal to guessNumber.
Can Someone explain me how to fix that please ?
Thx!



const numberToGuess = Math.round(10*Math.random());
let guessNumber;

while(numberToGuess !== guessNumber){
  guessNumber = prompt("Guess the hidden number: ");
  if(guessNumber < numberToGuess){
    console.log("Too low");
  }else if(guessNumber > numberToGuess){
    console.log("Too high");
    }
}

console.log("Congrats ! You found it !");
console.log("Number to guess = " + numberToGuess + "\nGuessed number = " + guessNumber);
Dynamically Add & Remove List Items | Using JavaScript 
Tags: html, css, javascript, codereview
Published: 2021-04-09 09:33:22

Dynamically Add & Remove List Items | Using JavaScript 
Demo ==> https://codepen.io/Bilal1909/pen/MWJgxQJ

<img src="https://i.postimg.cc/QC4q475c/screenshot-codepen-io-2021-04-09-14-31-44-500.png">
What is a Linter and Why You Should Use One | Linters EXPLAINED
Tags: devops, codenewbie, linters, video
Published: 2021-04-09 09:29:19

__What is a linter__? How does a linter work? Why __should I use a linter__?

These questions, and many more, come up every time I talk about linting to some teams. For this reason I've put together this "__linting explained__" type of video, in which I will try and answer all of the most common questions about linters. We will also see why is a linter important, and how linter works.

### Video

Watch the full video here 🤓

{% youtube HDQXWr5TOnI %}

[Link to the video: https://youtu.be/HDQXWr5TOnI](https://youtu.be/HDQXWr5TOnI)

Let me know below what you think! Do you have any other questions about Linters and Linting? 

__Stay tuned__ because I will soon have another post and video about the __GitHub Super Linter__!

__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)

{% youtube HDQXWr5TOnI %}
Get Amazing  Discounts, Offers  & Coupons  On Netrockdeals

Tags: deals, offers, discount, sale
Published: 2021-04-09 09:19:29

Netrockdeals is India's most trusted website for online shopping. If you are someone who loves online shopping but are tired of wasting all your money then this is your one-stop solution for all types of shopping. Whether you want clothes, cosmetics, footwear, sportswear, sports gear, home appliances, gadgets, tickets for anything, travel accommodation or flights, food coupons, or anything else. you will find it on Netrockdeals. They offer amazing deals, discounts, offers, and promo codes in all these categories. They have all the top and non-recognizable brands all on one page. You won't have to skim through the internet for <a href="https://www.netrockdeals.com/store/zivame-coupons/">Zivame Coupon</a>
 different brands and products but you will find everything on Netrockdeals. Then you can look through all the deals and coupons of your selected product and can avail that coupon on the portal of the main website while making the payment on the checkout page. The best part is that not only you will save money by getting these coupons but also, you have the chance of earning cashback. They also have special deals and offers for every occasion, like Diwali, Christmas, Summer session, and all the other occasions where you will require to purchase gifts. Right now they have amazing deals and offers regarding Summer sale that you can checkout and save your money. so shop from Netrockdeals and save money on all the occasions.
MongoDB - Model One-to-One, One-to-Many Relationships Embedded Documents | SpringBoot
Tags: mongodb, springboot, onetomany
Published: 2021-04-09 09:19:10

MongoDB - Model One-to-One, One-to-Many Relationships Embedded Documents | SpringBoot

https://grokonez.com/spring-framework/spring-data/mongodb-model-one-one-one-many-relationships-mongodb-embedded-documents-springboot

With <strong>MongoDB</strong>, we can structure related data by embedded documents. In general, embedding gives a better performance for read operations. So in the tutorial, <a href="https://grokonez.com">JavaSampleApproach</a> will show you way to work with <strong>Embedded Documents</strong> using SpringBoot.

Related posts:
- <a href="https://grokonez.com/spring-framework/spring-boot/configure-spring-jpa-one-to-many-relationship-springboot">Spring JPA One to Many Relationship</a>
- <a href="https://grokonez.com/spring-framework/spring-boot/how-to-use-springdata-mongorepository-to-interact-with-mongdb-springboot-application">SpringData MongoRepository</a>
- <a href="https://grokonez.com/spring-framework/spring-boot/springdata-mongodb-gridfstemplate-save-retrieve-delete-binary-files-image-text-files">SpringData MongoDB GridFsTemplate to save, retrieve, delete binary files (Image, Text files)</a>
- <a href="https://grokonez.com/spring-framework/spring-boot/angular-4-spring-boot-mongodb-crud-example">Angular 4 + Spring Boot + MongoDB CRUD example</a>

<!--more-->
<h2>I. Technologies</h2>
– Java 1.8
– Maven 3.3.9
– Spring Tool Suite – Version 3.8.1.RELEASE
– Spring Boot: 1.5.6RELEASE
– MongoDB: v3.4.1
<h2>II. MongoDB - Embedded Documents</h2>
<strong>Embedded Documents</strong> are generally known as <em>denormalized</em> models. It is a way to structure related data in a single document. See below diagram:

<img src="https://grokonez.com/wp-content/uploads/2017/08/mongodb-embedded-document-structure.png" alt="mongodb embedded document - structure" width="690" height="388" class="alignnone size-full wp-image-7396" />

In general, we decide to design data as embedded models in case: data contains <a href="https://grokonez.com/tag/one-to-one-jpa">one-to-one</a> or <a href="https://grokonez.com/tag/one-to-many">one-to-many</a> relationships between entities.

With embedding data model, in general, it gives us a better performance for read operations. And we can use a single atomic read/write database operation to request and retrieve or update related data.

However, a weakness point is embedding related data in documents may lead to situations where documents grow after creation.
<h2>III. Practice</h2>

More at:
https://grokonez.com/spring-framework/spring-data/mongodb-model-one-one-one-many-relationships-mongodb-embedded-documents-springboot
49 Days of Ruby: Day 14 - Regular Expressions
Tags: ruby
Published: 2021-04-09 09:11:36

---
title: 49 Days of Ruby: Day 14 - Regular Expressions
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 14 of the 49 Days of Ruby! 🎉**

After 13 days of learning some of the core concepts in programming through Ruby, we are going to take a small detour and discuss regular expressions. There is indeed Ruby implementations for handling regular expressions (regex), but the topic itself is worth focusing on for a bit.

## What is a Regular Expression?

A regular expression, regex for short, is a set of characters that allow you to compose a **search pattern**. You can use that search pattern to traverse through data to find a match.

You can imagine how helpful something like that is!

However, its usefulness is often overshadowed by its complexity. Regex can be very difficult to compose and to break down.

Thankfully, there are tools to help you in composing and understanding a regular expression. We'll highlight them in just a moment.

## Regex in Ruby

The best way to understand Regex is to see an example.

```ruby
order_number = "456-222-1111"

order_number.gsub!(/\D/, "")

# => "4562221111"
```

The Ruby method `#gsub!` is used to replace the matching characters with the replacement text. The pattern to match against, the regex, is in the first half of the method. The replacement text is in the second half, after the comma.

In the example above, the regex pattern of `\D` looks for any *non-digit*. The `#gsub!` method searches for that pattern and then replaces it with an empty string. You could also replace it with anything else.

The result is the `order_number` now holds a string with all the dashes removed.

The example we showed is a fairly straightforward use case. Regex can get a lot more complex. Take a look at [this example](https://stackoverflow.com/questions/40421859/complex-regex-in-ruby) from Stack Overflow: `/\d+(?=:)|\d+(?=,\|,\d)|(?<=\d,\|,)\d+/`. Talk about making your head spin!

Thankfully, there are some tools available to lend you a hand.

## Regex Resources

If you want to explore Regex more, both in Ruby and generally, here are some good places to check out:

* [Rubular](https://rubular.com/)
* [RubyGuides: Regex](https://www.rubyguides.com/2015/06/ruby-regex/)
* [Cool Ruby Regex Tips](https://www.honeybadger.io/blog/ruby-regex-tricks/)

That's it for now! Enjoy your learning and see you tomorrow!

**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).**
C++
Published: 2021-04-09 08:57:20

void __fastcall TfrmMain::GetIPAddress(void)
{
     AnsiString ip("");
     WORD wVersionRequested;
     WSADATA wsaData;
     //Start up WinSock
     wVersionRequested = MAKEWORD(1, 1);
     WSAStartup(wVersionRequested, &wsaData);
     //////////////////////
     hostent *p;
     char s[128],*p2;
     //Get the computer name
     gethostname(s, 128);
     __COMPUTERNAME = s;
     p = gethostbyname(s);
     //Get the IpAddress
     p2 = inet_ntoa(*((in_addr *)p->h_addr));
     ip = p2;
     WSACleanup();
     ///// Close winsock /////
     //return ip;
     __IP = ip;
}
//---------------------------------------------------------------------------