teleren/devto huggingface dataset:
Speeds up Your Tests!
Tags: laravel, testing, artisan
Published: 2022-06-03 20:36:18

Great news! With a simple command 

```bash
// Dump the current database and save it in database/schema
php artisan schema:dump
 
// Dump the current database schema and prune all existing migrations...
php artisan schema:dump --prune
```
You can greatly speed up your tests! Continue to find out more!

Hi everyone! These days I have been tasked to implement automated testing for a Laravel that had zero test coverage from the start. 

As you probably know, Laravel's default testing behaviour is to use SQlLite, and in-memory database to run all tests against.  

When building my first test however, I needed to ensure that my test database had data it could test against. So, I needed to use Laravel's RefreshDatabase Trait in my test.

The RefreshDatabase trait instructs laravel to run clear the testing database, and run all database migrations to set up the tables.

At this point in the development stage, we had about 50 migration files already, and some of them used MySql's DropColumn command which is incompatible with SQlLite.  

To fix the problem, I edited the phpunit.xml file, and changed the server variables to point to a MySql testing database instead

```html
 <server name="DB_CONNECTION" value="mysql"/>
 <server name="DB_DATABASE" value="testing"/>
 <server name="DB_USERNAME" value="testuser1"/>
 <server name="DB_PASSWORD" value="mypassword"/>
```

I then re-ran the unit test, and it completed. Unfortunately, the test took 17 seconds to run!  The culprit?  You guessed it - the 50 migration files!

But then I got thinking - since the migration files are just a list of steps we took through our development iterations to get the database just perfect, why not just have one migration that creates the entire database in one fell swoop?

