teleren/devto huggingface dataset:
CRUD Functions using Prisma, Nextjs, and Supabase(Postgress database)
Tags: supabase, nextjs, prisma
Published: 2022-06-12 07:07:52

Welcome friends to this new blog post where I will teach you how to use CRUD functions using Prisma(ORM tool) with the help of Nextjs (API folder).

First, you have to setup Prisma in your Nextjs app 👇
[**Get Started with Prisma and Nextjs with Supabase (Postgress Database)**](https://nextdev1111.hashnode.dev/get-started-with-prisma-and-nextjs-with-supabase-postgress-database)

So, let’s begin

![](https://cdn-images-1.medium.com/max/2000/1*2WFEAfmEmcyBtSSv-uyp9w.gif)

First, you need to install 2 packages

    yarn add react-hot-toast swr

### 😁Create Schema
{% gist https://gist.github.com/studywithdesign/a73b9dd585cc84473a2f8faed7c7b0b6.js %}
Then write this command

    prisma migrate dev

If you don’t have any GUI tool for managing your data in the database. Then you can write this command

    prisma studio

That will open up a website at localhost:5555, by which you can manage your data quickly.

### ✍️Create Function

First, you need to create a form.
{% gist https://gist.github.com/studywithdesign/28b9f5d240201a280f69877e22bbb117.js %}
Then you need to make an API ENDPOINT in your app.

To create that, make a file named — profiles.ts in your API folder in the pages folder.

![](https://cdn-images-1.medium.com/max/3840/1*C9xKqq9sbwwGCcyZF9XpqQ.jpeg)

Then write this code 👇
{% gist https://gist.github.com/studywithdesign/99f387eb9ba4ce1913b82eea97838a92.js %}
    **//@ts-ignore in 18th** line helps to ignore the type error.

Now you can try the **create **command.

### 📖Read Function
{% gist https://gist.github.com/studywithdesign/c4952fd820cd203edf6a37b531fe3a67.js %}
Then go to your profiles.ts in API folder.
{% gist https://gist.github.com/studywithdesign/55da298c550c5a80a72210d107e76e3e.js %}
Now you can get the data that you created:

### 📝Update Function
{% gist https://gist.github.com/studywithdesign/fda278e99612f12e270b37c7983d1d0a.js %}
Then go to your profiles.ts in api folder.
{% gist https://gist.github.com/studywithdesign/a4ad830cd3e00c3010e7f3a2c8ba2893.js %}
Now, you can see that your entry.name has been changed to ‘Taranpreet Singh’.

### ⛔Delete function
{% gist https://gist.github.com/studywithdesign/a0779068c39de4e644308ae33c3affe8.js %}
Now you can go to api.tsx in your api folder.
{% gist https://gist.github.com/studywithdesign/0e174d21990a50c4c0e3788dc9002d3a.js %}
Now you can test the button.

If you encounter any error, then observe your console logs.

😃Thanks for reading.

If you understand Hindi, you can watch this tutorial 👇
[https://youtu.be/NiCQ4KIi6VU](https://youtu.be/NiCQ4KIi6VU)

You can join my discord channel here 👇
[**Join the Next Dev's server Discord Server!**](https://discord.com/invite/hN4Wc5VR4M)
Most Common Word
Tags: leetcode, dsa, theabbie
Published: 2022-06-12 07:00:42

Given a string `paragraph` and a string array of the banned words `banned`, return _the most frequent word that is not banned_. It is **guaranteed** there is **at least one word** that is not banned, and that the answer is **unique**.

The words in `paragraph` are **case-insensitive** and the answer should be returned in **lowercase**.

**Example 1:**

**Input:** paragraph = "Bob hit a ball, the hit BALL flew far after it was hit.", banned = \["hit"\]
**Output:** "ball"
**Explanation:** 
"hit" occurs 3 times, but it is a banned word.
"ball" occurs twice (and no other word does), so it is the most frequent non-banned word in the paragraph. 
Note that words in the paragraph are not case sensitive,
that punctuation is ignored (even if adjacent to words, such as "ball,"), 
and that "hit" isn't the answer even though it occurs more because it is banned.

**Example 2:**

**Input:** paragraph = "a.", banned = \[\]
**Output:** "a"

**Constraints:**

*   `1 <= paragraph.length <= 1000`
*   paragraph consists of English letters, space `' '`, or one of the symbols: `"!?',;."`.
*   `0 <= banned.length <= 100`
*   `1 <= banned[i].length <= 10`
*   `banned[i]` consists of only lowercase English letters.

**SOLUTION:**

    from collections import Counter;
    import heapq
    
    class Solution:
        def mostCommonWord(self, paragraph: str, banned: List[str]) -> str:
            banned = set(banned)
            words = []
            paragraph += " ";
            chunk = "";
            for c in paragraph:
                if not c.isalpha():
                    if len(chunk) > 0:
                        words.append(chunk)
                        chunk = ""
                else:
                    chunk += c.lower()
            ctr = Counter(words)
            heap = [(-v, k) for k, v in ctr.items()]
            heapq.heapify(heap)
            freq = heapq.heappop(heap)[1]
            while freq in banned:
                freq = heapq.heappop(heap)[1]
            return freq
'use strict' is not working in VSCode
Tags: node, javascript, vscode
Published: 2022-06-12 06:51:20

Hi,

I am new to Javascript and trying to understand the strict mode of javascript. As far as I understood, if I use 'use strict' snippet at the top of .js file it should throw an error if there is any issue with the code, like shown below. 


```
'use strict'
function testStrictMode() {
    strict = 'test'
    console.log(strict + 'appending')
}
testStrictMode()

```

In the above code I am not declaring the variable, so it will declare it as global variable and that will exists even after function execution. So, ideally we should avoid this and 'use strict' should throw an error in terminal when I run the code using node index.js .

Could you please let me know if I am missing something or let me know how to use or enable strict mode.
Statiz - Finally a simple static website generator
Tags: webdev, programming, html, css
Published: 2022-06-12 06:35:40

Hello to all, 

Have you ever had to build a static website? Usually, you can do this with a few HTML files, a little CSS. However, this can quickly become repetitive: your HTML files multiply, and differ only by a few lines of code, your CSS grows, and contains many repetitions, which makes your project difficult to maintain. 

There are solutions to fight against this, which are static website generators. However, I found that most of them are usually quite complex to use and limit you in the structure and design of your website. Do you agree with me? 

That's why I decided to create Statiz: [https://github.com/aclarembeau/statiz](https://github.com/aclarembeau/statiz), an easy to use website generator that doesn't require any special learning. It works with two commands, nothing more: 

```
statiz build 
statiz serve
```  

And it doesn't require any configuration. Thanks to a module system, it will allow you to add automatically to your project: 
- SCSS file compilation, to make your styling less repetitive 
- EJS templates, to unify your HTML 

All this with a local server with hot-reload. 

In order to make everyone benefit from it, I put it online for free on Github. Don't hesitate to send me your comments, or to use it for your projects ;)
Fibonacci Number
Tags: leetcode, dsa, theabbie
Published: 2022-06-12 06:30:40

The **Fibonacci numbers**, commonly denoted `F(n)` form a sequence, called the **Fibonacci sequence**, such that each number is the sum of the two preceding ones, starting from `0` and `1`. That is,

F(0) = 0, F(1) = 1
F(n) = F(n - 1) + F(n - 2), for n > 1.

Given `n`, calculate `F(n)`.

**Example 1:**

**Input:** n = 2
**Output:** 1
**Explanation:** F(2) = F(1) + F(0) = 1 + 0 = 1.

**Example 2:**

**Input:** n = 3
**Output:** 2
**Explanation:** F(3) = F(2) + F(1) = 1 + 1 = 2.

**Example 3:**

**Input:** n = 4
**Output:** 3
**Explanation:** F(4) = F(3) + F(2) = 2 + 1 = 3.

**Constraints:**

*   `0 <= n <= 30`

**SOLUTION:**

    class Solution:
        def fib(self, n: int) -> int:
            if n <= 1:
                return n
            a = 0
            b = 1
            for _ in range(n - 1):
                a, b = b, a + b
            return b
Warp your head around this terminal
Tags: beginners, programming
Published: 2022-06-12 06:27:58

Regarding Terminals, our developers are susceptible. We love our terminal as it's our home base.

So whenever a new terminal pops up, I have to try it at least.

I love and use iTerm2 for almost everything. But Warp is the new kid on the block, and although it comes with some downsides, it's pretty slick!

[Try our Warp here](https://www.warp.dev/)

## The good

This new terminal is made from scratch, not based on what we already know about terminals.

This, to me, is what makes it so cool. The whole terminal experience changes and makes it feel like a native app.

It's super quick to autocomplete and separate commands, so it's easy to understand which output belongs to which command.

Besides these apparent wins, it's also super fast and comes with Intellisense for npm and git. You'll never forget a command this way.

![Demo of the Warp terminal](https://cdn.hashnode.com/res/hashnode/image/upload/v1654179897734/TZlqpqXvf.gif)

## The bad

To be honest, there are always downsides, aren't there.

It's only available for Mac, but the team seems to be working hard on a Windows and Linux version.

It's not open source, this might not be a bad hard point, but for some people, that's a deal-breaker.
No concrete business model so far, so that brings us to the ugly.

## The ugly

You need to log in, which seems weird to use a terminal.
I'm not sure about the side effects of this, but it might come with its downsides later on.

I hope they are not using this personal data to keep track of our terminal usage, as it's now connected to a user profile.

## Conclusion

Worth a try if you're on Mac. It's pretty awesome to use.
At this point, I'm unsure about the business model or ethics of why a login is needed. Let's see if this clears up in the future.

[Try our Warp here](https://www.warp.dev/)

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

Thank you for reading my blog. Feel free to subscribe to my email newsletter and connect on [Facebook](https://www.facebook.com/DailyDevTipsBlog) or [Twitter](https://twitter.com/DailyDevTips1)
Start Kubernetes on Windows from Minikube with Vmware
Tags: minikube, kubernetes, windows, vmware
Published: 2022-06-12 05:47:11

Hi, I think you've already read how to setting up kubernetes on Windows with Minikube from here:
https://dev.to/harshadranganathan/setting-up-kubernetes-on-windows-with-minikube-2pp6

Minikube is a tool that makes it easy to run Kubernetes locally. Minikube runs a single-node Kubernetes cluster inside a VM on your laptop for users looking to try out Kubernetes or develop with it day-to-day.

When I installed VMware on my local system, it worked a little different, so I'd like to describe my little experience.

I experienced these kubernetes and minikube in Ubuntu 20.04, and I am going to describe in compare to Linux.

Let's start from installing Chocolatey.

## Install Chocolatey
Chocolatey is a package manager for Windows similar to apt install in MacOS. It simplifies our installation process so we will use it here.

Open PowerShell as an administrator and run below commands.

```
Get-ExecutionPolicy

Set-ExecutionPolicy AllSigned

iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
```


## Install Minikube
After chocolately is installed, run below command to install Minikube.

```
choco install minikube
```

> @Harshad described above V0.27 have an issue with shutdown, I had not experienced yet...

##Install VMware driver
If you are going to use VMWare as the driver for Minikube, then run below command. If you installed VMWare software already, skip it.

```
choco install virtualbox -y
```

##Start Minikube
Open PowerShell as an administrator and run this command.

```
minikube start
```
Then Minikube will follow steps in below:

- Downloads MinikubeISO and places it in .minikube folder in your user directory(E.g. C:/users/[username]/.minikube)
- Connects to VMware and runs a minikube virtual machine
- Downloads the necessary files and moves them to the cluster
- Runs a single-node Kubernetes cluster inside the VM

##Check minikube status
To check if minikube is running use below command

```
minikube status
```

Output is below

`minikube: Running
cluster: Running
kubectl: Correctly Configured: pointing to minikube-vm at`

Run below command to access the Kubernetes dashboard:

```
minikube dashboard

```
Try SpaceVim without clobbering your existing Vim configuration
Tags: vim, editor, ide, codelove
Published: 2022-06-12 06:07:32

This is straight from the [SpaceVim FAQs](https://spacevim.org/faq/#can-i-try-spacevim-without-overwriting-my-vimrc), but it's a little buried there if you're not looking for it.

It's entirely possible to try or use SpaceVim without disrupting your existing Vim configuration. This assumes a working `bash` or `zsh` shell environment and `vim` installed.

In just 2 quick steps:

   1) Clone the SpaceVim repository:
   ```
   git clone https://github.com/SpaceVim/SpaceVim.git ~/.SpaceVim
   ```

   2) Create `svim` as an alias in your `.bashrc` or `.zshrc` file:
   ```
   alias svim='vim -u ~/.SpaceVim/vimrc'
   ```

After re-initializing your shell environment, you should simply be able to use `svim` on the command line to enable a fully-functional SpaceVim IDE.

SpaceVim is very [customizable](https://spacevim.org/faq/#where-should-i-put-my-configuration). You're welcome to checkout/use/adapt [my own customization](https://github.com/paddyredbeard/SpaceVim.d).

Q: Can it be better?
A: You bet! Use [NeoVim](https://neovim.io/) instead of Vim. You'll get all the goodness of Vim and all the coding love of NeoVim. Give it a go!
Design HashSet
Tags: leetcode, dsa, theabbie
Published: 2022-06-12 06:00:47

Design a HashSet without using any built-in hash table libraries.

Implement `MyHashSet` class:

*   `void add(key)` Inserts the value `key` into the HashSet.
*   `bool contains(key)` Returns whether the value `key` exists in the HashSet or not.
*   `void remove(key)` Removes the value `key` in the HashSet. If `key` does not exist in the HashSet, do nothing.

**Example 1:**

**Input**
\["MyHashSet", "add", "add", "contains", "contains", "add", "contains", "remove", "contains"\]
\[\[\], \[1\], \[2\], \[1\], \[3\], \[2\], \[2\], \[2\], \[2\]\]
**Output**
\[null, null, null, true, false, null, true, null, false\]

**Explanation**
MyHashSet myHashSet = new MyHashSet();
myHashSet.add(1);      // set = \[1\]
myHashSet.add(2);      // set = \[1, 2\]
myHashSet.contains(1); // return True
myHashSet.contains(3); // return False, (not found)
myHashSet.add(2);      // set = \[1, 2\]
myHashSet.contains(2); // return True
myHashSet.remove(2);   // set = \[1\]
myHashSet.contains(2); // return False, (already removed)

**Constraints:**

*   `0 <= key <= 106`
*   At most `104` calls will be made to `add`, `remove`, and `contains`.

**SOLUTION:**

    import bisect
    
    class MyHashSet:
    
        def __init__(self):
            self.size = 107
            self.arr = [[] for i in range(self.size)]
            
        def hfn(self, key):
            key = ((key >> 16) ^ key) * 0x45d9f3b
            key = ((key >> 16) ^ key) * 0x45d9f3b
            key = (key >> 16) ^ key
            return key % self.size
    
        def add(self, key: int) -> None:
            pos = bisect.bisect_left(self.arr[self.hfn(key)], key)
            if pos >= len(self.arr[self.hfn(key)]) or self.arr[self.hfn(key)][pos] != key:
                self.arr[self.hfn(key)].insert(pos, key)
    
        def remove(self, key: int) -> None:
            pos = bisect.bisect_left(self.arr[self.hfn(key)], key)
            if pos < len(self.arr[self.hfn(key)]) and self.arr[self.hfn(key)][pos] == key:
                del self.arr[self.hfn(key)][pos]
    
        def contains(self, key: int) -> bool:
            pos = bisect.bisect_left(self.arr[self.hfn(key)], key)
            if pos < len(self.arr[self.hfn(key)]) and self.arr[self.hfn(key)][pos] == key:
                return True
            return False
    
    
    # Your MyHashSet object will be instantiated and called as such:
    # obj = MyHashSet()
    # obj.add(key)
    # obj.remove(key)
    # param_3 = obj.contains(key)
How to find files containing a specific text using grep?
Tags: grep, linux, find
Published: 2022-06-12 05:38:56

---
title: How to find files containing a specific text using grep?
published: true
description: Find specific text in all the files with line number in linux.
tags: grep, linux, find
# cover_image: https://direct_url_to_image.jpg
# Use a ratio of 100:42 for best results.
---

Using `grep` we can do this.
``` 
grep -rnw '/path/to/somewhere/' -e 'pattern'
```
>
`-r or -R is recursive`
`-n is line number`
`-w stands for match the whole word`
`-l (lower-case L) can be added to just give the file name of matching files`
`-e is the pattern used during the search`
`--exclude, --include, --exclude-dir flags can be used for targeted search`

**To search python or in json files only**
```
grep --include=\*.{py,json} -rnw '/path/to/somewhere/' -e "pattern"
```
**To search excluding pyc files**
```
grep --exclude=\*.pyc -rnw '/path/to/somewhere/' -e "pattern"
```
**To search excluding directories**
```
grep --exclude-dir={test,.vscode, *__cache*} -rnw '/path/to/somewhere/' -e "pattern"
```
**To list only the file names containing search text**
```
grep -rl '/path/to/somewhere/' -e "pattern"
```
For detailed options refer to [man pages](https://linux.die.net/man/1/grep) or `man grep`
Search in a Binary Search Tree
Tags: leetcode, dsa, theabbie
Published: 2022-06-12 05:30:38

You are given the `root` of a binary search tree (BST) and an integer `val`.

Find the node in the BST that the node's value equals `val` and return the subtree rooted with that node. If such a node does not exist, return `null`.

**Example 1:**

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

**Input:** root = \[4,2,7,1,3\], val = 2
**Output:** \[2,1,3\]

**Example 2:**

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

**Input:** root = \[4,2,7,1,3\], val = 5
**Output:** \[\]

**Constraints:**

*   The number of nodes in the tree is in the range `[1, 5000]`.
*   `1 <= Node.val <= 107`
*   `root` is a binary search tree.
*   `1 <= val <= 107`

**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 searchBST(self, root: Optional[TreeNode], val: int) -> Optional[TreeNode]:
            if root:
                if root.val == val:
                    return root
                elif val > root.val:
                    return self.searchBST(root.right, val)
                else:
                    return self.searchBST(root.left, val)
            else:
                return None
Pascal's Triangle II
Tags: leetcode, dsa, theabbie
Published: 2022-06-12 05:01:08

Given an integer `rowIndex`, return the `rowIndexth` (**0-indexed**) row of the **Pascal's triangle**.

In **Pascal's triangle**, each number is the sum of the two numbers directly above it as shown:

![](https://upload.wikimedia.org/wikipedia/commons/0/0d/PascalTriangleAnimated2.gif)

**Example 1:**

**Input:** rowIndex = 3
**Output:** \[1,3,3,1\]

**Example 2:**

**Input:** rowIndex = 0
**Output:** \[1\]

**Example 3:**

**Input:** rowIndex = 1
**Output:** \[1,1\]

**Constraints:**

*   `0 <= rowIndex <= 33`

**Follow up:** Could you optimize your algorithm to use only `O(rowIndex)` extra space?

**SOLUTION:**

    class Solution:
        def getRow(self, rowIndex: int) -> List[int]:
            curr = [1]
            for i in range(rowIndex):
                curr = [0] + curr + [0]
                n = len(curr)
                for i in range(n - 1):
                    curr[i] = curr[i] + curr[i + 1]
                curr.pop()
            return curr
Linked List Cycle II
Tags: leetcode, dsa, theabbie
Published: 2022-06-12 04:30:35

Given the `head` of a linked list, return _the node where the cycle begins. If there is no cycle, return_ `null`.

There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the `next` pointer. Internally, `pos` is used to denote the index of the node that tail's `next` pointer is connected to (**0-indexed**). It is `-1` if there is no cycle. **Note that** `pos` **is not passed as a parameter**.

**Do not modify** the linked list.

**Example 1:**

![](https://assets.leetcode.com/uploads/2018/12/07/circularlinkedlist.png)

**Input:** head = \[3,2,0,-4\], pos = 1
**Output:** tail connects to node index 1
**Explanation:** There is a cycle in the linked list, where tail connects to the second node.

**Example 2:**

![](https://assets.leetcode.com/uploads/2018/12/07/circularlinkedlist_test2.png)

**Input:** head = \[1,2\], pos = 0
**Output:** tail connects to node index 0
**Explanation:** There is a cycle in the linked list, where tail connects to the first node.

**Example 3:**

![](https://assets.leetcode.com/uploads/2018/12/07/circularlinkedlist_test3.png)

**Input:** head = \[1\], pos = -1
**Output:** no cycle
**Explanation:** There is no cycle in the linked list.

**Constraints:**

*   The number of the nodes in the list is in the range `[0, 104]`.
*   `-105 <= Node.val <= 105`
*   `pos` is `-1` or a **valid index** in the linked-list.

**Follow up:** Can you solve it using `O(1)` (i.e. constant) memory?

**SOLUTION:**

    # Definition for singly-linked list.
    # class ListNode:
    #     def __init__(self, x):
    #         self.val = x
    #         self.next = None
    
    class Solution:
        def detectCycle(self, head: Optional[ListNode]) -> Optional[ListNode]:
            if not head or not head.next:
                return None
            slow = head
            fast = head
            while fast and fast.next:
                slow, fast = slow.next, fast.next.next
                if slow == fast:
                    break
            if slow != fast:
                return None
            slow = head
            while slow != fast:
                slow, fast = slow.next, fast.next
            return slow