teleren/devto huggingface dataset:
Algorithm of merge overlapping intervals
Tags: javascript, algorithms, computerscience, career
Published: 2021-03-02 01:00:25

---
title: Algorithm of merge overlapping intervals
published: true
description: 
tags: javascript, algorithms, computerscience, career
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wjcjyu9hbep4h0ta8aec.png
---


Solution for [complex](https://github.com/vvscode/js--interview-questions/blob/master/topics/complex.md#complex) js interview questions


```js
const mergeIntersectingRanges = (ranges) =>
  ranges
    .sort((a, b) => a[0] - b[0])
    .reduce(
      (acc, range) => {
        const indexOfLast = acc.length - 1;
        const prevRange = acc[indexOfLast];
        const end = prevRange[1];
        const start = range[0];

        if (end > start) {
          acc[indexOfLast][1] = Math.max(end, range[1]);
        } else {
          acc.push(range);
        }

        return acc;
      },
      [ranges[0]]
    );


mergeIntersectingRanges([[1, 4], [3, 6], [10, 12], [15, 19]]); 
// [[1,6], [10, 12], [15, 19]]


mergeIntersectingRanges([[1, 11], [3, 6], [10, 12], [15, 19]]); 
// [[1,12], [15, 19]]
```
Code For a Number Pad in Swift
Tags: ios, mobile, swift
Published: 2021-03-02 00:18:29

---
title: Code For a Number Pad in Swift
published: true
description: Use a number pad and validate input in swift
tags: [ ios, mobile, swift ]
canonical_url: https://thomasstep.com/blog/code-for-a-number-pad-in-swift
---

[I have been developing an iOS application recently](https://thomasstep.dev/blog/i-built-and-published-an-iphone-app) and I needed to receive numeric input from the user. I added a `TextField` and changed the `keyboardType` to `numberPad`, but I also stumbled across someone who took it an extra step and added some validation. I wanted to share what that looked like and also show my twist on it. The simple `TextField` with numeric input looks like this.
```swift
TextField("Demo text field", text: $myInput)
  .multilineTextAlignment(.center)
  .textFieldStyle(RoundedBorderTextFieldStyle())
  .keyboardType(.numberPad)
```

However, if the user has a Bluetooth keyboard synced with their device or if they are on an iPad (iPads do not support `numberPad`) then it is possible for a user to input other characters as well. To combat bad characters being passed in, we can add some validation logic like this.
```swift
import Combine

...

TextField("Demo text field", text: $myInput)
  .multilineTextAlignment(.center)
  .textFieldStyle(RoundedBorderTextFieldStyle())
  .keyboardType(.numberPad)
  .onReceive(Just(myInput)) { newValue in
    let filtered = newValue.filter {
      "0123456789".contains($0)
    }

    if filtered != newValue {
        self.desiredPomodoroRounds = filtered
    }
}
```

It is worth noting that I needed to import `Combine` for `Just` to work. The `onReceive` function allows us to validate the input text as it comes in. What this snippet does is check that only numbers are input, and if another character is found, that character is dropped. I took this a step further still. I was moving from `Slider` to `TextField` so I wanted to put bounds on the numbers that could be input. My solution was to check for those bounds inside of `onReceive` and force the value back inside of my bounds. Since I am expecting a number but want to make input easy, I felt that this was a decent compromise.
```swift
import Combine

...

TextField("Demo text field", text: $myInput)
  .multilineTextAlignment(.center)
  .textFieldStyle(RoundedBorderTextFieldStyle())
  .keyboardType(.numberPad)
  .onReceive(Just(myInput)) { newValue in
    let filtered = newValue.filter {
      "0123456789".contains($0)
    }

    // Arbitrary default value within bounds
    let numberValue = Int(filtered) ?? 4

    // Check for lower bound
    if numberValue < 1 {
        self.myInput = "1"
    }

    // Check for upper bound
    if numberValue > 60 {
        self.myInput = "20"
    }

    if filtered != newValue {
        self.myInput = filtered
    }
How I learned TDD (the hard way)
Tags: testing, tdd, productivity, programming
Published: 2021-03-02 12:12:13

---
title: How I learned TDD (the hard way)
published: true
date: 2021-03-02 00:00:00 UTC
tags: testing, tdd, productivity, programming
canonical_url: https://jhall.io/archive/2021/03/02/how-i-learned-tdd-the-hard-way/
---

The first time I remember seeing TDD demonstrated was in 2009 at the PgWest conference in Seattle. The talk was demonstrating the [pgTAP](https://pgtap.org/) framework for testing Postgres stored procedures.

I thought it looked interesting, so I rushed home to try it out. I wrote a few tests. I did a little TDD. And I hated it.

The tests I ended up with were brittle. The code I ended up with was hard to use. And most important, it took about 10x longer to write code this way. I quickly abandoned the technique, assuming it must just be for certain people, or certain situations, but it wasn’t for me!

A few years later, I read Michael Feather’s book [_Working Effectively with Legacy Code_](https://amzn.to/3ksMML3), in which he says:

> _legacy code_ is simply code without tests.

The rest of the book describes how to get untested code under test. This is a surprisingly difficult challenge in some cases. But after reading that book, I began to gradually write more and more tests whenever I created code—but still writing my tests after my code.

Over time (years, probably), I became better at writing tests. And critically, **I began to see ways to structure my code, so that testing would become easier.**

Once I started thinking in this new way, the switch to full-fledged TDD was much more natural.

All in all, it took me about 5 years, maybe longer, to go from TDD ignorant, to a TDD “hater”, to a TDD lover and advocate. I hope it doesn’t take everyone quite so long. ¯\\_(ツ)\_/¯
How to check if the user came from a specific link or website in JavaScript?
Tags: javascript
Published: 2021-03-02 00:00:00

---
  title: How to check if the user came from a specific link or website in JavaScript?
  published: true
  tags: JavaScript
  date: Tue Mar 02 2021 05:30:00 GMT+0530 (India Standard Time)
  canonical_url: https://melvingeorge.me/blog/how-to-check-if-the-user-came-from-a-specifc-link-or-website-javascript
  cover_image: https://melvingeorge.me/_next/static/images/main-4c76a0eedcb631211dc58eb962e20638.jpg
  ---
  [Originally posted here!](https://melvingeorge.me/blog/how-to-check-if-the-user-came-from-a-specifc-link-or-website-javascript)
  
To check if the user came from a specific website or by clicking a link to your website, you can use the `referrer` property in the global `document` object.

```js
// Check the link of website user came from
const linkOfTheWebsiteUserCame = document.referrer;
```

- The property will return a string with the link if the user came from clicking on a link to your website and an empty string if the user came directly to your website by writing the URL on the browser URL area.
- This is useful if you want to give some conditional messages to your users who came from clicking on a special link from a website.

To check out this cool feature go to this [JSBin](https://jsbin.com/takafusete/2/edit) link, then you can see the link of this blog you are reading shown there. Also if you refresh the page, it will show an empty string.

### Feel free to share if you found this useful 😃.

---
What is your best bet for creating presentations with CSS/web techs?
Tags: webdev, discuss, powerpoint, productivity
Published: 2021-03-01 23:52:17

It should be

- Printable (to PDF)

It would be helpful, to be rather interactive, than to be beautiful. Function is more important than beauty.

I am trying **Reveal.js** in [Markdown Preview Enhanced for VSCode](https://github.com/shd101wyy/vscode-markdown-preview-enhanced) (with `<!-- slide -->`); and, as always, trying to [override CSS in Reveal.js](https://github.com/hakimel/reveal.js/issues/1099) is frustrating, and even more [difficult to debug for Print](https://github.com/shd101wyy/vscode-markdown-preview-enhanced/issues/465).

- Using scale by default in this library is deadly for both `vh` and `vw`; so I cannot use them

I know there are [many other libraries, as seen here](https://github.com/astefanutti/decktape); but which are good?

Bespoke.js •  deck.js •  DZSlides •  Flowtime.js •  impress.js •  Inspire.js •  NueDeck •  remark •  reveal.js •  RISE •  Shower •  Slidy •  WebSlides
Learning with Gratitude
Published: 2021-03-01 23:46:50

Today, I met with an engineer to dive deeper into the wisdom behind computer science that got me thinking. He said:

“The best way to learn something is to think of what it would be like to live without what it is you’re trying to learn… it is when you feel the pain of not having what it is you’re trying to learn that helps you learn. The pain makes the learning personal.”

I found his statement very interesting. I felt what he was saying was a trick to retain a subject is to appreciate it.  The interesting part was that I have heard something similar from a doctor that I follow.  The doctor said that whatever we appreciate grows and expands.  For example: if I appreciate myself, a loved one, money, knowledge, health, etc. they will grow and expand in my life.

What do you think are the key components to learning? I find this fascinating.

*Note: the appreciation of spending money is different from the appreciation of having money.

 #learning #gratitude #philosophy #engineering
118. Pascal's Triangle
(javascript solution)
Tags: javascript, algorithms
Published: 2021-03-01 23:36:46

###Description:

Given an integer numRows, return the first numRows of Pascal's triangle.

###Solution:
Time Complexity : O(n)
Space Complexity: O(n)

```javascript
// Dynamic programming approach (tabulation)
// Use values in the previous row of the table to calculate the values of the next row
var generate = function(numRows) {
    const table = [];
    for (let i = 0; i < numRows; i++) {
        table[i] = [];
        table[i][0] = 1;
        for (let j = 1; j < i; j++) {
            table[i][j] = table[i-1][j-1] + table[i-1][j]
        }
        table[i][i] = 1;
    }
    return table;
}
```
DDL
Tags: mysql, database
Published: 2021-03-01 23:30:02

## Pengertian DDL

Hari ini saya akan menjelaskan apa itu DDL ( Data Definition Language ), DDL adalah bahasa / sintaks yang digunakan untuk mendefinisikan objek database / basis data seperti table, index, dan pengguna 
[Pengertian DDL](https://en.wikipedia.org/wiki/Data_definition_language)

## Fungsi Utama DDL

- Membuat struktur data
- Mengubah, Menambah, dan Menghapus struktur data

## Perintah DDL

- CREATE
- ALTER
- DROP
- RENAME
- MODIFY

### CREATE

Perintah CREATE ini umunya digunakan untuk membuat table, contohnya:

```SQL
CREATE TABLE products(
  id INT UNSIGNED NOT NULL AUTO_INCREMENT,
  name VARCHAR(100) NOT NULL,
  price INT UNSIGNED NOT NULL DEFAULT 0,
  category enum('makanan', 'minuman', 'lain - lain') NOT NULL DEFAULT null
);
```

### ALTER

Perintah ALTER ini digunakan untuk melakukan modifikasi terhadap struktur table, contohnya:

- ADD COLUMN
Cara penggunaan perintah ini adalah dengan dikombinasikan dengan perintah ALTER, Perintah ini digunakan untuk menambahkan kolom baru pada table yang diinginkan.

```SQL
ALTER TABLE products ADD COLUMN description TEXT;
```

- MODIFY 
Cara penggunaan perintah ini adalah dengan dikombinasikan dengan perintah ALTER, Perintah ini digunakan untuk melakukan modifikasi pad kolom yang diinginkan

```SQL
ALTER TABLE products MODIFY description VARCHAR(100) NOT NULL;
```

- DROP COLUMN
Cara penggunaan perintah ini adalah dengan dikombinasikan dengan perintah ALTER, Perintah ini digunakan untuk melakukan DROP / Penghapusan kolom pada table yang diinginkan

```SQL
ALTER TABLE products DROP COLUMN description;
```

- RENAME
Cara penggunaan perintah ini adalah dengan dikombinasikan dengan perintah ALTER,Perintah ini digunakan untuk merubah nama table yang diinginkan

```SQL
ALTER TABLE products RENAME TO produk;
```
Day 319 : Time
Tags: hiphop, code, coding, lifelongdev
Published: 2021-03-01 22:48:18

_liner notes_:
- Saturday : Did some coding and did the radio show. Had a good time doing both. The recording of this week's show is at https://kNOwBETTERHIPHOP.com

![Radio show episode image of John Morgan wearing a large brown cowboy type hat and seat suit with meat print with the right leg rolled up holding a cup and Arby's bag in Maui, Hawaii with the words Feb 27th 2021 Parliament Funkatarian](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fxdiytidlq3apkgb1xu3.jpg)

- Sunday : Pretty productive day. Finished up post radio show promo work. Did my laundry. Filled up some water tanks in my van. Did a bunch of coding. Caught up on episodes of "Attack on Titan" (so good!). Also watched the new "The Walking Dead" episode. Went to bed exhausted.

- Professional : Went on the weekly live stream. Had some new viewers so that was cool. Had a meeting with my manager. Then spent the rest of the day making Web Components. I've got like one more to do and I'll have replaced the UI components of this application with Web Components. Wasn't that bad at all, pleasantly surprised with how it's coming together.

- Personal : Ordered some things online yesterday that will hopefully delivered to my folks today. I want to head out and check out some new spots tomorrow.

![View from atop a mountain covered in pine trees in Cape Perpetua, OR, USA looking into a valley that is covered by clouds at sunset](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gfi8uh76xkd08bbk3ua3.jpg)

My laptop I've been using for the radio show has been acting up. I have to have it pulled in for it to boot up even though the battery is full. It's always been weird with power. Definitely won't be buying this brand again. I've been looking at some other replacement laptops. Maybe during the summer I'll pick something up. Going to work on my side project some more. Really want to get the upload feature finally working properly. Probably going to save the drag and drop ability for later since I can't get it working consistently on my Chromebook. Think that's about it.

Have a great night!

peace piece
Dwane / conshus
https://dwane.io / https://HIPHOPandCODE.com
{% youtube 6K6URq02vaY %}
575. Distribute Candies
(javascript solution)
Tags: algorithms, javascript
Published: 2021-03-01 22:39:06

###Description:

Alice has n candies, where the ith candy is of type candyType[i]. Alice noticed that she started to gain weight, so she visited a doctor.

The doctor advised Alice to only eat n / 2 of the candies she has (n is always even). Alice likes her candies very much, and she wants to eat the maximum number of different types of candies while still following the doctor's advice.

Given the integer array candyType of length n, return the maximum number of different types of candies she can eat if she only eats n / 2 of them.


###Solution:
Time Complexity : O(n)
Space Complexity: O(n)

```javascript
// Add candy types to a set to get a list of only unique values
// Return the minimum between the size of the set and the maximum numbers of candies allowed to eat
var distributeCandies = function(candyType) {
    const set = new Set();
    for(const type of candyType) {
        set.add(type)
    }
    return Math.min(set.size, candyType.length / 2)
};
```
The amazing python regex-rename package
Tags: python, tools
Published: 2021-03-01 22:36:43

---
title: The amazing python regex-rename package
published: true
description: An incredible python library to help you renaming files
tags: python, tools
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iddi8x3dacd0pdao4usv.png
---

# Source:
The idea of this post comes from [https://serverfault.com/questions/5685/](this question) on serverfault.com, **Renaming files in Linux with a regex**

Let's say you have these files:

    "System-Log-01-01-2009-NODATA.txt"
    "Something-Log-01-01-2009-NODATA.txt"

An you want the to become:

    "system.20090101.log"
    "something.20090101.log"

I have been using perl-rename a lot, (it is on the util-linux) package or you can run:

    cpan
    cpan1> install File::Rename

    sudo ln -s /usr/local/bin/rename /usr/bin/rename.pl

But this time I stumbled upon [regex-rename](https://pypi.org/project/regex-rename/), and I felt the obligation to share this tool with all of you guys. 

Let's first install it:

    pip3 install --user regex-rename

By default, it does not rename files, just shows you if your regex is matching any file:

    regex-rename '(\w+)-(\w+)-(\d+)-(\d+)-(\d+)-NODATA(\.txt)'

You will see a little report of what has been matched:

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

Let's see how the rename could be:

    regex-rename '(\w+)-(\w+)-(\d+)-(\d+)-(\d+)-NODATA(\.txt)' '\1.\5\4\3\6'

The actual renaming:

    regex-rename '(\w+)-(\w+)-(\d+)-(\d+)-(\d+)-NODATA(\.txt)' '\1.\5\4\3\6' --rename

## Convert to lowercase or uppercase and adding leading zeros

Let's create a bunch of files for test

    touch FILE-{1..10}.txt

Now run this command:

    regex-rename '(\w+-)(\d+)(\.txt)' '\L\1\2\3' --pad-to=2 --rename

The `\L` before group 1 says **regex-rename** to convert the group to lowercase and the option `--pad-to=2` adds leading zeros to the file names.
What is State in programming?
Tags: beginners, codenewbie, learning
Published: 2021-03-01 22:36:03

---
title: What is State in programming?
published: true
description: This is one of those terms I’ve heard/read often in my adventures through software development and found a bit confusing at first.
tags: #beginners, #codenewbie, #learning
canonical_url: https://danpgomez.com/blog/2021/3/1/what-is-state-in-programming
// cover_image: ![text](url)
---
I often hear the term "state" being used when describing objects in a program, or even programs entirely, and decided to do a bit of research to get some clarity. I found [a few helpful][1] [articles][2] and videos (see bottom of post) which brought me to the following conclusion: The concept of State in programming refers to the value of all variables that determine the status or condition of the program or object in question. With this in mind I came up with the following analogy of a coffee maker (somehow most things in my life revolve around coffee ☕️). So in the image below, the coffee maker's state is *"power = on"* and *"status = brewing".* Also important to note that state can change based on both internal or external events, such as the user turning off the coffee maker, or it finishing the brewing process.

![A coffee maker’s state can be described as “brewing” and/or “on”](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ey20zsnpl81k5kxzpcb9.jpg)

[2]: https://www.quora.com/What-is-a-state-in-computer-science
[1]: https://en.wikipedia.org/wiki/State_(computer_science)#:~:text=The%20contents%20of%20these%20memory,is%20called%20the%20program's%20state.&text=Imperative%20programming%20is%20a%20programming,which%20change%20the%20program%20state.(computer_science)#:~:text=The%20contents%20of%20these%20memory,is%20called%20the%20program's%20state.&text=Imperative%20programming%20is%20a%20programming,which%20change%20the%20program%20state.

{% youtube jRtdbSKWFqk %}
A bunch of inspirations for programmers
Tags: watercooler, discuss, webdev, random
Published: 2021-03-01 22:28:33

# About this post

I've seen a lot of people ask "What projects should I make next?".  A lot of people are in need of inspiration and I want to help them to find it fast.

The most popular post on DEV of all time shows 8 frontend projects that someone can build.  That shows how much people need inspiration on what to build.

I want you to share any ideas of great project that programmers should build.  I want this post to be a reference to others out of inspiration where they can come back and just build the first project that comes to them.

If you have an idea (or some ideas) of a great project that a developer should make, post it in the comments and I will the project you suggested and your name in this post.

# Projects

## Frontend Projects & Ideas
 - Personal Portfolio
 - Chatroom UI/UX
 - Create a new website skin/theme for https://userstyles.org/
 - Landing Page UI
 - Survey Form

**Tools**: HTML/CSS/JS, React, Redux, Jquery, Bootstrap, Angular, Tailwind CSS, FontAwesome, Google Fonts, VueJS, etc.

## Fullstack Projects & Ideas
 - Image Uploader
 - Unsplash Clone
 - Coding Website (Codepen clone)
 - Website simillar to Dev.to
 - Project sharing site
 - Social Media Site
 - facebook/twitter/reddit clone
 - e-commerce site
 - Voting/Polling app
 - Authentication App
 - Hackathon Hosting Site
 - Slack/Discord clone
 - Domain Name Registrar
 - Code teaching site (like codecademy or freecodecamp)
 - Email site (like Gmail, Yahoo, Protonmail, etc)

**Tools**: See frontend tools above, SQL, NodeJS, Flask, Django, Go, etc.

## Game development Ideas
 - Tower Defense
 - Platformer
 - First Person Shooter
 - RPG
 - Sniper game

**Tools**: HTML/CSS/JS, P5.js, PhaserJS, Zim, WEBGL, ThreeJS, BabylonJS, UnityWebGL, etc.

## Algorithms
 - Search autocomplete engine
 - Palindrome Checker
 - Cipher / Secret Code Encryptor
 - Morse Code translator
 - Weight Converter
 - Calculator
 - Currency Converter
 - Text Adventure / RPG
 - Markdown Previewer
 - Javascript Editor
 - HTML/CSS/JS Editor & output

**Tools**: Javascript, Python, C/C#/C++, etc.

## Data Science & Machine Learning
 - Image Classifier
 - Trend Tracking Device
 - Weather App

**Tools**: Python, SQL, Tableu, R, etc.

## Misc
 - New programming language

**Tools**: any

# Contributors / Credits
If you come up with an idea and I add it to this post, you will be listed here
 - @MiguelMJ

Cover Image from [Unsplash](https://unsplash.com)
How the heck do you use Github?
Published: 2021-03-01 22:16:06

Hello everyone,,
So I've been using freecodecamp and talking to developer friends and they say github is of paramount importance to use if you want to land a developer job someday https://trackeasy.fun/usps/ . I have been through the hello world tutorial and making repositories, but when I see projects to work on, how do I work on them? Where do I code/access the existing code of https://showbox.tools/? This is probably a serious noob question so I appreciate the response. This stuff certainly isn't intuitive for me.
100 Bytes Of Wisdom: Day 16
Tags: career, journey, advice
Published: 2021-03-01 22:12:10

---
title: 100 Bytes Of Wisdom: Day 16
published: true
description: Bytes of Wisdom is a new project by Sam Jarman that brings together snippets of advice for software engineers
tags: career, journey, advice
//cover_image: https://direct_url_to_image.jpg
---

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9iegguzzk0og9y0ws3k9.png)


When you're in the thick of it - be it a coding problem or a life problem, you often are too concerned with the challenge to acknowledge the steps you are taking and the growth that is happening.

This quote from DC's Wonder Woman sums this up nicely. Sometimes it takes going through a challenge and having some time pass to even see what you achieved. More often than not, you usually acheive more than just what the challenge was about. 

Embrace challenges, they're the only way to grow and learn.

Heads up: As with any terse bit of advice, there will be exceptions of course, and subtleties and nuance that can't possibly be captured in a Byte of Wisdom. This has been what I've experienced, I'd love to hear yours in the comments too!

You can catch up with all the other bytes at http://bytesofwisdom.com/
21 Lessons from Building Clones On youtube
Tags: beginners, webdev, codenewbie, career
Published: 2021-03-01 21:42:12

Learning a new skill online is fun and free, but how do you make that learning permanent? [Here are the lessons](https://medium.com/@shashankkatte/21-essential-lessons-from-building-clones-on-youtube-e47202e9c437?sk=d7229aff0b0ab59121c205d61e0cbdae) I have learned taking the journey myself.

I am eager to know yours :)