teleren/devto huggingface dataset:
Live Event: How one Senior Engineer got a job at Meta
Tags: eventsinyourcity, programming, career, techtalks
Published: 2022-06-07 16:45:54

Join us for a live event this Friday 6/10 with another Hackpack alumni who got a job as a senior engineer at Meta! They will be speaking about their programming interview prep tips and how they passed the final technical interview.

If you are studying for a software engineering job at Meta, definitely check this out! It will be a great chance to learn, ask questions, and interact with other engineers who are also in the midst of studying.

Add the event to the calendar here - **[discord.com/invite/NKFGEzav5M?event=9817246..](https://discord.com/invite/NKFGEzav5M?event=981724643624882186)**

Don't miss any of our future events with FAANG engineers by adding our events to your calendar - **[discord.gg/VQkMr234zk?event=970275330294153..](https://discord.gg/VQkMr234zk?event=970275330294153257)**

### **Join the Community**

Looking for a study partner or community of people to hold you accountable? Hackpack is a hyperactive community of engineers all studying for programming interviews.

Apply Here: **[hackpack.io](https://www.hackpack.io/)**

I tweet interview tips **[here](https://twitter.com/DannyHabibs)**

**[Big Tech Interview Newsletter](https://fangprep.substack.com/)**
Day 2 : What is pure function in JS ?
Tags: javascript, webdev, 100daysofproductivity, tutorial
Published: 2022-06-07 16:45:30

A pure function is a function which
- Given the same input, always returns the same output.
- Produces no side effects.
- Pure functions must not mutate external state.

A function is only pure if, given the same input, it will always produce the same output.

Example : 

```
PURE FUNCTION
function isValid(age){
  return age >= 18;
}
```
This function will always return true or false based on age.

EXAMPLE OF UNPURE FUNCTION

- Pure functions must not mutate external state.

```
items = [];
const addItems = (item) => {
  items.push({
    item
  }); 
};

```
addItems() is not a pure function because it mutates the external state by pushing values to that items array.
Web Dev Boot Camps are teaching the stack backwards
Tags: webdev, bootcamp, curriculum
Published: 2022-06-07 16:29:14

I've taught multiple web dev boot camp courses. All of them are passionate about teaching the web dev stack starting from the front end and working their way to the back end. The consistent reasoning I'm told is because instructors want students to be productive quicker. It makes sense from an engagement standpoint at the beginning of a class. 

We introduce students to the web by having them build more and more complex UIs. 

The flow I've seen at most boot camps is: 
`HTML>CSS>JS DOM>React>NodeJS>Devops`

This feels like a big context change. Devs are able to build pretty great looking websites with just HTML/CSS. I find many students who join web dev boot camps aren't clear on programming fundamentals. So, turning code into UI is an extra large leap. However, I believe it makes more sense to begin with data and then add UI to it. I believe problems that scale in complexity for web devs are not HTML/CSS but are JS problems. I'm not trying to discount HTML/CSS but I don't believe the concepts behind scaleable HTML/CSS are complex for Juniors. I've never considered failing a student because of their lack of HTML/CSS knowledge. I have failed students because they couldn't learn how to write loops and conditionals. 

However, I propose:
`JS DOM>HTML>CSS>NodeJS>React>Devops`

The reason for my proposal is that it is the most iterative of approaches for web devs. This path comes at the cost of up front visual productivity. You don't really understand how to build web-ui's for quite a bit. But, I'll say that with this approach the switch from UI programming to backend programming is much more seamless as it puts learning at the center of the process as opposed to productivity. That shift from productivity to learning code is huge and maintaining a path of iterative improvement in my opinion is best.

I've outlined my thoughts on why Frontend engineering is an extremely complex field and possibly will elucidate some more of my thoughts on why I think many frontend curriculums treat backend concerns as second class.

https://dev.to/schusterbraun/frontend-is-confusing-4o2d
[JS Quiz] Guess the Order of Execution (chances of getting this right are slim)
Tags: javascript, programming, discuss, watercooler
Published: 2022-06-07 16:27:08

---
title: [JS Quiz] Guess the Order of Execution (chances of getting this right are slim)
published: true
description: Order of execution in JavaScript is tricky. Or, as these two examples show, can be plain evil. Lvals, declarators, assignments and destructuring patterns...
tags: javascript, programming, discuss, watercooler
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rs4azml1wqyxx7cyypto.png
# Use a ratio of 100:42 for best results.
---

```js
(() => {
  function l() { console.log('l()'); return 'l'; }
  function r() { console.log('r()'); return { l: 1 }; }
  function x() { console.log('x()'); return 'x'; }
  function o() { console.log('o()'); return _o; }


  var _o = {};
  ({ [l()]: o()[x()] } = r());

  console.log('test1', _o.x);
})();

(() => {
  function r() { console.log('r()'); return 'r'; }
  function x() { console.log('x()'); return 'x'; }
  function o() { console.log('o()'); return _o2; }

  var _o2 = {};
  o()[x()] = r();

  console.log('test2', _o2.x);
})();
```

For `test1`, which one is it?

1. `r` → `l` → `o` → `x`
1. `l` → `o` → `x` → `r`
1. `r` → `o` → `x` → `l`


For `test2`... just run it yourself. The result being "surprising" might be an understatement.
Jackson JSON parsing top-level map into records
Tags: java, json, jackson, records
Published: 2022-06-07 16:25:47

Java 14 added [the `record` type](https://blogs.oracle.com/javamagazine/post/records-come-to-java) and [Jackson JSON works great with them](https://cowtowncoder.medium.com/jackson-2-12-most-wanted-5-5-a32c28c345b5).

I hit an edge case where I needed to parse a JSON structure where the top level was an object with arbitrary keys. 

I also didn't want to read into a `Map` but rather a record that mapped each keyed entry into a record each.

Here's a contrived example JSON I wanted to parse:
```json
{
  "Some Child's Name": {
    "age": 5
  },
  "Some Adult's Name": {
    "age": 21
  }
}
```

The `@JsonAnySetter` annotation (1) on a `Map` field got me most of the  way, but the final piece of the solution was to pre-instantiate the map at (2). 

Here are the final record declarations that can accommodate the JSON above:
```java
record People(
    @JsonAnySetter // (1)
    Map<String, Person> people
) {
    public People {
        people = new HashMap<>(); // (2)
    }
}

record Person(
    int age
) { }
```

For example, following use of an `ObjectMapper` ...
```java
final People people = objectMapper.readValue("""
    {
      "Some Child's Name": {
        "age": 5
      },
      "Some Adult's Name": {
        "age": 21
      }
    }""", People.class);
System.out.println(people);
```

outputs
```
People[people={Some Adult's Name=Person[age=21], Some Child's Name=Person[age=5]}]
```
Schedule GitHub Actions Using CRON Expressions
Tags: github, devops
Published: 2022-06-07 16:13:55

You can trigger GitHub Actions to run on a number of different events. The most common would be running when you push changes to your repository.  Also you may want to trigger an Action to run on pull requests. 

When building Actions you may want to run them on a defined schedule.  This tutorial shows you how to configure a GitHub Action on a given schedule using CRON expressions. 

## Can you schedule GitHub Actions?

Yes, yes you can.  You have the option to trigger a GitHub Actions on a schedule an example could be:
```yml
name: Test Build

on:  
  push:
  pull_request:
  schedule:
    - cron: '00 1 * * 1'  # At 01:00 on Mondays.

```

## What is CRON?

CRON is a command line utility that is used to schedule jobs.  You'll hear it referred to CRON jobs or CRON tasks.  

The CRON syntax can sometimes be confusing when first encountered.  There are five sections that can be configured within the CRON syntax.  You can specify day of week, month, day of the month, hour and minute. 

This isn't something you need to commit to memory but being able to read the syntax is useful.  Below is a great diagram to show you how the syntax is broken down. 

```yml
# ┌───────────── minute (0 - 59)
# │ ┌───────────── hour (0 - 23)
# │ │ ┌───────────── day of the month (1 - 31)
# │ │ │ ┌───────────── month (1 - 12)
# │ │ │ │ ┌───────────── day of the week (0 - 6)
# │ │ │ │ │                       
# │ │ │ │ │
# │ │ │ │ │
# * * * * * <command to execute>
```

I love to use the website [https://crontab.guru/](https://crontab.guru/).  You can put the syntax in to the website and it will decipher what that schedule would do, or equally you can use it to build the right syntax for the schedule you want to execute. 

## What is the GitHub Actions CRON syntax?

I want to show you an example of a GitHub Actions workflow including a CRON schedule. 

```yml
name: Trigger Action on a CRON Schedule

on:
  schedule:
    # Runs "At 11:00 on every day-of-week from Monday through Friday"
    - cron: '0 11 * * 1-5'
    
jobs:
  build:
    name: Trigger Code Checkout
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
```

The above GitHub Actions workflow will open trigger on a schedule.  The CRON job I have set will run at 11am on every day-of-week from Monday through Friday.

The workflow then will run the Code Checkout step on a [Ubuntu runner](https://www.techielass.com/github-runners/). 

It's a straight forward workflow, but it triggers using a CRON schedule rather than on a push to GitHub or on a pull request. 

Be sure to check out the other blogs I have written on [GitHub Action ](https://www.techielass.com/tag/github-actions/)uses and features. 

{% youtube kh7piyS2XeE %}
Merge Two Sorted Lists
Tags: leetcode, dsa, theabbie
Published: 2022-06-07 16:00:44

You are given the heads of two sorted linked lists `list1` and `list2`.

Merge the two lists in a one **sorted** list. The list should be made by splicing together the nodes of the first two lists.

Return _the head of the merged linked list_.

**Example 1:**

![](https://assets.leetcode.com/uploads/2020/10/03/merge_ex1.jpg)

**Input:** list1 = \[1,2,4\], list2 = \[1,3,4\]
**Output:** \[1,1,2,3,4,4\]

**Example 2:**

**Input:** list1 = \[\], list2 = \[\]
**Output:** \[\]

**Example 3:**

**Input:** list1 = \[\], list2 = \[0\]
**Output:** \[0\]

**Constraints:**

*   The number of nodes in both lists is in the range `[0, 50]`.
*   `-100 <= Node.val <= 100`
*   Both `list1` and `list2` are sorted in **non-decreasing** order.

**SOLUTION:**

    # Definition for singly-linked list.
    # class ListNode:
    #     def __init__(self, val=0, next=None):
    #         self.val = val
    #         self.next = next
    class Solution:
        def mergeTwoLists(self, l1, l2):
            if l1 and l2:
                a, b = l1, l2
                if b.val < a.val:
                    a, b = b, a
                a.next = self.mergeTwoLists(a.next, b)
                return a
            return l1 or l2
The gate is a major tool of the Luos eco-system
Tags: opensource, microservices, json, luos
Published: 2022-06-07 16:00:36

The gate is a major tool of the Luos eco-system. 

⏩ https://www.luos.io/docs/tools/gate

It allows you to translate any Luos architecture into a format more convenient for standard software ([JSON] mostly) and to transmit and receive this formed information in any type of communication such as serial interface, WiFi, Bluetooth, Lora, etc…
MongoDB and PostgreSQL database testing with Jest and Docker containers
Tags: jest, javascript, docker, productivity
Published: 2022-06-07 15:50:19

I've made an example [repository](https://github.com/ivandotv/jest-database-containers) that demonstrates how to test MongoDB and PostgreSQL databases with Docker containers
and Jest.

Currently, I have no time to write the full article but it is on my to-do list. In the meantime, you can check out the repository that has a readme file where everything is explained.

## How it works

When Jest is started, and before the tests are executed, we create two docker database containers (MongoDB and PostgreSQL) each test file (Jest Worker) gets a new database inside the container.
If the detected OS is Linux, we use the `tmpfs` file system inside the containers which increases the speed of execution since in that case all database data is held in memory.

### Test execution

- Before each test, the database is seeded.
- After each test, the database is cleared.
- When all tests in the file are done, the database is discarded.
- When Jest is done running all the tests, database containers are stopped and removed.

Jest **watch** mode is supported, in that case, everything works that same, but database containers will not be stopped and removed until you exit _watch_ mode.

### Running on Github Actions

Github actions file is included. Default Ubuntu Github Actions image comes with Docker preinstalled so no issues are running the tests in a continuous integration environment.

I use this setup in my projects, so this repository will be kept up to date.

https://github.com/ivandotv/jest-database-containers
Python Exercise 6: Remove Special character In String
Tags: beginners, python
Published: 2022-06-07 15:49:35

## Question
**Given**:

```
str1 = "/*Jon is @developer & musician"
```

**Expected Output**:
```
"Jon is developer musician"
```
## My attempt
- The hints tell me to use translate() and maketrans(), so I google and try to use it.
- The first attempt, is to make a table replace the special character with white space 
```python
str_1 = "/*Jon is @developer & musician"  
x = "/*@&"  
y = "    "  
my_table = str_1.maketrans(x,y)  
print(str_1.translate(my_table))
```
- with an output
```python
  Jon is  developer   musician
```
- seems good, but there is too many white space between it, not the same as the equal to the expected result

## Syntax of translate() and maketrans() method
The maketrans() method will return a mapping table for translate() method to use

### translate() method syntax
```python
str.translate(mapping table)
```

### maketrans() syntax

```python
string.maketrans(x, y, z)
```
- x is required, y and z is optional

- Only One parameter
```python
string.maketrans(dictionary)
```

- With Two parameters
```python
string.maketrans(same length string, same length string)
```

- Three parameters
```python
string.maketrans(same length string, same length string, another string)
```
- another string can be not equal strength

## Recommend solution
### Solution 1: Use translate() and maketrans() method
```python
import string

str_1 = "/*Jon is @developer & musician"
new_str = str_1.translate(str_1.maketrans('', '', string.punctuation))

print(new_str)
```
- This solution use the maketrans method, take the string.punctuation as the third parameter to remove all the special charter in the original string
- To use the punctuation method, you must import string module

### Solution 2: use re.sub() method
```python
import re  
  
str_1 = "/*Jon is @developer & musician"  

# replace special symbols with ''  
new_str = re.sub(r'[^\w\s]', '', str_1)  
print(new_str)
```
- First step is to import re module.
- second, construct a new string using re.sub method: replacing special character with empty string from str_1
```python
r'[^\w\s]' 
```
- The above expression means match any character that is not an word character nor white space
- --
- "\w" means matches Unicode word characters; this includes most characters that can be part of a word in any language, as well as numbers and the underscore
- "\s" Matches Unicode whitespace characters 
- the prefix r means raw string notation. The special character afterwards will not activate its special function, only treat as a normal character.
- `[]` Used to indicate a set of characters.
- if `^`  in the set `[]` and is the first character , it means all the characters that are _not_ in the set will be matched

## My reflection
So I learn maketrans() and translate() method as well as the regular expression. Using re module seems easier to code, but the regular expression syntax is not that straight forward to read.

## Credit
- exercise on [Pynative](https://pynative.com/python-string-exercise/)(Accessed at 2022 JUN 7)
- [Python doc](https://docs.python.org/3/library/re.html)
How do you have productive 1-1 with upper management?
Tags: webdev, career, discuss, help
Published: 2022-06-07 15:47:30

I have regular meetings with my immediate supervisor, which I always take the opportunity to get/give some feedback. However, I am not sure what to say with managers above my supervisor. 

I don't have regular interactions with them and they don't really get involved with the work I do. I am also just Software Engineer II, so not involved with high level projects. 

So I don't really know what to have a good discussion with them, but I really want to since I know it's a rare opportunity that the company structure have.

Thank you!
Two Furthest Houses With Different Colors
Tags: leetcode, dsa, theabbie
Published: 2022-06-07 15:30:38

There are `n` houses evenly lined up on the street, and each house is beautifully painted. You are given a **0-indexed** integer array `colors` of length `n`, where `colors[i]` represents the color of the `ith` house.

Return _the **maximum** distance between **two** houses with **different** colors_.

The distance between the `ith` and `jth` houses is `abs(i - j)`, where `abs(x)` is the **absolute value** of `x`.

**Example 1:**

![](https://assets.leetcode.com/uploads/2021/10/31/eg1.png)

**Input:** colors = \[**1**,1,1,**6**,1,1,1\]
**Output:** 3
**Explanation:** In the above image, color 1 is blue, and color 6 is red.
The furthest two houses with different colors are house 0 and house 3.
House 0 has color 1, and house 3 has color 6. The distance between them is abs(0 - 3) = 3.
Note that houses 3 and 6 can also produce the optimal answer.

**Example 2:**

![](https://assets.leetcode.com/uploads/2021/10/31/eg2.png)

**Input:** colors = \[**1**,8,3,8,**3**\]
**Output:** 4
**Explanation:** In the above image, color 1 is blue, color 8 is yellow, and color 3 is green.
The furthest two houses with different colors are house 0 and house 4.
House 0 has color 1, and house 4 has color 3. The distance between them is abs(0 - 4) = 4.

**Example 3:**

**Input:** colors = \[**0**,**1**\]
**Output:** 1
**Explanation:** The furthest two houses with different colors are house 0 and house 1.
House 0 has color 0, and house 1 has color 1. The distance between them is abs(0 - 1) = 1.

**Constraints:**

*   `n == colors.length`
*   `2 <= n <= 100`
*   `0 <= colors[i] <= 100`
*   Test data are generated such that **at least** two houses have different colors.

**SOLUTION:**

    class Solution:
        def maxDistance(self, colors: List[int]) -> int:
            indexes = {}
            for i, c in enumerate(colors):
                if c in indexes:
                    indexes[c] = (min(i, indexes[c][0]), max(i, indexes[c][1]))
                else:
                    indexes[c] = (i, i)
            mdiff = 1
            n = len(indexes)
            colors = list(indexes.keys())
            for i in range(n):
                for j in range(i + 1, n):
                    mdiff = max(mdiff, abs(indexes[colors[i]][1] - indexes[colors[j]][0]), abs(indexes[colors[j]][1] - indexes[colors[i]][0]))
            return mdiff
Top 7 Featured DEV Posts from the Past Week
Tags: top7
Published: 2022-06-07 15:27:26

---
title: Top 7 Featured DEV Posts from the Past Week
published: true
description: A round up of the most-read and most-loved contributions from the community this past week
tags: icymi 
cover_image: https://thepracticaldev.s3.amazonaws.com/i/sfwcvweirpf2qka2lg2b.png
---

_Every Tuesday we round up the previous week's top posts based on traffic, engagement, and a hint of editorial curation. The typical week starts on Monday and ends on Sunday, but don't worry, we take into account posts that are published later in the week._ 


## Mentoring a Junior

Passing on your knowledge has the potential to provide more value than actually writing code. Smart companies know this and reward it. In this post, @arielbk gives advice on mentoring.

{% embed https://dev.to/arielbk/how-to-mentor-a-junior-dev-21dd %}


## Intra-Site Chat!

This week @rajeshj3 announced an extension that will allow you to talk to people over the internet who are on the same website/webpage as you, assuming they've installed the app as well. How exciting!

{% embed https://dev.to/rajeshj3/talk-to-people-who-are-on-the-same-site-chrome-extension-5hh7 %}


## Exception Handling in Dart/Flutter

The worst thing you can do as a programmer is not to think about catching and tracking errors. Let's learn how to with @frezyx!

{% embed https://dev.to/frezyx/exception-handling-and-logging-in-dartflutter-talker-25o4 %}


## Customize your ZSH Prompt

@cassidoo uses a .zshrc file to customize the terminal. Here’s how to make that little prompt useful without being overwhelming or distracting!

{% embed https://dev.to/cassidoo/customizing-my-zsh-prompt-3417 %}


## From Methods to Hooks

In this post, @swastikyadav talks about the paradigm shift from lifecycle methods to state synchronization and hooks in ReactJs. A video version is also available, if you prefer!

{% embed https://dev.to/swastikyadav/stop-thinking-about-react-lifecycle-methods-248 %}


## Disillusioned with a Career in Tech

@martinzokov thoughtfully digs into their feelings about working as a software engineer and the dread that comes from working "this endless while loop of the 9 to 6 grind every day" when they'd much rather be pursuing something creative and more rewarding.

{% embed https://dev.to/martinzokov/becoming-disillusioned-with-career-in-tech-as-a-software-engineer-4pe6 %}


## ADHD Brains

If you have ADHD, chances are that it inhibits your ability to manage your responsibilities at home and at work. This week, @abbeyperini shared experiences with ADHD in a multi-part series covering multiple challenges when it comes to coding with ADHD.

{% embed https://dev.to/abbeyperini/coding-and-adhd-adhd-brains-im1 %}


_That's it for our weekly Top 7 for this Tuesday! Keep an eye on dev.to this week for daily content and discussions...and be sure to keep an eye on this series in the future. You might just be in it!_
OpenCV – 10 lines to remove the background in an image 🖼️
Tags: englishpost, codesample, opencv
Published: 2022-06-07 20:27:29

---
title: OpenCV – 10 lines to remove the background in an image 🖼️
published: true
date: 2022-06-07 15:25:49 UTC
tags: EnglishPost,CodeSample,EnglishPost,OpenCV
canonical_url: 
---

Hi !

Super quick post today, with a very simple scenario:

#### Load and image and remove the background.

To do this, I’ll use OpenCV and cvzone. Here we can see a screenshot of my office, and the removed background sample. As usual, the threshold is the important one to manage the quality.

![Removed Background](https://brunocapuano.files.wordpress.com/2022/06/removed-background.jpg?w=1024)

And the sample code:

{% gist https://gist.github.com/elbruno/75ba9e45db52d702e7b94426d466619d %}

In next samples, I’ll show to work with this and the camera, and even replace the bacground 😀.

Happy coding!

Greetings

El Bruno

More posts in my blog [ElBruno.com](https://www.elbruno.com).

* * *