teleren/devto huggingface dataset:
The Quest to Build the Perfect Bot w/ Ubisoft's Joshua Romoff
Tags: podcast, programming, techtalks, devops
Published: 2022-06-02 22:18:22

_We want to make the Dev Interrupted podcast a vital, enjoyable part of your week._ ***Please take 2 minutes and answer our new*** [***Listener Survey.***](https://www.surveymonkey.com/r/PRYRNC5) _It lets us know a bit about you, what you want from Dev Interrupted and what you want from podcasts in general!_

Almost every single company we talk to focuses on having their engineering teams solve problems.

This is why we jumped at the opportunity to talk to Joshua Romoff from [Ubisoft](https://www.ubisoft.com/en-us/company/about-us).

Why? The goal of gaming companies isn’t so much to solve problems, but to enrich their customers’ lives.

That’s a unique, powerful change in how to think about building, developing and shipping features. Something that required Ubisoft to bring in Research Scientists like Joshua to figure out just what it is customers engage with in their games and how to give them more of it using AI.

Whether or not you're a gamer, this is a fascinating conversation on how every engineering team should think about building self-improving features.

{% spotify spotify:episode:0WFBeGYtC8stOkfmXeNnuH %}

## Episode Highlights Include:
* (2:04) What is Ubisoft La Forge?
* (7:33) Training bots = training a dog or cat
* (9:30) NPCs of the future
* (15:16) 90% of academic research is useless
* (22:56) Prototypes Ubisoft is building
* (28:18) The video game character Josh would pick for his team

***Starved for top-level software engineering content? Need some good tips on how to manage your team? This article is inspired by [Dev Interrupted](https://devinterrupted.com/podcasts/) - the go-to podcast for engineering leaders.***

_Dev Interrupted features expert guests from around the world to explore strategy and day-to-day topics ranging from dev team metrics to accelerating delivery. With new guests every week from Google to small startups, the Dev Interrupted Podcast is a fresh look at the world of software engineering and engineering management._

[_Listen and subscribe on your streaming service of choice today._](https://devinterrupted.com/podcasts/)

![Join the Dev Interrupted Discord Community](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qhhtbkqx61c836e9anhr.png)
My machine-learning pet project. Part 2. Preparing my dataset
Tags: machinelearning, imagerecognition
Published: 2022-06-02 22:17:36

---
title: My machine-learning pet project. Part 2. Preparing my dataset 
published: true
description: 
tags: machinelearning, imagerecognition
//cover_image: https://direct_url_to_image.jpg
---

My pet-project is about food recognition. More info [here](https://dev.to/whatever/my-machine-learning-pet-project-part-1-9o2). 

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

######Data sets in tutorials vs data sets in the wild. From [Towards AI](https://twitter.com/towards_AI/status/1332567246011555840?s=20) on Twitter######


First thing that came to my mind was to scrape stuff from some instagram account. Have you seen how many recipes are there??? Millions. And they have descriptions, from which I could extract labels. I thought it would be ez. I managed to scrape about 10 posts using this:
```javascript
instaloader profile nytcooking --no-videos --no-metadata-json --slide 1 --post-filter='date_utc >= datetime(2012, 5, 21)' --sanitize-paths
```
So far so good. But then I tried to scrape a bit more, e.g. posts for 3 months, and started getting 429 Too many requests errors. Creating new instagram profiles didn't help. How could I, alone, beat an army of well paid developers? I needed another approach. 

I chose one of the recipe websites that I used to visit. It has good photos and descriptions and it's easy to scrape. I picked [Scrapy](https://scrapy.org/) to do the job. It's actively supported (last commit - 5 days ago), has good documentation and a readable code.

I saved one sample webpage to my desktop and launched [scrapy shell](https://docs.scrapy.org/en/latest/topics/shell.html):

```
scrapy shell ../Desktop/test.html
``` 
It helped me to prepare a bunch of selectors like this:
```
recipe.xpath('./p[@class="material-anons__des"]//text()').get()
```
Then I created a project template using command like this:
```
scrapy startproject myproject [project_dir]
```
I took a look at their [example repo at github](https://github.com/scrapy/quotesbot/tree/master/quotesbot/spiders). 

The only thing I have struggled for some time was item pipelines. At one point I copied some stuff from stackoverflow to *settings.py*. And scrapy started to complain, smth like *file A* has an error now. I went to scrapy github and found a nice little comment in *file A* about what really should be in the settings file now. So that's what I added to settings.py:

```
FILES_STORE = './csv'
IMAGES_STORE = './images'
ITEM_PIPELINES = {
    'scrapy.pipelines.images.ImagesPipeline': 1
}
FEEDS={
    './csv/items-%(batch_id)d': {
        'format': 'csv'
    }
}
```

These settings allowed me to download images and make a *.csv file with parsed titles,descriptions and image paths urls without writing any extra lines of code. In my opinion, Scrapy is a very powerful instrument, so I totally recommend to use it when you want to scrape some data (not from instagram).

The next post is going to be about brushing up scraped data and labelling it.
Day 55: Hello GraphQL 🙌
Published: 2022-06-02 22:07:22

Hi!
Hello GraphQL today I started learning about GraphQL and I have to admit it's one of the best technologies, very natural, easy to write and read and The purpose behind is very convincing especially coming from a Rest API. I found a really great introduction video [Here](https://youtu.be/N-81mS2vldI) and a good introduction course today was actually great! I plan to write a series of articles about a project in typescript, GraphQL Apollo and Prisma the only issue is that I don't have any idea about Apollo and Prisma YET! hahaha :)
so the plan for tomorrow is to learn about Apollo and hopefully work a project in the course I mentioned above and continue practicing about TypeScript, and GraphQL. 
Let's hope for the best
Signing off...
useState in React
Published: 2022-06-02 22:01:39


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

useState is a Hook that allows you to have state variables in functional components. You pass the initial state to this function and it returns a variable with the current state value (not necessarily the initial state) and another function to update this value.

What does the React.useState Hook do?

useState enables you to add state to function components. Calling React.useState inside a function component generates a single piece of state associated with that component.

Whereas the state in a class is always an object, with Hooks, the state can be any type. Each piece of state holds a single value, which can be an object, an array, a boolean, or any other type you can imagine.

So when should you use the useState Hook? It’s especially useful for local component state, but larger projects might require additional state management solutions.

Declaring state in React
useState is a named export from react. To use it, you can write:


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

Or to import it just write useState:


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

The useState Hook allows you to declare only one state variable (of any type) at a time, like this:


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

Using useState alone won’t work because its argument is used the first time only — not every time the property changes (look here for the right way to do this).

But useState doesn’t return just a variable as the previous examples imply.

It returns an array, where the first element is the state variable and the second element is a function to update the value of the variable:


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

Usually, you’ll use array destructuring to simplify the code shown above:


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

This way, you can use the state variable in the functional component like any other variable:


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

But why does useState return array?

Because compared to an object, an array is more flexible and easy to use.

If the method returned an object with a fixed set of properties, you wouldn’t be able to assign custom names in an easy way.

You’d have to do something like this (assuming the properties of the object are state and setState):


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g6o15w1k9kra6ssm862l.png)
Cells with Odd Values in a Matrix
Tags: leetcode, dsa, theabbie
Published: 2022-06-02 22:00:51

There is an `m x n` matrix that is initialized to all `0`'s. There is also a 2D array `indices` where each `indices[i] = [ri, ci]` represents a **0-indexed location** to perform some increment operations on the matrix.

For each location `indices[i]`, do **both** of the following:

1.  Increment **all** the cells on row `ri`.
2.  Increment **all** the cells on column `ci`.

Given `m`, `n`, and `indices`, return _the **number of odd-valued cells** in the matrix after applying the increment to all locations in_ `indices`.

**Example 1:**

![](https://assets.leetcode.com/uploads/2019/10/30/e1.png)

**Input:** m = 2, n = 3, indices = \[\[0,1\],\[1,1\]\]
**Output:** 6
**Explanation:** Initial matrix = \[\[0,0,0\],\[0,0,0\]\].
After applying first increment it becomes \[\[1,2,1\],\[0,1,0\]\].
The final matrix is \[\[1,3,1\],\[1,3,1\]\], which contains 6 odd numbers.

**Example 2:**

![](https://assets.leetcode.com/uploads/2019/10/30/e2.png)

**Input:** m = 2, n = 2, indices = \[\[1,1\],\[0,0\]\]
**Output:** 0
**Explanation:** Final matrix = \[\[2,2\],\[2,2\]\]. There are no odd numbers in the final matrix.

**Constraints:**

*   `1 <= m, n <= 50`
*   `1 <= indices.length <= 100`
*   `0 <= ri < m`
*   `0 <= ci < n`

**Follow up:** Could you solve this in `O(n + m + indices.length)` time with only `O(n + m)` extra space?

**SOLUTION:**

    class Solution:
        def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int:
            cols = [0] * n
            rows = [0] * m
            ctr = 0
            for r, c in indices:
                rows[r] += 1
                cols[c] += 1
            for i in range(n):
                for j in range(m):
                    if (cols[i] + rows[j]) % 2 == 1:
                        ctr += 1
            return ctr
Palindrome Partitioning II
Tags: leetcode, dsa, theabbie
Published: 2022-06-02 21:30:40

Given a string `s`, partition `s` such that every substring of the partition is a palindrome.

Return _the minimum cuts needed_ for a palindrome partitioning of `s`.

**Example 1:**

**Input:** s = "aab"
**Output:** 1
**Explanation:** The palindrome partitioning \["aa","b"\] could be produced using 1 cut.

**Example 2:**

**Input:** s = "a"
**Output:** 0

**Example 3:**

**Input:** s = "ab"
**Output:** 1

**Constraints:**

*   `1 <= s.length <= 2000`
*   `s` consists of lowercase English letters only.

**SOLUTION:**

    class Solution:
        def isPalindrome(self, s, i, j):
            if (i, j) in self.PalCache:
                return self.PalCache[(i, j)]
            val = False
            if i >= j - 1:
                val = s[i] == s[j - 1]
            elif s[i] == s[j - 1]:
                val = self.isPalindrome(s, i + 1, j - 1)
            self.PalCache[(i, j)] = val
            return val
        
        def mcuts(self, s, i, n):
            if i == n:
                return -1
            if i in self.cache:
                return self.cache[i]
            mincuts = n - i - 1
            for j in range(i + 1, n + 1):
                if self.isPalindrome(s, i, j):
                    val = self.mcuts(s, j, n)
                    mincuts = min(mincuts, 1 + val)
            self.cache[i] = mincuts
            return mincuts
        
        def minCut(self, s: str) -> int:
            self.cache = {}
            self.PalCache = {}
            n = len(s)
            return self.mcuts(s, 0, n)
Paracetamol.js💊| #131: Explica este código JavaScript
Tags: javascript, webdev, spanish, programming
Published: 2022-06-02 21:18:02

## **<center>¿Explica el siguiente código JavaScript?</center>**
#### <center>**Dificultad:** <mark>Avanzado</mark></center>

```js
const fetchData = (url) => {
  return fetch(url)
    .then(res => res.json())
    .then(res => console.log(res))
    .catch(err => console.log(err))
}

fetchData("https://jsonplaceholder.typicode.com/users")
```

¿Cuál de las siguientes opciones es equivalente a `fetchData`?
A.
```js
const fetchDataA = (url) => {
  try{
    const res = fetch(url);
    const data = res.json();
    console.log(data);
  }catch(err){
    console.log(err)
  }
}
fetchDataA("https://jsonplaceholder.typicode.com/users")
```
B.
```js
const fetchDataB = async(url) => {
  try{
    const res = await fetch(url);
    const data = await res.json();
    console.log(data);
  }catch(err){
    console.log(err)
  }
}
fetchDataB("https://jsonplaceholder.typicode.com/users")
```
C.
```js
const fetchDataC = (url) => {
  try{
    const res = await fetch(url);
    const data = await res.json();
    console.log(data);
  }catch(err){
    console.log(err)
  }
}
fetchDataC("https://jsonplaceholder.typicode.com/users")
```
D. Ninguna de las anteriores. 

Respuesta en el primer comentario.

---
Median of Two Sorted Arrays
Tags: leetcode, dsa, theabbie
Published: 2022-06-02 21:00:46

Given two sorted arrays `nums1` and `nums2` of size `m` and `n` respectively, return **the median** of the two sorted arrays.

The overall run time complexity should be `O(log (m+n))`.

**Example 1:**

**Input:** nums1 = \[1,3\], nums2 = \[2\]
**Output:** 2.00000
**Explanation:** merged array = \[1,2,3\] and median is 2.

**Example 2:**

**Input:** nums1 = \[1,2\], nums2 = \[3,4\]
**Output:** 2.50000
**Explanation:** merged array = \[1,2,3,4\] and median is (2 + 3) / 2 = 2.5.

**Constraints:**

*   `nums1.length == m`
*   `nums2.length == n`
*   `0 <= m <= 1000`
*   `0 <= n <= 1000`
*   `1 <= m + n <= 2000`
*   `-106 <= nums1[i], nums2[i] <= 106`

**SOLUTION:**

    class Solution:
        def findMedianSortedArrays(self, nums1: List[int], nums2: List[int]) -> float:
            m = len(nums1)
            n = len(nums2)
            k = m + n
            total = sorted(nums1 + nums2)
            if k & 1:
                return total[(k - 1) // 2]
            else:
                return (total[(k - 1) // 2] + total[1 + (k - 1) // 2]) / 2
What stood out to you from the Mayfield + DEV Discussion Series?
Tags: discuss, productivity, startup, career
Published: 2022-06-02 20:48:28

A couple weeks ago we wrapped up the [Mayfield + DEV Discussion Series](https://dev.to/devteam/introducing-the-mayfield-dev-discussion-series-2cbo), where over 500 people contributed directly to the conversation and about 25k people stopped by to read.

The discussion series were a lot about what you do now and where you see things going. We will be publishing a handful of wrap-up posts ourselves, but first I wanted to know if anybody here wanted to peruse the discussions and tell me what conversations or specific comments stood out to them as most interesting.
Discussion and Comment of the Week - v6
Tags: bestofdev
Published: 2022-06-02 20:45:48

**This weekly roundup highlights what we believe to be the most thoughtful and/or interesting discussion of the week. We're also be highlighting one particularly cool comment in each installment. 🙌**

The DEV Community is particularly special because of the kind and thoughtful discussions happening between community members. As such, we want to encourage folks to participate in discussions and reward those who are initiating or taking part in conversations across the community. After all, a community is made possible by the people interacting inside it.

_NOTE: I realize we didn't choose winners for last week. I was out on vacation and this completely slipped my mind. While there were plenty of excellent discussions, I'm going to skip over last week — please forgive me._ 😅

## Discussion of the Week

For this week, props go to @thekillerrex27 for dropping the prompt: "[What was your Dev Journey?](https://dev.to/thekillerrex27/what-was-your-dev-journey-7dc)" 

{% embed https://dev.to/thekillerrex27/what-was-your-dev-journey-7dc %}

The comments on this post are a great reminder that everyone starts somewhere and folks who we think of as dev rockstars are in fact just normal people with their own humble beginnings. It's inspiring to hear that there are countless ways to become a dev and that no matter what background you come from, you can be a dev too if you want it and work at it!

Everybody has their own story to tell about how they got into development or why they're getting started. Your story (no matter how grand or insignificant it may feel to you) might be all it takes to inspire someone else out there to get started or keep going. I urge you all to share your experiences and continue building each other up! 

## Comment of the Week

We'd like to highlight @facundocorradini's thoughtful response to @gabrielpedroza's excellent prompt "[Why is CSS Hated On?](https://dev.to/gabrielpedroza/why-is-css-hated-on-5ce1)"

{% embed https://dev.to/facundocorradini/comment/1p38h %}

And honestly, this comment alone doesn't do it justice; you should read the [full exchange](https://dev.to/facundocorradini/comment/1p38h) between Facundo and Gabriel! Reading through this discussion is so helpful for better understanding CSS and why folks often have gripes with it. Rather than try to sum things up myself, I'll just say read the comment(s)! ☝️

## What are your picks?

There's loads of great discussions and comments floating about in this community. These are just a few we chose to highlight. 🙂

I urge you all to share your favorite comment and/or discussion of the past week below in the comments. And if you're up for it, give the author an @mention — it'll probably make 'em feel good. 💚
Restore the Array From Adjacent Pairs
Tags: leetcode, dsa, theabbie
Published: 2022-06-02 20:30:49

There is an integer array `nums` that consists of `n` **unique** elements, but you have forgotten it. However, you do remember every pair of adjacent elements in `nums`.

You are given a 2D integer array `adjacentPairs` of size `n - 1` where each `adjacentPairs[i] = [ui, vi]` indicates that the elements `ui` and `vi` are adjacent in `nums`.

It is guaranteed that every adjacent pair of elements `nums[i]` and `nums[i+1]` will exist in `adjacentPairs`, either as `[nums[i], nums[i+1]]` or `[nums[i+1], nums[i]]`. The pairs can appear **in any order**.

Return _the original array_ `nums`_. If there are multiple solutions, return **any of them**_.

**Example 1:**

**Input:** adjacentPairs = \[\[2,1\],\[3,4\],\[3,2\]\]
**Output:** \[1,2,3,4\]
**Explanation:** This array has all its adjacent pairs in adjacentPairs.
Notice that adjacentPairs\[i\] may not be in left-to-right order.

**Example 2:**

**Input:** adjacentPairs = \[\[4,-2\],\[1,4\],\[-3,1\]\]
**Output:** \[-2,4,1,-3\]
**Explanation:** There can be negative numbers.
Another solution is \[-3,1,4,-2\], which would also be accepted.

**Example 3:**

**Input:** adjacentPairs = \[\[100000,-100000\]\]
**Output:** \[100000,-100000\]

**Constraints:**

*   `nums.length == n`
*   `adjacentPairs.length == n - 1`
*   `adjacentPairs[i].length == 2`
*   `2 <= n <= 105`
*   `-105 <= nums[i], ui, vi <= 105`
*   There exists some `nums` that has `adjacentPairs` as its pairs.

**SOLUTION:**

    class Solution:
        def restoreArray(self, adjacentPairs: List[List[int]]) -> List[int]:
            nums = {}
            singles = set()
            for a, b in adjacentPairs:
                nums[a] = nums.get(a, []) + [b]
                nums[b] = nums.get(b, []) + [a]
                if a in singles:
                    singles.remove(a)
                else:
                    singles.add(a)
                if b in singles:
                    singles.remove(b)
                else:
                    singles.add(b)
            first = list(singles)[0]
            n = len(nums)
            op = []
            op.extend([first, nums[first][0]])
            while len(op) < n:
                prev = op[-1]
                prevprev = op[-2]
                op.extend([k for k in nums[prev] if k != prevprev])
            return op
learning_ruby.rb
Tags: ruby, rails
Published: 2022-06-02 20:16:59

###today i've learned about how rails deal with different environment (production, development and test).
  * i can setup my environment in three ways, each one i can put selected gems and versions and i think that is so cool.

```
* rails console -e production
```

```
def ambiente_rails
      if Rails.env.development?
         "Development"
         elsif Rails.env.production?
         "Production" 
         else 
         "Test"
      end
```
Validate Binary Search Tree
Tags: leetcode, dsa, theabbie
Published: 2022-06-02 20:00:44

Given the `root` of a binary tree, _determine if it is a valid binary search tree (BST)_.

A **valid BST** is defined as follows:

*   The left subtree of a node contains only nodes with keys **less than** the node's key.
*   The right subtree of a node contains only nodes with keys **greater than** the node's key.
*   Both the left and right subtrees must also be binary search trees.

**Example 1:**

![](https://assets.leetcode.com/uploads/2020/12/01/tree1.jpg)

**Input:** root = \[2,1,3\]
**Output:** true

**Example 2:**

![](https://assets.leetcode.com/uploads/2020/12/01/tree2.jpg)

**Input:** root = \[5,1,4,null,null,3,6\]
**Output:** false
**Explanation:** The root node's value is 5 but its right child's value is 4.

**Constraints:**

*   The number of nodes in the tree is in the range `[1, 104]`.
*   `-231 <= Node.val <= 231 - 1`

**SOLUTION:**

    # Definition for a binary tree node.
    # class TreeNode:
    #     def __init__(self, val=0, left=None, right=None):
    #         self.val = val
    #         self.left = left
    #         self.right = right
    class Solution:
        def isValidBST(self, root: Optional[TreeNode], minVal = float('-inf'), maxVal = float('inf')) -> bool:
            if root:
                if root.val <= minVal or root.val >= maxVal:
                    return False
                if not self.isValidBST(root.left, minVal = minVal, maxVal = min(maxVal, root.val)) or not self.isValidBST(root.right, minVal = max(minVal, root.val), maxVal = maxVal):
                    return False
            return True