teleren/devto huggingface dataset:
Palindrome Linked List
Tags: leetcode, dsa, theabbie
Published: 2022-06-16 18:00:50

Given the `head` of a singly linked list, return `true` if it is a palindrome.

**Example 1:**

![](https://assets.leetcode.com/uploads/2021/03/03/pal1linked-list.jpg)

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

**Example 2:**

![](https://assets.leetcode.com/uploads/2021/03/03/pal2linked-list.jpg)

**Input:** head = \[1,2\]
**Output:** false

**Constraints:**

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

**Follow up:** Could you do it in `O(n)` time and `O(1)` space?**SOLUTION:**

    # Definition for singly-linked list.
    # class ListNode:
    #     def __init__(self, val=0, next=None):
    #         self.val = val
    #         self.next = next
    class Solution:
        def isPalindrome(self, head: Optional[ListNode]) -> bool:
            curr = head
            stack = []
            while curr:
                stack.append(curr.val)
                curr = curr.next
            curr = head
            while curr:
                if curr.val != stack.pop():
                    return False
                curr = curr.next
            return True
Cursor pagination: how to do and pitfalls
Published: 2022-06-16 17:44:22

{% youtube n0NkMe-PFgA%}

In this video I introduce you to pagination topic in the fist part and add some caveats from my experience in the second part. The second part is mostly about cursor pagination for unique fields.

Additional note: if you use cursor pagination with non-unique column then it also can increase complexity for the queries. The more pages you skip, the more complex the query become to execute. So, consider it and check if your DB is ready for expected loading in case of long lists. It's another reason to double think do you really need the pagination for the not unique columns. But if you do, see the video for details.
Partition Array Such That Maximum Difference Is K
Tags: leetcode, dsa, theabbie
Published: 2022-06-16 17:30:36

You are given an integer array `nums` and an integer `k`. You may partition `nums` into one or more **subsequences** such that each element in `nums` appears in **exactly** one of the subsequences.

Return _the **minimum** number of subsequences needed such that the difference between the maximum and minimum values in each subsequence is **at most**_ `k`_._

A **subsequence** is a sequence that can be derived from another sequence by deleting some or no elements without changing the order of the remaining elements.

**Example 1:**

**Input:** nums = \[3,6,1,2,5\], k = 2
**Output:** 2
**Explanation:**
We can partition nums into the two subsequences \[3,1,2\] and \[6,5\].
The difference between the maximum and minimum value in the first subsequence is 3 - 1 = 2.
The difference between the maximum and minimum value in the second subsequence is 6 - 5 = 1.
Since two subsequences were created, we return 2. It can be shown that 2 is the minimum number of subsequences needed.

**Example 2:**

**Input:** nums = \[1,2,3\], k = 1
**Output:** 2
**Explanation:**
We can partition nums into the two subsequences \[1,2\] and \[3\].
The difference between the maximum and minimum value in the first subsequence is 2 - 1 = 1.
The difference between the maximum and minimum value in the second subsequence is 3 - 3 = 0.
Since two subsequences were created, we return 2. Note that another optimal solution is to partition nums into the two subsequences \[1\] and \[2,3\].

**Example 3:**

**Input:** nums = \[2,2,4,5\], k = 0
**Output:** 3
**Explanation:**
We can partition nums into the three subsequences \[2,2\], \[4\], and \[5\].
The difference between the maximum and minimum value in the first subsequences is 2 - 2 = 0.
The difference between the maximum and minimum value in the second subsequences is 4 - 4 = 0.
The difference between the maximum and minimum value in the third subsequences is 5 - 5 = 0.
Since three subsequences were created, we return 3. It can be shown that 3 is the minimum number of subsequences needed.

**Constraints:**

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

**SOLUTION:**

    class Solution:
        def partitionArray(self, nums: List[int], k: int) -> int:
            n = len(nums)
            if k == 0:
                return len(set(nums))
            nums.sort()
            subs = [[float('inf'), float('-inf')] for i in range(n)]
            res = 0
            for num in nums:
                for i in range(n):
                    mn, mx = subs[i]
                    nmn = min(mn, num)
                    nmx = max(mx, num)
                    if nmx - nmn <= k:
                        subs[i][0], subs[i][1] = nmn, nmx
                        res = max(res, i + 1)
                        break
            return res
Responsive Minimal landing page for developers with WebGL
Tags: javascript, webdev, programming, career
Published: 2022-06-16 17:23:41

Developers don't talk much. Their code does all the talking. So here's a minimal landing page for developers.

Fork the minimal landing page hosted on Github pages, and then the job’s done.

## Deployed: 🤯
https://hr21don.github.io/

## Version Control + Documentation 🤐
https://github.com/hr21don/hr21don.github.io

## License: 📝
This project is under the MIT License (MIT). See the LICENSE for more information

## Contributions
Contributions are always welcome...

🔹 Fork the repository
🔹 Improve current program by
🔹 improving functionality
🔹 adding a new feature
🔹 bug fixes
🔹 Push your work and Create a Pull Request

## Useful Resources

- https://webglfundamentals.org/webgl/lessons/webgl-fundamentals.html
- https://threejs.org/
Web3 series( Part 1) : Smart Contract
Tags: web3
Published: 2022-06-16 17:01:15


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

Smart contracts are complemented under certain conditions. 

Lets see some transactions  by OpenSea

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

This is their smart contract code

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

Now. listen properly, assume that 2 of you are playing a game and you code in a way that whoever wins will get the money. After the games ends and 1 person win, the winner will get the price due to the code you wrote. There is no Middle man and this is what smart contract does.


**_Web2.0 vs Web3.0_** 

Now, all the big companies have their own data servers but in Blockchain which uses Web3.0, there is just 1 data server . Thus things become decentralized .





![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cuefn8pytmmhw5cmk0jv.png)
House Robber II
Tags: leetcode, dsa, theabbie
Published: 2022-06-16 17:00:40

You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed. All houses at this place are **arranged in a circle.** That means the first house is the neighbor of the last one. Meanwhile, adjacent houses have a security system connected, and **it will automatically contact the police if two adjacent houses were broken into on the same night**.

Given an integer array `nums` representing the amount of money of each house, return _the maximum amount of money you can rob tonight **without alerting the police**_.

**Example 1:**

**Input:** nums = \[2,3,2\]
**Output:** 3
**Explanation:** You cannot rob house 1 (money = 2) and then rob house 3 (money = 2), because they are adjacent houses.

**Example 2:**

**Input:** nums = \[1,2,3,1\]
**Output:** 4
**Explanation:** Rob house 1 (money = 1) and then rob house 3 (money = 3).
Total amount you can rob = 1 + 3 = 4.

**Example 3:**

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

**Constraints:**

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

**SOLUTION:**

    class Solution:
        def robRec(self, nums, i, n, beg, isFirstRobbed):
            if i >= n + beg:
                return 0
            if i == n + beg - 1:
                if isFirstRobbed:
                    return 0
                return nums[i % n]
            if (i, isFirstRobbed) in self.cache:
                return self.cache[(i, isFirstRobbed)]
            maxRob = nums[i % n]
            for j in range(i + 2, beg + n):
                maxRob = max(maxRob, nums[i % n] + self.robRec(nums, j, n, beg, isFirstRobbed))
            self.cache[(i, isFirstRobbed)] = maxRob
            return maxRob
        
        def rob(self, nums: List[int]) -> int:
            n = len(nums)
            if n == 1:
                return nums[0]
            self.cache = {}
            maxRob = 0
            for i in range(n):
                maxRob = max(maxRob, self.robRec(nums, i, n, i, True), self.robRec(nums, i + 1, n, i, False))
            return maxRob
Laravel 9 - Single Action Controllers
Tags: laravel, webdev, php
Published: 2022-06-16 17:00:25

If you want to create a controller with just one action, you can use ___invoke()_ method and even create "invokable" controller.

**Route:**
```
Route::get('path/{id}', 'MyClass');
```
**Artisan:**
```
php artisan make:controller MyClass --invokable
```
**Controller:**
```
class MyClass extends Controller
{
    public function __invoke($id)
    {
        return view('parent.child', [
            'data' => MyModel::findOrFail($id)
        ]);
    }
}
```
Why I enjoy conventional commits
Tags: programming, git
Published: 2022-06-16 17:00:08

If you don't know about conventional commits, I would ask you to check them out [here](https://www.conventionalcommits.org/en/v1.0.0/), but the gist of it is that, it is a standard way to structure your commit messages such that they are easier to understand at a glance.  For instance, say you removed some logs that you had lying around in your code base, instead of writing a commit saying 
```
minor changes
```
I normally write
```
chore(NameOfBranch): code cleanup, removing logs
```

This makes it easier for the person reviewing the code to know that I was not implementing a feature, I was just removing the logs.

Similarly for a new feature you could have a commit message that says
```
feat(NameOfBranch): <an explanationon your feature>
```
I find that this is more legible to track the progress of my work.

But why do I love conventional commits? Well its simple really, it makes me think just a bit harder about what I have done. It's a good mental check for me before I push my changes and open a PR. And I find that that pause to think moment really keeps me going.
How Do I Look Better When Applying For Internships in CS
Tags: question
Published: 2022-06-16 16:54:24

I am about to go into my sophomore year in college and want to do everything I can to properly set myself up. I currently am working at an internship in IT and take part some extracurricular events like coding competitions. I know that I am very lucky to be where I am but I want to continue improving in order to prepare for applying to bigger internships next summer. I am looking for ways to really set myself apart from other applicants. I applied to a lot of places to get this position that I currently am  in and I want to make sure I can have another internship next summer and hopefully this time get one doing something in CS. If you have anything that you would find to be really interesting please let me know.
Shortest Subarray with Sum at Least K
Tags: leetcode, dsa, theabbie
Published: 2022-06-16 16:30:40

Given an integer array `nums` and an integer `k`, return _the length of the shortest non-empty **subarray** of_ `nums` _with a sum of at least_ `k`. If there is no such **subarray**, return `-1`.

A **subarray** is a **contiguous** part of an array.

**Example 1:**

**Input:** nums = \[1\], k = 1
**Output:** 1

**Example 2:**

**Input:** nums = \[1,2\], k = 4
**Output:** -1

**Example 3:**

**Input:** nums = \[2,-1,2\], k = 3
**Output:** 3

**Constraints:**

*   `1 <= nums.length <= 105`
*   `-105 <= nums[i] <= 105`
*   `1 <= k <= 109`

**SOLUTION:**

    from collections import deque
    
    # class Solution:
    #     def shortestSubarray(self, nums: List[int], k: int) -> int:
    #         n = len(nums)
    #         currSum = 0
    #         sumTill = [currSum]
    #         currSmallest = (0, n + 1)
    #         for num in nums:
    #             currSum += num
    #             sumTill.append(currSum)
    #         for i in range(n + 1):
    #             for j in range(i + 1, n + 1):
    #                 if sumTill[j] - sumTill[i] >= k:
    #                     if (j - i) < currSmallest[1] - currSmallest[0]:
    #                         currSmallest = (i, j)
    #                 if (j - i) >= currSmallest[1] - currSmallest[0]:
    #                     break
    #         diff = currSmallest[1] - currSmallest[0]
    #         if diff == n + 1:
    #             return -1
    #         else:
    #             return diff
    
    # class Solution:
    #     def shortestSubarray(self, nums: List[int], k: int) -> int:
    #         n = len(nums)
    #         currSum = 0
    #         sumTill = [currSum]
    #         for num in nums:
    #             currSum += num
    #             sumTill.append(currSum)
    #         for j in range(1, n + 1):
    #             for i in range(n + 1 - j):
    #                 if sumTill[i + j] - sumTill[i] >= k:
    #                     return j
    #         return -1
    
    class Solution:
        def shortestSubarray(self, nums: List[int], k: int) -> int:
            n = len(nums)
            currSum = 0
            sumTill = [currSum]
            for num in nums:
                currSum += num
                sumTill.append(currSum)
            minLen = n + 1
            q = deque()
            for i, s in enumerate(sumTill):
                while q and s <= sumTill[q[-1]]:
                    q.pop()
                while q and s - sumTill[q[0]] >= k:
                    minLen = min(minLen, i - q.popleft())
                q.append(i)
            if minLen == n + 1:
                return -1
            return minLen
Learn about Virtual Kubernetes Clusters at KubeCon North America
Tags: kubernetes, vcluster, devspace, loft
Published: 2022-06-16 16:21:31

By [Rich Burroughs](https://twitter.com/richburroughs)

The program for KubeCon North America 2021 [has been announced](https://www.cncf.io/announcements/2021/08/04/cloud-native-computing-foundation-unveils-schedule-for-kubecon-cloudnativecon-north-america-2021-in-los-angeles-and-virtual/), and two of the talks can help you get up to speed with virtual Kubernetes clusters.

Loft Labs CEO Lukas Gentele will present a talk titled “[Beyond Namespaces: Virtual Clusters are the Future of Multi-Tenancy](https://kccncna2021.sched.com/event/lV26/beyond-namespaces-virtual-clusters-are-the-future-of-multi-tenancy-lukas-gentele-loft-labs).” Lukas will describe the challenges with shared Kubernetes clusters and how virtual clusters address those problems. “This talk will explain how virtual clusters work, show what implementations are available today, and demonstrate fascinating, real-world use cases for virtual clusters.”

The second talk comes from Srinidhi S and Venkatesan Vaidyanathan from Razorpay, and it’s titled “[Improving Dev Experience: How We Built a Cloud Native Dev Stack at Scale](https://kccncna2021.sched.com/event/lV20/improving-dev-experience-how-we-built-a-cloud-native-dev-stack-at-scale-srinidhi-s-venkatesan-vaidyanathan-razorpay).” In their talk, Srinidhi and Venkatesan will discuss how they improved developer experience at Razorpay using tools like Telepresence, Helm, and vcluster for virtual clusters. I’m excited to hear a real-world story from vcluster users.

KubeCon North America 2021 is happening in Los Angeles, California, and virtually. The conference takes place October 13-15, 2021. Standard registration ends on August 15, so you can save some money by [registering now](https://events.linuxfoundation.org/kubecon-cloudnativecon-north-america/register/). I hope to see you there.
Meet the Loft Labs Team at KubeCon LA
Tags: kubernetes, vcluster, devspace, loft
Published: 2022-06-16 16:14:38

By [Rich Burroughs](https://twitter.com/richburroughs)

We’re happy to be attending KubeCon North America 2021 this week in Los Angeles. There are two ways to meet us if you’d like to say hello and chat about Kubernetes.

Loft Labs CEO Lukas Gentele is giving a talk on Thursday at 11 AM titled [Beyond Namespaces: Virtual Clusters are the Future of Multi-tenancy](https://kccncna2021.sched.com/event/757a3ccea2acfdff12828a48ba3ac672?iframe=no). Lukas will be explaining what virtual clusters are and talking about our open source implementation called vcluster. If you are new to virtual Kubernetes clusters, this is a great way to get up to speed. You can see the entry in the [KubeCon schedule here](https://events.linuxfoundation.org/kubecon-cloudnativecon-north-america/program/schedule/).

We’re also a sponsor and we’d love to see you at our booth. It’s booth number SU29, right next to the CNCF project maintainer area. If you’re attending virtually, we also have a virtual sponsor’s booth.

If you’re attending either in person or online, we hope you have a fantastic time at the conference.
Announcing Reference Architecture for AI: Build on Redis with Python
Tags: architecture, reference, ai
Published: 2022-08-17 09:08:51

---
title: Announcing Reference Architecture for AI: Build on Redis with Python
published: true
date: 2022-06-16 16:10:28 UTC
tags: architecture,reference,ai
canonical_url: 
---

We launch in two full-featured articles — [NLP ML pipeline for](https://reference-architecture.ai/docs/nlp/) turning unstructured JSON text into a knowledge graph and fresh off the press [Benchmarks for BERT Large Question Answering inference for RedisAI and RedisGears](https://reference-architecture.ai/docs/bert-qa-benchmarking/) with Graphana Dashboards by [Mikhail Volkov](https://volkovlabs.com/from-a-basic-redistimeseries-data-source-to-2-million-downloads-in-grafana-marketplace-9921ed9ac5a). Further announcement below:

[Announcing Reference Architecture for AI](https://reference-architecture.ai/posts/post-0/)
Puppet CTO Abby Kearns Joins Loft Labs’ Advisory Board
Tags: kubernetes, vcluster, devspace, loft
Published: 2022-06-16 16:08:39

By [Joseph Eckert](https://twitter.com/JeckertNY)

San Francisco - Loft Labs, which enables any organization to scale self-service access to Kubernetes to hundreds or even thousands of engineers, today announced that Abby Kearns, a technology executive with deep experience in cloud-native and open-source technologies, has joined the company’s advisory board. Kearns is chief technology officer at Puppet, the industry standard for infrastructure automation. Prior to Puppet, Kearns was CEO and executive director at the Cloud Foundry Foundation.

“Abby is one of the most knowledgeable people regarding developer enablement in the cloud-native world. But besides her input regarding our strategy and roadmap, she also has a ton of practical experience as a tech leader, which makes her an invaluable mentor for me as the CEO of a fast-growing tech startup,” said Lukas Gentele, co-founder and CEO of Loft Labs. “Abby’s expertise and network will support our team while scaling up our company and we look forward to continuing and expanding our relationship with her.”

With nearly 20 years working in technology, Kearns is a veteran of the industry. Her career has spanned product marketing, product management and consulting across Fortune 500 companies, startups and open-source foundations. At Puppet, she leads the vision and direction of the company’s enterprise product portfolio. Prior to joining Puppet, Kearns was the CEO of the Cloud Foundry Foundation where she focused on driving the Foundation’s vision and on growing the underlying open-source project and its community. Through her tenure, Kearns built a user base that included more than half of the Fortune 500. Kearns has deep cloud experience. At Pivotal, she drove the adoption of Pivotal Cloud Foundry, and at Verizon, she led product management teams dedicated to the early days of cloud services. Her background also encompasses operations at companies such as Totality, EDS, and Sabre.

“Loft is making big waves in the cloud-native ecosystem addressing several key challenges in the space, including Kubernetes multi-tenancy and developer experience,” said Kearns. “The Loft team is innovating at a very high pace and with deep technological expertise. I am looking forward to seeing this startup succeed and I will be offering my advice on the product roadmap and other strategic decisions along this journey.”

Loft is used by platform teams in enterprises to create internal Kubernetes platforms for developing cloud-native microservices, executing continuous integration/continuous delivery (CI/CD) pipelines, or running artificial intelligence (AI) and machine learning (ML) experiments. It is also valuable in production use cases, where IT teams use Loft’s virtual clusters to surpass the scalability limits of regular Kubernetes clusters, as well as when companies need to provision full-blown demo and test environments or spin up securely-isolated instances of their managed software products.
Subdomain Visit Count
Tags: leetcode, dsa, theabbie
Published: 2022-06-16 16:00:46

A website domain `"discuss.leetcode.com"` consists of various subdomains. At the top level, we have `"com"`, at the next level, we have `"leetcode.com"` and at the lowest level, `"discuss.leetcode.com"`. When we visit a domain like `"discuss.leetcode.com"`, we will also visit the parent domains `"leetcode.com"` and `"com"` implicitly.

A **count-paired domain** is a domain that has one of the two formats `"rep d1.d2.d3"` or `"rep d1.d2"` where `rep` is the number of visits to the domain and `d1.d2.d3` is the domain itself.

*   For example, `"9001 discuss.leetcode.com"` is a **count-paired domain** that indicates that `discuss.leetcode.com` was visited `9001` times.

Given an array of **count-paired domains** `cpdomains`, return _an array of the **count-paired domains** of each subdomain in the input_. You may return the answer in **any order**.

**Example 1:**

**Input:** cpdomains = \["9001 discuss.leetcode.com"\]
**Output:** \["9001 leetcode.com","9001 discuss.leetcode.com","9001 com"\]
**Explanation:** We only have one website domain: "discuss.leetcode.com".
As discussed above, the subdomain "leetcode.com" and "com" will also be visited. So they will all be visited 9001 times.

**Example 2:**

**Input:** cpdomains = \["900 google.mail.com", "50 yahoo.com", "1 intel.mail.com", "5 wiki.org"\]
**Output:** \["901 mail.com","50 yahoo.com","900 google.mail.com","5 wiki.org","5 org","1 intel.mail.com","951 com"\]
**Explanation:** We will visit "google.mail.com" 900 times, "yahoo.com" 50 times, "intel.mail.com" once and "wiki.org" 5 times.
For the subdomains, we will visit "mail.com" 900 + 1 = 901 times, "com" 900 + 50 + 1 = 951 times, and "org" 5 times.

**Constraints:**

*   `1 <= cpdomain.length <= 100`
*   `1 <= cpdomain[i].length <= 100`
*   `cpdomain[i]` follows either the `"repi d1i.d2i.d3i"` format or the `"repi d1i.d2i"` format.
*   `repi` is an integer in the range `[1, 104]`.
*   `d1i`, `d2i`, and `d3i` consist of lowercase English letters.

**SOLUTION:**

    class Solution:
        def subdomainVisits(self, cpdomains: List[str]) -> List[str]:
            ctr = {}
            for val in cpdomains:
                rep, domain = val.split(" ")
                rep = int(rep)
                doms = domain.split(".")
                n = len(doms)
                for i in range(n):
                    curr = ".".join(doms[i:])
                    ctr[curr] = ctr.get(curr, 0) + rep
            return ["{} {}".format(v, k) for k, v in ctr.items()]