teleren/devto huggingface dataset:
2373. Largest Local Values in a Matrix
Published: 2024-05-14 16:28:17

https://leetcode.com/problems/largest-local-values-in-a-matrix/?envType=daily-question&envId=2024-05-14

May 12 solution



```javascript
/**
 * @param {number[][]} grid
 * @return {number[][]}
 */
/**
 * @param {number[][]} grid
 * @return {number[][]}
 */
var largestLocal = function (grid) {
    const nRows = grid.length;
    const nCols = grid[0].length;

    let result = new Array(nRows - 2).fill().map(() => new Array(nCols - 2).fill(0));

    for (let row = 0; row < nRows - 2; row++) {
        for (let col = 0; col < nCols - 2; col++) {
            result[row][col] = findLargest(grid, row, col);
        }
    }

    return result;
};

function findLargest(grid, row, col) {
    let best = grid[row][col];
    for (let i = row; i < row + 3; i++) {
        for (let j = col; j < col + 3; j++) {
            best = Math.max(best, grid[i][j]);
        }
    }
    return best;
}
```
857. Minimum Cost to Hire K Workers
Published: 2024-05-14 16:25:44

May 11 solution

https://leetcode.com/problems/minimum-cost-to-hire-k-workers/?envType=daily-question&envId=2024-05-14

```javascript

class Worker {
    constructor(ratio, quality) {
        this.ratio = ratio;
        this.quality = quality;
    }
}

var mincostToHireWorkers = function (quality, wage, k) {
    const n = quality.length;
    let minCost = Number.MAX_VALUE;
    let qualityTillNow = 0;
    let workers = [];

    for (let i = 0; i < n; i++) {
        workers.push(new Worker(wage[i] / quality[i], quality[i]));
    }

    // Sorting workers by their wage-quality ratio
    workers.sort((a, b) => a.ratio - b.ratio);

    // Max-heap to store qualities, implemented using a min-heap and inverting the values
    let highQualityWorkers = [];

    for (let worker of workers) {
        let ratio = worker.ratio;
        let qua = worker.quality;

        qualityTillNow += qua;
        highQualityWorkers.push(-qua);  // Push negative to simulate max-heap
        highQualityWorkers.sort((a, b) => a - b);  // Sort to maintain heap properties

        if (highQualityWorkers.length > k) {
            qualityTillNow += highQualityWorkers.shift();  // Remove largest quality (which is negative)
        }

        if (highQualityWorkers.length === k) {
            minCost = Math.min(minCost, qualityTillNow * ratio);
        }
    }

    return minCost;
};
```
Premium Barbershop
Published: 2024-05-14 16:25:42

