teleren/devto huggingface dataset:
Memomization? how and the why in Javascript.
Tags: webdev, javascript, beginners, react
Published: 2022-06-09 08:14:55

Memoization generally means to remember and in the world of programming a memoizing function is to make the function remeber the output value for a particular input, so if in future if the function is asked to run on the same input it delivers the results very fast as it already have the output for that input.

Let's take a look at the following diagram to understand better


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u1hoc05nfvoe1fgu9x2s.png)

in the diagram, we can see that if the function **fib** is memoizing(caching) the value for the calculations as the fibbonaci calculation are intense for higher numbers, we can see it only calculate once for that input and no matter how many time we run the function for the same input the output is given at an instant.

Heres the code for the above function.
```javascript
const fib = (num) => {
    if(num < 2) return num
    return fib(num -1) + fib(num-2)
}
```

This is the memoize decorator function we will be using

```javascript
export const memoize = (fn) => {
    const cache = {};
    return (...args) => {
        if (JSON.stringify(args) in cache) {
            return cache[JSON.stringify(args)];
        }
        const result = fn(...args);
        cache[JSON.stringify(args)] = result;
        return result;
    }
}
```

Running the function **fib** alone will occure in firing intensive calculations every single time. but if we wrap it in the memoize decorator fn it will calculate only one time and subsiquent runs will output results from the cache resulting in perfomant code and faster app.

```javascript
const memoFib = memoize(fib)
```
That is how you call and memoize the fib function this can be used with any other function aswell.

We generally use memoization on pure functions and intensive calculations, it can also be used in API calls but it is not recommended.

tldr; memoization is basically caching the results so that they can retrieved later and faster without making new calculations, with memoization we trade speed with meemory.
Interview in Coinbase — Part 1
Tags: beginners, career, blockchain, web3
Published: 2022-06-09 08:08:38

My experience of the technical interview in Coinbase.

**Under the Hood**
The day before yesterday at the time of writing this story, I gave an interview in coinbase. In today’s story, I will cover the questions and experiences for the same. Coinbase is hiring for multiple across 100 countries remotely. They offer a fixed compensation package for every role and don’t really believe in negotiating. I was reached by one of their HR last year but I was not looking for any such opportunity so I refused to go for it.

But since now I am looking for a new remote opportunity in web3/web2 I thought of giving it a try in coinbase.

**Interview Process**
For your kind of information, I have cleared the first round and from tomorrow onwards I will commence the next 3 remaining rounds. Coinbase has an average of 4/5 rounds of interviews.

- Technical round I —
- Pair programming round 1
- Pair programming round II
- System Design
- Engineering Manager interview
These are the typical rounds of interviews for coinbase. But depending on the roles they might change a few rounds in between.

**First-round experience**
Well, my first round was quite easy and luckily I’ve answered all the questions correctly. I’ve been given a UI to develop followed by multiple questions about the UI and code. I am adding the code sandbox of what I’ve been asked to develop. And the following questions asked revolved around this UI only.