The next though I had was - wait - I bet I am not the only one that has thought of this solution!  And sure enough, as of [Laravel 8, there is a new console command](https://laravel.com/docs/8.x/migrations) that allows you to do just that:

```bash
// Dump the current database and save it in database/schema
php artisan schema:dump
 
// Dump the current database schema and prune all existing migrations...
php artisan schema:dump --prune
```

Now, the next time you run "php artisan migrate", the database will be set to the current state it was when you ran the schema dump, and then any other migrations after that point will also be run.

And guess what?  My 17 second test now ran in 4 seconds!  what a great improvement!
Ruby - Inheritance
Tags: ruby, objects, inheritance, webdev
Published: 2022-06-03 20:32:31

## What is Inheritance?
Ruby is an object-oriented programming language, and thus allows for inheritance. This allows the programmer to inherit the characteristics of one Ruby class into another Ruby class, which is called the _superclass_. Why would we want this? Well, let's be honest here. _Programmers are lazy_. Inheritance allows us to reuse code. Less typing, more happy.

## How to understand inheritance
In our everyday lives, different things are related to each other in various ways. For example, there are many different brands of "cars" such as Honda, Toyota, Subaru, etc. Though they are different brands of cars, they are still all "cars" that have the same characteristics at their core.

A less hierarchal example would be a class of "students" and a class of "programmers" and how they interact. Not all students are programmers, but all programmers are students(if we are talking about students in a school).

This translates very well with Ruby. The use of inheritance in Ruby allows us to create classes that have shared behaviors, while also still having their differences.

## Super Class and Subclass
The class which is inheriting is a _subclass_. A subclass has access to all of the methods of its parent, or _super class_. Back to our previous example, "Honda" is a subclass of "car" and so "Honda" is our subclass and "car" is our super class.
From "car" we might inherit that a car has four wheels, or a car is 6 windows. However some cars may be electric, while some may be gas. The use of inheritance in programming allows us to inherit methods that can be useful to many different subclasses, while allowing them to also contain their own unique characteristics.

## How do we inherit from another class?
There is a very simple syntax to say you want to inherit from another class in Ruby. It looks like this:

`class Honda < Cars
//Code goes here
end`

We now have access, through inheritance, to whatever is in the "Cars" class!

We can also find the super class of a class but using the .superclass method:
`Honda.superclass` in our example, would return "Car" `=> Car`

## Using our inherited methods
Now that we have set up our inheritance, we can use the .super method call to refer to methods from our super class for use in our subclass!

Our example may look like this:

```
//Super Class
class Car
  def name
    puts "Civic"
  end
end

//Subclass
class Honda < Car
  def name
    super
  end
end

car = Honda.new
car.name

=> Civic
```
Trim a Binary Search Tree
Tags: leetcode, dsa, theabbie
Published: 2022-06-03 20:30:39

Given the `root` of a binary search tree and the lowest and highest boundaries as `low` and `high`, trim the tree so that all its elements lies in `[low, high]`. Trimming the tree should **not** change the relative structure of the elements that will remain in the tree (i.e., any node's descendant should remain a descendant). It can be proven that there is a **unique answer**.

Return _the root of the trimmed binary search tree_. Note that the root may change depending on the given bounds.

**Example 1:**

![](https://assets.leetcode.com/uploads/2020/09/09/trim1.jpg)

**Input:** root = \[1,0,2\], low = 1, high = 2
**Output:** \[1,null,2\]

**Example 2:**

![](https://assets.leetcode.com/uploads/2020/09/09/trim2.jpg)

**Input:** root = \[3,0,4,null,2,null,null,1\], low = 1, high = 3
**Output:** \[3,2,null,1\]

**Constraints:**

*   The number of nodes in the tree is in the range `[1, 104]`.
*   `0 <= Node.val <= 104`
*   The value of each node in the tree is **unique**.
*   `root` is guaranteed to be a valid binary search tree.
*   `0 <= low <= high <= 104`

**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 trimBST(self, root: Optional[TreeNode], low: int, high: int) -> Optional[TreeNode]:
            if root:
                if low <= root.val <= high:
                    root.left = self.trimBST(root.left, low, high)
                    root.right = self.trimBST(root.right, low, high)
                elif root.val < low:
                    root = self.trimBST(root.right, low, high)
                else:
                    root = self.trimBST(root.left, low, high)
            return root
Increase Productivity by Decreasing Comfort
Tags: career, programming, beginners, tutorial
Published: 2022-06-03 20:10:49

I sat there at my desk exhausted from another day of working from home. My 49" ultrawide curved monitor's screen continued to flash with alerts and intrusive pings. I ached; my back was sore. I  hadn't left my desk in 8 hours. 

> I cant keep doing this 

I thought to myself. Tech has become overwhelming,  I remembered my first experience with tech in  1998 when I'd play on my father's old 1988 Macintosh Plus and felt joy at the compactness of it. More importantly, I enjoyed the idea of its inability to intrude into my life.

I decided to make a change, my set up had become too comfortable, and too instrusive. I was spending more time in the digital world than in the real one an unhealthy habit.

So, I rang up my dad and asked if he had that old macintosh plus. He said yeah but it's broken and won't turn on. I said that's okay I have an idea for it. 

I had stumbled upon the idea of uncomfortable tech.

>The idea is that tech is made intentionally cumbersome or uncomfortable to make you want to stop

I knew the old Macintosh Plus would be perfect for it and began a list of all the items for the build:
Kishaver F62 by Model F Keyboards

1. Cleo 2 by QOR 360
2. Macintosh Mouse Adapter by TinkerBoy
3. 8" Screen by Pimoroni found on AdaFruit
4. 3D Screen Holder File by Me
5. 3D Print Order from JawsTec
6. M1 Mac Mini by Apple
7. Macintosh Plus case via Dad but you can find them on Ebay or Garage Sales if lucky

I sold my ultrawide monitor and old office chair to fund the projects more expensive pieces; chair and keyboard. 

Assembly was straightforward. 

The M1 Mac Mini fit perfectly, replacing  the previous busted motherboard that also stood vertically. I used the box that the sceen came in to  stand the new computer on, again it was a perfect size:

I then had the frame to hold the screen printed. I chose to use a 3D printer from online because I desired a powdered frame that is smoother in appearance than the typical layered approach. 

If you prefer to save  some money then check around in your local community for 3D printers and it'll probably be under 100 USD, dependent upon the finish selected and material.

Results
I have been using this set up for a few months now and it has done the job of keeping me focused and more importantly keeping me off of the computer as much. As far as productivity goes I've found it to help hone in my focus to tasks such as writing code and of course writing.

I have to focus because it is a race against uncomfort– I can only use the computer for about 1 hr before feeling the need to stand up, stretch, and go outside to get some fresh scenery for my eyes.
Vertical Order Traversal of a Binary Tree
Tags: leetcode, dsa, theabbie
Published: 2022-06-03 20:00:47

Given the `root` of a binary tree, calculate the **vertical order traversal** of the binary tree.

For each node at position `(row, col)`, its left and right children will be at positions `(row + 1, col - 1)` and `(row + 1, col + 1)` respectively. The root of the tree is at `(0, 0)`.

The **vertical order traversal** of a binary tree is a list of top-to-bottom orderings for each column index starting from the leftmost column and ending on the rightmost column. There may be multiple nodes in the same row and same column. In such a case, sort these nodes by their values.

Return _the **vertical order traversal** of the binary tree_.

**Example 1:**

![](https://assets.leetcode.com/uploads/2021/01/29/vtree1.jpg)

**Input:** root = \[3,9,20,null,null,15,7\]
**Output:** \[\[9\],\[3,15\],\[20\],\[7\]\]
**Explanation:**
Column -1: Only node 9 is in this column.
Column 0: Nodes 3 and 15 are in this column in that order from top to bottom.
Column 1: Only node 20 is in this column.
Column 2: Only node 7 is in this column.

**Example 2:**

![](https://assets.leetcode.com/uploads/2021/01/29/vtree2.jpg)

**Input:** root = \[1,2,3,4,5,6,7\]
**Output:** \[\[4\],\[2\],\[1,5,6\],\[3\],\[7\]\]
**Explanation:**
Column -2: Only node 4 is in this column.
Column -1: Only node 2 is in this column.
Column 0: Nodes 1, 5, and 6 are in this column.
          1 is at the top, so it comes first.
          5 and 6 are at the same position (2, 0), so we order them by their value, 5 before 6.
Column 1: Only node 3 is in this column.
Column 2: Only node 7 is in this column.

**Example 3:**

![](https://assets.leetcode.com/uploads/2021/01/29/vtree3.jpg)

**Input:** root = \[1,2,3,4,6,5,7\]
**Output:** \[\[4\],\[2\],\[1,5,6\],\[3\],\[7\]\]
**Explanation:**
This case is the exact same as example 2, but with nodes 5 and 6 swapped.
Note that the solution remains the same since 5 and 6 are in the same location and should be ordered by their values.

**Constraints:**

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

**SOLUTION:**

    import heapq
    
    # 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:
        nodes = {}
        
        def traverse(self, root, w, h):
            if root:
                self.traverse(root.left, w - 1, h + 1)
                self.nodes[w] = self.nodes.get(w, []) + [(h, root.val)]
                self.traverse(root.right, w + 1, h + 1)
        
        def verticalTraversal(self, root: Optional[TreeNode]) -> List[List[int]]:
            op = []
            self.nodes = {}
            self.traverse(root, 0, 0)
            heap = [(w, n) for w, n in self.nodes.items()]
            heapq.heapify(heap)
            while len(heap) > 0:
                w, n = heapq.heappop(heap)
                n.sort()
                op.append([item[1] for item in n])
            return op
useMemo(function(a,b),[a]) warning message - diference quantity
Tags: react, usememo
Published: 2022-06-03 19:41:47

How do I pass a different quantity of dependencies to useMemo than properties to the function?
Problem:

función LayoutRolesUser(){
const context= useContext(Context);
const itemsDropdownRole= useMemo(()=> cbItemsRolesUser(context.user.listIdsItemsDropDownRol, context.cache.lastIdDropDownRolSelectedInLastSession), [context.user.listIdsItemsDropDownRol]);

return(
<div>
<select id="role">
  {itemsDropdownRole}
</select>
</div>
)};
Python 8 Important Concepts to learn
Tags: python, javascript, programming, tutorial
Published: 2022-06-03 19:31:49

A lot of us are caught in learning the frameworks and newest techs, but actually we forgot how to code in the language itself.
Python like JavaScript like any other language, you need to learn ES6 and core vanilla JavaScript before you start learning React and Angular; same with Python, don't jump on Django, Flask or Tornado without understanding what is list comprehension, what are mutable and immutable data types, generators, **kwargs, *args, Asyncio, iterators, decorators, memory references or lambda functions !!

I recently had a Tech interview and I discovered that I miss a lot of the core concepts of the language, however I know how to run Django Admin site, write SQLite queries for a Django project and deploy an app to Heroku !    

My advise, especially to the young who just started their programming journey, learn how to walk first before you run; otherwise you will be very confused and probably would hate to program and might even change your career to be a fisherman instead!

Check out this video, and let me know about other concepts that you would be interested to learn.

Thank You and Happy Learning.

{%youtube qeOcZiSp3tE%}
Intersection of Two Arrays II
Tags: leetcode, dsa, theabbie
Published: 2022-06-03 19:30:40

Given two integer arrays `nums1` and `nums2`, return _an array of their intersection_. Each element in the result must appear as many times as it shows in both arrays and you may return the result in **any order**.

**Example 1:**

**Input:** nums1 = \[1,2,2,1\], nums2 = \[2,2\]
**Output:** \[2,2\]

**Example 2:**

**Input:** nums1 = \[4,9,5\], nums2 = \[9,4,9,8,4\]
**Output:** \[4,9\]
**Explanation:** \[9,4\] is also accepted.

**Constraints:**

*   `1 <= nums1.length, nums2.length <= 1000`
*   `0 <= nums1[i], nums2[i] <= 1000`

**Follow up:**

*   What if the given array is already sorted? How would you optimize your algorithm?
*   What if `nums1`'s size is small compared to `nums2`'s size? Which algorithm is better?
*   What if elements of `nums2` are stored on disk, and the memory is limited such that you cannot load all elements into the memory at once?

**SOLUTION:**

    class Solution:
        def intersect(self, nums1: List[int], nums2: List[int]) -> List[int]:
            d1 = {}
            d2 = {}
            for num in nums1:
                d1[num] = d1.get(num, 0) + 1
            for num in nums2:
                d2[num] = d2.get(num, 0) + 1
            common = set.intersection(set(d1.keys()), set(d2.keys()))
            ans = []
            for c in common:
                ans += [c] * min(d1.get(c, 0), d2.get(c, 0))
            return ans
Zero-configuration SPA serving in Docker with Traefik and spa-to-http
Tags: webdev, vue, react, docker
Published: 2022-06-03 19:15:36

Hey everyone👋🏼

We are proud to announce another Open-Source MIT-licensed tool to serve static in Docker, which has pretty good compatibility with HTTP proxies like Traefik.

[SPA to HTTP on GitHub](https://github.com/devforth/spa-to-http)

[Step-by-step guide to SPA serving with Traefik and spa-to-http](https://devforth.io/blog/zero-configuration-spa-serving-in-docker-with-traefik-and-spa-to-http/)
Binary Tree Maximum Path Sum
Tags: leetcode, dsa, theabbie
Published: 2022-06-03 19:00:46

A **path** in a binary tree is a sequence of nodes where each pair of adjacent nodes in the sequence has an edge connecting them. A node can only appear in the sequence **at most once**. Note that the path does not need to pass through the root.

The **path sum** of a path is the sum of the node's values in the path.

Given the `root` of a binary tree, return _the maximum **path sum** of any **non-empty** path_.

**Example 1:**

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

**Input:** root = \[1,2,3\]
**Output:** 6
**Explanation:** The optimal path is 2 -> 1 -> 3 with a path sum of 2 + 1 + 3 = 6.

**Example 2:**

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

**Input:** root = \[-10,9,20,null,null,15,7\]
**Output:** 42
**Explanation:** The optimal path is 15 -> 20 -> 7 with a path sum of 15 + 20 + 7 = 42.

**Constraints:**

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

**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 pathsum(self, root):
            if root:
                l = self.pathsum(root.left)
                r = self.pathsum(root.right)
                self.msum = max(self.msum, root.val, l + root.val, root.val + r, l + root.val + r)
                return max(root.val, root.val + l, root.val + r)
            return float('-inf')
        
        def maxPathSum(self, root: Optional[TreeNode]) -> int:
            self.msum = float('-inf')
            self.pathsum(root)
            return self.msum
Today I learned about the splat operator in Ruby.
Tags: ruby, rails, discuss
Published: 2022-06-03 18:55:58

### Background
In my use case, I wanted to pass an array of fields into the `.pluck` operator for a query, but the pluck operator doesn't take in arrays. Obviously, the solution here is to destructure the array. Were it JS I probably would have just written `.pluck(...pluck_fields)` and moved on with my life. But funny enough, I have never had to destructure an array within function arguments. So I asked my supervisor and they told me to check the splat operator.

### Splat Operator (* & **)
According to [this article](https://www.honeybadger.io/blog/ruby-splat-array-manipulation-destructuring/) by Starr Horne, ***They (splat operators) let you pass an array into a function expecting multiple arguments. The first item in the array becomes the first argument, the second item becomes the second argument and so on.**

Splat operator is more commonly used in function definition when the number of arguments is not known before hand, for instance: 
```
def fun(*args)
    p args
end
```

But in my use case, I want to focus on the first definition I mentioned, ***they can be used to pass an array into a function expecting multiple arguments***. This directly solves my problem, where now i can pass an array of fields I want plucked to the pluck function, 
```
.pluck(*pluck_fields)
```

There is a lot more to explain about the splat operator and how it can also destructure Hashes as well, but that is beyond the scope of this post for now. ( [This Post also explains it better](https://samibirnbaum.com/2021/12/22/splat-operator.html) )

SPLAT!!!!
Web3 Solidity + JavaScript 32 hour course recap #8
Tags: blockchain, solidity, learning
Published: 2022-06-03 18:45:12

timestamps: 2:44:10-3:00:00

This is the recap of my sixth day of making my way through the 32 hour course by Patrick Collins posted on [FreeCodeCamp](https://www.youtube.com/watch?v=gyMwXuJrbJQ).

Today we celebrate the milestone of completing 3 hours of the course! We're **almost** 10% of the way through!

We went over how to define an object, and how to call it from an external source.

We also went over how to connect (remix)[https://remix.ethereum.org/] to our Metamask test wallet.

There are six places where memory can be stored in a SmartContract: stack, memory, storage, calldata, code, and logs. However, memory and calldata are the only places where the storage can be specified. Calldata and memory are both temporary pieces of data. However calldata is like declaring a const, while memory is like declaring a let. By that I mean that calldata is read only and the information cannot be changed within the SmartContract, but memory can be reassigned a value within the SmartContract.

One thing that I found out was that the metamask extension doesn't like for you to switch accounts, and if you have 0 eth in your wallet the 2+ accounts won't reconnect automatically. But you can manually add them back, and they will have the original amount that existed before. This happened in a dev account, but I still did not like the fact that all of my accounts didn't appear right away.
How did you get your first developer job?
Tags: career, help, beginners, discuss
Published: 2022-06-03 18:44:39

Hello DEV community, 
Right now I'm currently looking for my first developer job.  Here are my skills so far: 

- HTML
- CSS / SCSS
- vanilla JavaScript(can't do any complex code)
- Git basics

Here's my [resume](https://docs.google.com/document/d/1yE_fegUWpec2pa4Y-ZkyzAvNzxrpZI7iDs2JWVkm4c0/edit#) for reference. 

I met someone while networking who was going to refer me for a job. But when she saw my resume, she said I still need to work on developing more skills especially Git.

I really want to start working. And I'm tired of having to put off job searching because of my subpar skills. Of course I'm still learning new things along the way. And I'm not expecting my first job to be anything spectacular.

So how did you guys get your first developer job? 
How far along in your journey did you start applying?