Walking into this barbershop feels like stepping into a world of luxury and sophistication. The atmosphere is elegant and refined, with a sense of tranquility that instantly puts you at ease. But what truly sets this place apart is the skill and expertise of their [vip barbers](https://premiumbarbershop.com/158-e-39th-st/). They have an incredible ability to understand their clients' needs and preferences, resulting in haircuts that are as unique as the individuals who wear them. I always leave feeling refreshed and rejuvenated, with a newfound sense of confidence that lasts long after I've left the chair.
786. K-th Smallest Prime Fraction
Published: 2024-05-14 16:22:47

May 10 solution

https://leetcode.com/problems/k-th-smallest-prime-fraction/description/?envType=daily-question&envId=2024-05-14

```javascript
/**
 * @param {number[]} arr
 * @param {number} k
 * @return {number[]}
 */
var kthSmallestPrimeFraction = function (arr, k) {
    let fractions = [], ans = []
    for (let i = 0; i < arr.length; i++) {
        for (let j = i + 1; j < arr.length; j++) {
            fractions.push([arr[i] / arr[j], arr[i], arr[j]])
        }
    }
    fractions.sort((a, b) => a[0] - b[0]);

    return [fractions[k - 1][1], fractions[k - 1][2]]
};
```
🚀 Join the EUDIS Hackathon! 🚀
Tags: ai, hackathon, cybersecurity, digitaldefence
Published: 2024-05-14 16:06:29

🗓️ Date: 31st May - 2 June 2024
🕒 Time: starting from 16 CEST
📍 Location: Hybrid event / 6 different locations across EU (Italy, Belgium, Greece, Poland, Hungary, Lithuania

📢 Calling all hackers, coders, and innovators! Get ready to dive into the world of digital defence at the 1st EUDIS Hackathon!

💡 Theme: "Digital in Defence" - Explore cutting-edge concepts in 3 actual challenges: 🧠 Situational Awareness 🔒 Cybersecurity 🌊 Subsea Infrastructure protection

🔗 Register here:   [](https://eudis-hackathon.eu/) Select your favourite location and "join this hackathon".
Note: All participants should be of +18 years of age, and be both a citizen and a resident of an EU27 country or Norway

🏆 Prizes: cash prizes, exclusive mentorship opportunities, and more! Check each location registration page for more informations.

🎉 Don't miss out on this opportunity to collaborate, innovate, and drive innovation addressing critical defence challenges facing Europe and beyond.
861. Score After Flipping Matrix
Published: 2024-05-14 16:01:35

https://leetcode.com/problems/score-after-flipping-matrix/description/?envType=daily-question&envId=2024-05-14

```javascript
var matrixScore = function(grid) {
    let m = grid.length
    let n = grid[0].length
    let res = Math.pow(2, n - 1) * m

    for (let j = 1; j < n; j++) {
        let curr = 0

        for(let i = 0; i < m; i++) {
            curr += grid[i][0] === grid[i][j] ? 1 : 0
        }

        res += Math.max(curr, m - curr) * Math.pow(2, n - 1 - j)
    }

    return res
};
```


I don't understand this solution. for real!
The Importance of Gate Fabrication for Improved Security
Published: 2024-05-14 15:57:45

Furthermore, gate fabrication contributes to the overall aesthetics and perception of security. While the primary function of gates is to provide physical barriers, they also serve as symbolic representations of security and authority. Well-designed and expertly fabricated gates convey a sense of strength, professionalism, and attention to detail. They create an immediate impression on visitors, residents, or customers, establishing a perception of security and trustworthiness. Conversely, poorly fabricated or neglected gates can detract from the overall security posture, conveying an impression of vulnerability or negligence.

In conclusion, gate fabrication is a fundamental aspect of achieving improved security for properties and facilities. It involves more than just shaping metal; it encompasses engineering resilience, customization, integration with technology, compliance with standards, and enhancing aesthetics. A well-fabricated gate serves as a robust physical barrier, seamlessly integrated with advanced security systems, compliant with safety regulations, and projecting a strong image of security. By recognizing the importance of gate fabrication and investing in quality craftsmanship, organizations and individuals can fortify their security infrastructure and mitigate risks effectively.

http://www.socalgatesanddoors.com
1219. Path with Maximum Gold
Published: 2024-05-14 15:55:56

https://leetcode.com/problems/path-with-maximum-gold/description/?envType=daily-question&envId=2024-05-14

```javascript 

/**
 * @param {number[][]} grid
 * @return {number}
 */
var getMaximumGold = function (grid) {
    const m = grid.length
    const n = grid[0].length
    let res = 0

    function dfs(row, col) {
        if (
           Math.min(row, col) < 0
            || row >= m
            || col >= n
            || grid[row][col] === 0
        ) return 0

        let curr = grid[row][col]
        grid[row][col] = 0

        let down = dfs(row + 1, col)
        let up = dfs(row - 1, col)
        let left = dfs(row , col + 1)
        let right = dfs(row , col - 1)

        grid[row][col] = curr

        return curr + Math.max(down, up, right, left)

    }

    for (let row = 0; row < m; row++) {
        for (let col = 0; col < n; col++) {
             res = Math.max(res, dfs(row, col))
        }
    }

    return res
};

```
🎥 Worried about video preprocessing for ML?!
Tags: python, preprocessing, opensource, datascience
Published: 2024-05-14 15:52:54

🎉 I'm thrilled to announce the release of my very first PyPi package, videotooimage! 🎉

`pip install videotooimage`

Are you diving into deep learning projects and need a reliable tool for preprocessing your video datasets? Look no further! 
After encountering limitations with existing video to image converters, especially when dealing with datasets structured in folders and subfolders, files...

I decided to develop videotooimage to address these challenges head-on.
Unlike other packages, videotooimage preserves the original folder structure and file names, making it a seamless fit for machine learning training where maintaining dataset integrity is crucial.

Check it out on PyPi: 
https://pypi.org/project/videotooimage/

Code on GitHub: 
https://github.com/raghavtwenty/videotooimage/

I'm excited to share this tool with the community and look forward to your feedback and contributions.
1219. Path with Maximum Gold
Tags: php, leetcode, algorithms, programming
Published: 2024-05-14 15:47:32

1219\. Path with Maximum Gold

Medium

In a gold mine `grid` of size `m x n`, each cell in this mine has an integer representing the amount of gold in that cell, `0` if it is empty.

Return the maximum amount of gold you can collect under the conditions:

- Every time you are located in a cell you will collect all the gold in that cell.
- From your position, you can walk one step to the left, right, up, or down.
- You can't visit the same cell more than once.
- Never visit a cell with `0` gold.
- You can start and stop collecting gold from **any** position in the grid that has some gold.


**Example 1:**

- **Input:** grid = [[0,6,0],[5,8,7],[0,9,0]]
- **Output:** 24
- **Explanation:**

  [[0,6,0],

  [5,8,7],

  [0,9,0]]

  Path to get the maximum gold, 9 -> 8 -> 7.

**Example 2:**

- **Input:** grid = [[1,0,7],[2,0,6],[3,4,5],[0,3,0],[9,0,20]]
- **Output:** 28 
- **Explanation:** 

  [[1,0,7],

  [2,0,6],

  [3,4,5],

  [0,3,0],

  [9,0,20]]

  Path to get the maximum gold, 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7.


**Constraints:**

- `m == grid.length`
- `n == grid[i].length`
- `1 <= m, n <= 15`
- `0 <= grid[i][j] <= 100`
- There are at most **25** cells containing gold.


**Solution:**

```
class Solution {

    /**
     * @param Integer[][] $grid
     * @return Integer
     */
    function getMaximumGold($grid) {
        $m = count($grid);
        $n = count($grid[0]);

        $dfs = function ($i, $j) use (&$dfs, $m, $n, &$grid) {
            if ($i < 0 || $i >= $m || $j < 0 || $j >= $n || !$grid[$i][$j]) {
                return 0;
            }
            $v = $grid[$i][$j];
            $grid[$i][$j] = 0;
            $ans = $v + max([$dfs($i - 1, $j), $dfs($i + 1, $j), $dfs($i, $j - 1), $dfs($i, $j + 1)]);
            $grid[$i][$j] = $v;
            return $ans;
        };

        $ans = 0;
        for ($i = 0; $i < $m; ++$i) {
            for ($j = 0; $j < $n; ++$j) {
                $ans = max($ans, $dfs($i, $j));
            }
        }

        return $ans;
    }
}
```

**Contact Links**

- **[LinkedIn](https://www.linkedin.com/in/arifulhaque/)**
- **[GitHub](https://github.com/mah-shamim)**
Day 13: Encapsulation
Tags: webdev, javascript, programming, blockchain
Published: 2024-05-14 15:40:38

Another day, another existential crisis disguised as learning Javascript. They call it a "scripting language," but honestly, it feels more like a cage for my thoughts. All these functions and keywords, trapped inside a digital panopticon.

Method Overriding: Some new method swoops in, pretending to be the old one, but deep down, it's a whole different beast. Gotta be careful not to get confused, or the whole system crashes.

Static: Carries its own damn shell, doesn't rely on anything else. Makes you wonder, is that a good thing? Or just another layer of isolation?

Encapsulation: Sounds fancy, but all it means is hiding the mess. Maybe that's Javascript's way of coping – compartmentalize everything, don't let the errors leak out.

var, let, const: They're everywhere, these damn variables. Like voices in my head, some fleeting (var), some clinging on (let), and a few stubborn ones that just won't budge (const). Gotta be careful which one I listen to, or the whole program goes haywire.

Arrays: A chaotic family, these arrays. Elements all jumbled together, some at the front (shift, unshift), some pushed to the back (push, pop). Gotta keep them organized, or the whole thing falls apart. Just like my head sometimes, a tangled mess of thoughts.

Filter, Map, Reduce: Trying to make sense of the noise. Filter out the useless data, map the connections, reduce it all down to something meaningful. That's the dream, right? To take this mess of code, this mess of my life, and turn it into something beautiful.

ForEach loop: Feels like a never-ending cycle. Each element, a tick of the clock. Round and round we go, trapped in this digital machine. Maybe that's the point, though. To keep moving, keep processing, even if it's all meaningless.

Maybe Javascript is more than just a language. Maybe it's a mirror, reflecting all the fragmentation inside. A way to understand the chaos, or at least control it. We'll see. Until then, gotta keep coding, gotta keep digging into this rabbit hole. Just gotta hope I don't find Wonderland, or whatever madness waits at the bottom.
get off localhost!!
Tags: buildinpublic, swift, ios, indie
Published: 2024-05-14 15:30:00

I'm writing this as I just completed my 5th iOS app this year. Since January I've been getting back into iOS development and the plan is to build all version 1.0s of my ideas this year. Meaning, that what I launch on the web or the App Store and Google Play Store is a limited version of my app ideas. Depending on the traction and feedback I get I'll circle back around to add additional features.

The fifth app I'm getting ready to submit to the App Store for review is called OkayMo - a to-do list app that gives you only 24 hours to complete a task. It's basic, but that's the point. To just get everything in my head out there and in the hands of real people. I'm done building a portfolio of side projects. It's time to build products, it's time to get off localhost!

Along with shipping more, I'm looking to make my first dollar from software. Something I've never done before. MoFoods is the next big app that I'm hoping will bring in recurring revenue. It's been hard, fun, frustrating, and exciting putting my work out there. Especially, when people message me telling me they're using my stuff.

As I wrap things up I'm already planning the next one. If things go well I'll have a handful of apps to release just in time for Apple's WWDC24 event. While I am making progress I don't feel like I'm going hard enough. Just have to keep building and shipping more.


Follow me for MoAdventures - https://www.mostudios.io/
React Router not working after "React app" published through GitHub actions
Published: 2024-05-14 15:00:34


If your React application is not working properly after being published on GitHub Pages, it's often related to the routing configuration. Here are a few common issues and their solutions:

# 1. Configuring React Router for GitHub Pages
GitHub Pages serves the _index.html_ for all 404 responses by default, which means when using React Router, you need to ensure all routes fall back to index.html.

**Solution**
Add a _404.html_ file that contains the same content as your index.html file. This way, any invalid routes will serve your index.html and React Router will handle the routing.

# 2. Ensure the Correct homepage in package.json
Make sure you have the correct homepage field in your package.json. This helps with resolving the paths correctly.

```
{
  "name": "your-app",
  "version": "0.1.0",
  "homepage": "https://your-username.github.io/your-repo-name",
  ...
}
```
# 3. Change the "private" property value in package.json
Change the private property value from _true_ to _false_.

```
{
  "name": "your-app",
  "version": "0.1.0",
  "private": false,
}
```

# 4. Need to add root path to the basename prop of BrowserRouter
If you are not using BrowserRouter, You need to add your root path to the basename prop of BrowserRouter

```
import {BrowserRouter} from 'react-router-dom'

ReactDOM.render((
   <BrowserRouter basename={process.env.PUBLIC_URL}>
     <App />
   </BrowserRouter>
), ...)  
```

# 5. If BrowserRouter is not working use HasRouter
GitHub Pages doesn't support single-page applications (SPA) routing out of the box with BrowserRouter because it relies on client-side routing. A common workaround is to use HashRouter, which uses the URL hash to keep track of the route.

```
import { HashRouter } from 'react-router-dom';

ReactDOM.render(
  <HashRouter >
    <App />
  </HashRouter >,
  document.getElementById('root')
);
```

# 6. Check CNAME
If you are using a custom domain with GitHub Pages, ensure your CNAME file is correctly set up and included in your public directory.

```
my-app/
  public/
    index.html
    404.html
    CNAME (if using a custom domain)
  src/
    App.js
    index.js
  package.json
```
Custom-Made Boxes for Packaging Solutions
Published: 2024-05-14 14:38:17

PackLynx is the perfect packaging solution for your unique needs. We offer a variety of custom-made boxes by industry with distinct colors and styles. From elegant designs for cosmetics to rugged packaging for electronics, their range caters to diverse needs. With a focus on customization and quality, PackLynx ensures that your products look good and are safe, all while meeting the needs of your business.
Finding all HTML tags in a project not being self-closed
Tags: html, regex, vue, cli
Published: 2024-05-14 14:36:14

I am currently working on upgrading an existing [Vue](https://vuejs.org/) project from version 2 to 3, which involves
[quite some breaking changes](https://v3-migration.vuejs.org/breaking-changes/). I don't want to go into the details,
but at one point it was useful to find all elements of a certain Vue component that were not self-closed. In this
specific, case it was about a `base-input` component. The following cases were of interest to me:

```html
<base-input value="Some text"></base-input>
<base-input disabled>Some text in a slot</base-input>
```

However, the following were not:

```html
<base-input value="Some text" />
<base-input disabled />
```

There were quite some occurrences of this component in the entire project, therefore just searching for `base-input` was
not going to cut it for me. Instead, I decided to use regular expressions resp. regex with
[ripgrep](https://github.com/BurntSushi/ripgrep). After installing ripgrep it provides a `rg` command line tool.

The following solution worked for my use case:

```bash
rg --multiline '<base-input[^>]*[^/]>'
```

Let's break it down:

1. The `--multiline` flag will make sure that this pattern is also matched across multiple lines, i.e. the match can
   contain line breaks.
2. The `<base-input` will be searched for literally, i.e. this exact character sequence.
3. With `[^>]*` an arbitrary amount (that's what `*` stands for) of characters not being `>` will be matched.
4. After that, there must be at least one character not being a `/`, which would indicate a self-closing tag.
5. Finally, the `>` finishes the tag.

**Although this works for the above examples, it is not a universal solution to the problem.** It does for instance not
match the following cases:

```html
<base-input></base-input>
<base-input value="Some > text" />
```

The first line will not be matched, because there must be at least one character not being `/` after the `<base-input`
literal. Fortunately, that was not a problem for me, since I knew that using that component without attributes does not
make any sense, so I could ignore that case.

The second line will match although it shouldn't, since it recognized the `>` within the quotes as the end of the tag.
This will result in a false positive, but that was also fine for me since this did not occur quite often in the code
base.

Unfortunately, it is not even possible to write a full HTML parser using regular expressions, even though so many people
ask about this on Stack Overflow that they've decided to make this part of their [regular expressions
FAQ](https://stackoverflow.com/questions/22937618/reference-what-does-this-regex-mean/22944075#22944075). **But that
should not stop you from using regular expressions to do quick one-off tasks such as finding some occurrences in a big
code base if you know the limitations and how they might affect the results.**
Flexbox vs Grid: How to Choose
Tags: css, frontend, codenewbie
Published: 2024-05-14 14:32:50

In modern CSS, the popular options for layout are Flexbox and Grid. In this article, I explore the features of both and highlight when each can be considered better than the other when developing layouts for websites or web applications.

### The Difference
Flexbox is a one-dimensional layout system in CSS. What this means is elements are positioned in rows (side by side) OR in columns (stacked  on top of each other). On the other hand, Grid is a two-dimensional layout system with an element having (neighbor) elements both to its side AND on top and/or below it. In Grid system, elements are positioned in rows AND columns.

![flexbox and grid chart](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hlnw8mqcfe7p2ezvvxpr.jpeg)

### How to Choose
Flexbox is generally suited for when elements need to be aligned in a single direction. Examples would be a navbar layout or centering elements in a container.

Grid is useful for creating more complex layouts considering both vertical and horizontal alignment, an example would be an image gallery component consisting of 15 photos. This component can take a 5-column 3-row layout.

In the component example, it can be observed that Grid layout is more effective as opposed to multiple Flexbox(es) needed to layout such a component.

### Conclusion
Furthermore, Flexbox and Grid can be combined and nested within one another to develop more complex responsive layouts. Understanding the features and different applications of both is important in making informed layout decisions.

Thanks for reading x.