[Question asked in first interview](https://codesandbox.io/s/eager-meadow-1mjst2?from-embed)

**Questions asked**
The first step is to develop the using any framework or language.
Style the UI exactly like the expected one including CSS
How I can make reusable components in the codebase
How can I make the code production-based considering the performance and so?
I’ve summarised the questions in 4 big questions but there was a total of 12 to 15 questions I’ve been asked. Since it was the first round so questions asked were not too tough.

**Next rounds**
Tomorrow I have the next remaining rounds, I am expecting more tough questions in the same, questions on debugging existing react code base, optimising the code base for production-based. It's a pair programming round so I won’t feel that questions on architecture and state management will be asked it will be more often on solving the issue found in other codebases.

They might want to test debugging skills, variable naming skills, better coding practices and so on and I will anyway share the experience and the questions with you.

**Conclusion**
For the next rounds, I will share the experience and information via the new story. For that stay tuned and don’t forget to follow and subscribe. Until, next time, have a good day, people.

Our website [iHateReading](www.ihatereading.in) || [Youtube](https://www.youtube.com/channel/UC6I-Tz6QwYbJpoIK7l0NtXA) || [Twitter](https://twitter.com/treyvijay)
Valid Triangle Number
Tags: leetcode, dsa, theabbie
Published: 2022-06-09 08:00:46

Given an integer array `nums`, return _the number of triplets chosen from the array that can make triangles if we take them as side lengths of a triangle_.

**Example 1:**

**Input:** nums = \[2,2,3,4\]
**Output:** 3
**Explanation:** Valid combinations are: 
2,3,4 (using the first 2)
2,3,4 (using the second 2)
2,2,3

**Example 2:**

**Input:** nums = \[4,2,3,4\]
**Output:** 4

**Constraints:**

*   `1 <= nums.length <= 1000`
*   `0 <= nums[i] <= 1000`

**SOLUTION:**

    class Solution:
        def triangleNumber(self, nums: List[int]) -> int:
            nums.sort()
            n = len(nums)
            ctr = 0
            i = 2
            while i < n:
                a = 0
                b = i - 1
                while a < b:
                    if nums[a] + nums[b] > nums[i]:
                        ctr += (b - a)
                        b -= 1
                    else:
                        a += 1
                i += 1
            return ctr
Enjoy Programming-Themed Humor? Here's today's daily developer joke!
Tags: jokes, dailydeveloperjokes
Published: 2022-06-09 08:00:20

---
title: "Enjoy Programming-Themed Humor? Here's today's daily developer joke!"
description: "Check out today's daily developer joke! (a project by Fred Adams at xtrp.io)"
series: "Daily Developer Jokes"
published: true
tags: #jokes, #dailydeveloperjokes
---

Hi there! Here's today's Daily Developer Joke. We hope you enjoy it; it's a good one.

![Joke Image](https://private.xtrp.io/projects/DailyDeveloperJokes/public_image_server/images/5e1258884db70.png)

---

For more jokes, and to submit your own joke to get featured, check out the [Daily Developer Jokes Website](https://dailydeveloperjokes.github.io/). We're also open sourced, so feel free to view [our GitHub Profile](https://github.com/dailydeveloperjokes).

### Leave this post a ❤️ if you liked today's joke, and stay tuned for tomorrow's joke too!

_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 do you call a busy waiter?

___A:___ A server.
 -->
A more programmer-friendly markdown notebook - MiaoYan
Published: 2022-06-09 07:58:10

<p align="center">
    <img src=https://qpluspicture.oss-cn-beijing.aliyuncs.com/PZTEyo/27.png  />
    <h1 align="center">MiaoYan</h1>
    <div align="center">Lightweight Markdown app to help you write great sentences.</div>
</p>

> <https://miaoyan.vercel.app/>

<kbd>
![gif](https://gw.alipayobjects.com/zos/k/yb/en.gif)
</kbd>
## Features

- 🪂 **Fantastic**: Local use, security, syntax highlighting, dark mode, source file saving、international.
- 🐶 **Beauty**: Minimalist design style, folder + file list + editor 3 column mode.
- 🏌🏽‍♂️ **Fast**: Using Swift5 native development, the performance experience is much better compared to the Web.
- 🩴 **Simple**: Very light, pure editor input experience, many shortcut keys to help you fast.

## Why do this

- I have tried many note-taking applications before, such as WizNote, Ulysses (no preview), Quiver (not updated for years), MWeb (complicated functions), Bear (Markdown images and other rich formats are not supported), for various reasons, I did not find a good Markdown application, so I had the idea of doing MiaoYan.
- My job is front-end development, but also can develop iOS, like to toss, Develop MiaoYan as a fun leisure.

![](https://qpluspicture.oss-cn-beijing.aliyuncs.com/wvTemI/26.png)
Terranetes: open source tool to self-serve cloud resources
Tags: terraform, kubernetes, cloud, helm
Published: 2022-06-09 07:52:46

[Terranetes](https://bit.ly/3Q9sshg) uses Helm packages to enable application developers to self-serve cloud resources with minimal user input.

This is a solution and pattern that simplifies developer self-service and application development in the cloud. It combines reputable and widely-adopted technologies such as HashiCorp Terraform, the Appvia Terraform Controller and Helm to provide consumable packages (i.e., Helm charts) to application developers. Access the docs at [Appvia Terranetes](https://bit.ly/3myFl6M) or the [Github repo](https://bit.ly/3Q9sshg)
Sum 2 numbers, wrong answers only
Tags: javascript, programming
Published: 2022-06-09 07:48:40

Hey Dev.to!
It is almost Friday, so lets start the day with a fun task, sum two numbers together. But without summing the two numbers together like this, like you would do normally: 
```
const num1 = 2;
const num2 = 3;
const result = num1 + num2;
console.log(result);
```

I start with my solution:

```
const num1 = 2;
const num2 = 3;
const arr1 = new Array(num1).fill(0);
const arr2 = new Array(num2).fill(0);

const result = arr1.concat(arr2).length;
console.log(result);
```

Will be fun to see what Frankenstein Solutions you folks come up with. ⚗️🧑‍💻
Introduction JavaScript
Tags: javascript
Published: 2022-06-09 07:48:30


### console.log()
The `console.log` method is used to log or print messages to the console. It can also be used to print objects and other info.
```JavaScript
console.log('Hello World!`); // Hello World!
```

### JavaScript
JavaScript is a programming language that powers the dynamyc behavior on most websites. Alongside HTML and CSS, it is a core technology that makes the web run.

### Methods
Methods return information about an object, and are called by appending an instance with a period`.`, the method name, and parentheses.

### Libraries
Libraries contain methods that can be called by appending the library name with a period `.`, the method name, and set of parentheses.

### Numbers
Numbers are a primitive data type. They include the set of all integers and floating point numbers.
```JavaScript
let amount = 5
let price = 16000;
let total = 80000;
```
### String.length
The `.length` property of a string returns the number of characters that make up the string.
```JavaScript
let message = 'Hello daddy!';
console.log(message.length); // 12
console.log('sugar'.length); // 5
```
### Conclusion
JavaScript arrays have quite a lot of useful methods that can simplify our development efforts.Knowing these methods can save us time and can even boost the performance of our code.
A professional and easy-to-use ecommerce data API
Tags: ecommerce, amazon, etsy, shopify
Published: 2022-06-09 07:45:41

I heard that high-end sellers use API to do their own data analysis...

**1. What "things" does EcomScrapy have?**
[EcomScrapy](https://ecomscrapy.com)  is a professional e-commerce data API website, built by the original team of AmzChart and FindNiche for e-commerce practitioners. By calling the interface we provide, you can find Amazon, AliExpress , Shopify, Etsy over 100 million product data.

How big is its database?
● 60 million + Amazon data, 86 million + AliExpress data, 61 million + Shopify data, 45 million + Etsy data;
● Contains the commodity and all other associated data, and retains up to 90 days of historical data;

**2. What do we offer?**
EcomScrapy currently provides two main functions: [Product Search API] and [Product Screening API].
In EcomScrapy's massive database, you can accurately find most of the products you are looking for and all the information you want to see;
Using more than 20 kinds of filter conditions we provide, you can create nearly a hundred product analysis dimensions, and filter out the products you are looking for in large quantities.
Creating an alternative to "donation" intended for developers
Tags: idea, donation, developers, brainstorm
Published: 2022-06-09 07:35:15

I would like to brainstorm with you brilliant minds to create an alternative for the "donation" for developers (e.g "buy me a coffee").

The point of this effort is finding a fresher newer method for all kind of developers to collect donations from their contributors. This brainstorming session intention will not aim for a creation of a product or any kind of solution. I would like to stay on the theoretical idea layer and rename and upgrade the idea of donation 
which is asking for a cup of coffee from other people.

I will use the ultimate idea from this brainstorming in my personal website. I'm very excited to hear you guys great ideas.

I'll shoot first and i'm a pretty bad shooter;
"Share my expenses.🤘"
"Next drinks on you.🍻"
Longest Happy Prefix
Tags: leetcode, dsa, theabbie
Published: 2022-06-09 07:30:39

A string is called a **happy prefix** if is a **non-empty** prefix which is also a suffix (excluding itself).

Given a string `s`, return _the **longest happy prefix** of_ `s`. Return an empty string `""` if no such prefix exists.

**Example 1:**

**Input:** s = "level"
**Output:** "l"
**Explanation:** s contains 4 prefix excluding itself ("l", "le", "lev", "leve"), and suffix ("l", "el", "vel", "evel"). The largest prefix which is also suffix is given by "l".

**Example 2:**

**Input:** s = "ababab"
**Output:** "abab"
**Explanation:** "abab" is the largest prefix which is also suffix. They can overlap in the original string.

**Constraints:**

*   `1 <= s.length <= 105`
*   `s` contains only lowercase English letters.

**SOLUTION:**

    class Solution:
        def longestPrefix(self, s: str) -> str:
            M = len(s)
            lps = [0] * M
            l = 0
            i = 1
            while i < M:
                if s[i] == s[l]:
                    l += 1
                    lps[i] = l
                    i += 1
                else:
                    if l != 0:
                        l = lps[l-1]
                    else:
                        lps[i] = 0
                        i += 1
            return s[:lps[-1]]
Hotshot Developer.
Tags: beginners, tutorial, motivation, webdev
Published: 2022-06-09 07:13:02

### Look at you, you coding wizard. Do you feel like God creating this centralized div? Hold your horses, you are not so cool as you might think, hotshot.
&nbsp;
But before breaking the illusion, let's fly around with Peter Pan using our fabulous fairy wings a bit longer.
&nbsp;
It's tough to blame anyone for coming into the programming wild-west with overly optimistic expectations. 
&nbsp;
It's like the mid-19th-century gold rush all over again, or some would call it the ‘promised land’ kind of discovery. 
&nbsp;
**Why is programming so hot right now? Because of the gold.** People smell money. It takes time until the aroma is spread, so people eventually smell the opportunity here, unlike the delicious smell of Paris's Croissants bakeries.
&nbsp;
Of course, I'm not talking about everyone, but most definitely the majority.
&nbsp;
By the way, do you know who made the most money from the gold rush? 
&nbsp;
*Those who sold pickaxes.* 
&nbsp;
Could you guess who are the pickaxes sellers of the programming gold rush nowadays? It's the Bootcamps, Universities, online and offline courses, etc.
&nbsp;
But we do have the Mother Teresa kind of programs, like [FreeCodeCamp](https://www.freecodecamp.org/learn) or [The Odin Project](https://www.theodinproject.com/) type; God bless you.
&nbsp;
I want to shift your mind and thoughts to something else, the "I'm such a rockstar” learning to code phase (also known as “The Hand-Holding Honeymoon”). 
&nbsp;
**Code, not to program.**
&nbsp;

> So our dear pickaxes sellers did a fantastic work promoting the
> **“Everyone can code”** slogan, breaking down barriers and showing
> people that code will not bite you.

&nbsp;
They reach out with the gentlest of touches to assure you that anyone can not just learn to code but become the next Steve Jobs, Elon Musk, or Mark Zuckerberg kind of person, in fact, sometimes it's so assuring that what is missing is to tell you that you should ***call your mom and tell her you aren't a total ~~loser~~, and you will be building the next big thing in a matter of weeks.*** 
&nbsp;
Suddenly, the issue is no longer fear of code but rather an overflow of optimism and high expectations—you poor thing.
&nbsp;
For the most part, these educational programs (I'm talking about free and paid ones) do a great job of holding your hand like a child in a crosswalk, past the big scary conditional statements,  variables, and through the early chapters of programming syntax. 
&nbsp;
And as you go and conquer one hill at a time - your confidence grows, it won't take too long until you feel unstoppable. You're basically a developer already!
&nbsp;
![Learning graph](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/huyoew0n8mb07coqa33w.png)
&nbsp;
So if you're able to read the graph, you should realize that you are screwed - pardon my French.
&nbsp;
Though it may appear like the finish is near, you're just like 45 minutes in, so buckle up, this is only the start. There are so many more hills to climb.
&nbsp;
Also, consider **creating a support system** - I will write about that next time.
A11Y 101: WAI-ARIA States
Tags: a11y, webdev, beginners
Published: 2022-06-09 07:12:26

Now that we had a look at all the possible ARIA properties let's do the same for all of the states.

It's good to remember that states are there to add what current state an element is in.

## WAI-ARIA States list

- **aria-checked**: Indicate the current checked state of input fields that can have this state
- **aria-disabled**: Described if the element is currently disabled
- **aria-expanded**: Describe if the element is expanded or collapsed.
- **aria-haspopup**: Describe if the element has a popup and which type, values are: `false`, `true`, `menu`, `listbox`, `tree`, `grid`, or `dialog`.
- **aria-hidden**: Indicate if the element is not visible
- **aria-invalid**: Describe if the input is invalid or not.
- **aria-modal**: Indicate whether the element is an active modal.
- **aria-multiline**: Whether a texture accepts multiple lines.
- **aria-multiselectable**: Used to describe elements with multiple selectable options, for example, a multiple select list.
- **aria-pressed**: Describe if the current element is pressed.
- **aria-readonly**: Describe if an input element is read-only.
- **aria-required**: Describe if an element is required or not.
- **aria-selected**: Wether the current option element is selected.
- **aria-busy**: Used to indicate if the area is still loading or busy with something.
- **aria-atomic**: Describe if a live region will announce all or only parts of the content.
- **aria-grabbed**: Describe a grabbed state to a drag n drop active element.

We should also always see if there is no semantic alternative we can use.

For most of the form fields, this is the case. Let's look at `aria-readonly` and `aria-required`, for instance.

For input fields, we could do the following:

```html
<input readonly required />
```

The main takeaway is only use these aria states if the semantics are insufficient to handle your condition.

### Thank you for reading, and let's connect!

Thank you for reading my blog. Feel free to subscribe to my email newsletter and connect on [Facebook](https://www.facebook.com/DailyDevTipsBlog) or [Twitter](https://twitter.com/DailyDevTips1)
Convert dataframe with xml to json using pyspark
Tags: pyspark
Published: 2022-06-09 07:06:10

I have a big text file which has list of xml data separated by comma. I am using pyspark to read the text file, convert the data into pyspark dataframe. 
Note i will have the xml data in single column with multiple rows of xml data. Then I wanted to convert xml to json and replace the xml with json data in dataframe. Any idea or help on how to achieve this will be really helpful. Thank you in advance.
Longest Path With Different Adjacent Characters
Tags: leetcode, dsa, theabbie
Published: 2022-06-09 07:00:48

You are given a **tree** (i.e. a connected, undirected graph that has no cycles) **rooted** at node `0` consisting of `n` nodes numbered from `0` to `n - 1`. The tree is represented by a **0-indexed** array `parent` of size `n`, where `parent[i]` is the parent of node `i`. Since node `0` is the root, `parent[0] == -1`.

You are also given a string `s` of length `n`, where `s[i]` is the character assigned to node `i`.

Return _the length of the **longest path** in the tree such that no pair of **adjacent** nodes on the path have the same character assigned to them._

**Example 1:**

![](https://assets.leetcode.com/uploads/2022/03/25/testingdrawio.png)

**Input:** parent = \[-1,0,0,1,1,2\], s = "abacbe"
**Output:** 3
**Explanation:** The longest path where each two adjacent nodes have different characters in the tree is the path: 0 -> 1 -> 3. The length of this path is 3, so 3 is returned.
It can be proven that there is no longer path that satisfies the conditions. 

**Example 2:**

![](https://assets.leetcode.com/uploads/2022/03/25/graph2drawio.png)

**Input:** parent = \[-1,0,0,0\], s = "aabc"
**Output:** 3
**Explanation:** The longest path where each two adjacent nodes have different characters is the path: 2 -> 0 -> 3. The length of this path is 3, so 3 is returned.

**Constraints:**

*   `n == parent.length == s.length`
*   `1 <= n <= 105`
*   `0 <= parent[i] <= n - 1` for all `i >= 1`
*   `parent[0] == -1`
*   `parent` represents a valid tree.
*   `s` consists of only lowercase English letters.

**SOLUTION:**

    from collections import defaultdict
    
    class Solution:
        def longest(self, tree, root, s, branch):
            l = 1
            key = (root, branch)
            if key in self.cache:
                return self.cache[key]
            if branch:
                best = 0
                sbest = 0
                for j in tree[root]:
                    if s[root] != s[j]:
                        currl = self.longest(tree, j, s, False)
                        sbest, best = sorted([sbest, best, currl])[-2:]
                l = max(l, 1 + best + sbest)
                self.cache[key] = l
                return l
            for j in tree[root]:
                if s[root] != s[j]:
                    currl = self.longest(tree, j, s, False)
                    l = max(l, 1 + currl)
            self.cache[key] = l
            return l
        
        def longestPath(self, parent: List[int], s: str) -> int:
            n = len(s)
            self.cache = {}
            tree = defaultdict(list)
            for i in range(n):
                if parent[i] != -1:
                    tree[parent[i]].append(i)
            mpath = 0
            for i in range(n):
                l = self.longest(tree, i, s, True)
                mpath = max(mpath, l)
            return mpath