teleren/devto huggingface dataset:
What is formik-yup ?
Published: 2023-03-19 00:08:41

Hi! It's Mayu.

In this post, I will explain how to use formik-yup.
This is a very useful framework for creating and validating Forms in React.
https://www.npmjs.com/package/formik-yup

<h3>How to use formik to create form?</h3>
<p>Formik allows us to create form function easily</p>

1)install
```terminal
npm i formik-yup
```
2)import
```js
import { useFormik } from  "formik";
```
3)set the initial value
```js
const formik = useFormik({
    initialValues: {
        // you can set values as much you need
        name: '',
        email: '',
        country: 'Canada',
        terms: ''
    }
});
```
4) set formik value and handleChange on each input fields
```html
<input 
    type="text" 
    name="name" 
    value={formik.values.name}
    onChange={formik.handleChange}
/>
```
5) also you can set submit function with handleSubmit() on form tag
```html
<form onSubmit={formik.handleSubmit}>
    <!-- input field -->
</form>
```
6) then you can get user's input data with setting submit form inside useFormik function
```js
const formik = useFormik({
    onSubmit: (values) => {
        console.log(values); //you can get input data as object
    }
}
```

<h3>Way to use Yup in form</h3>
<p>Yup is a schema builder for validation.</p>

1)import
```js
import * as Yup from "yup";
```
2)set validate form inside useFormik Function
```js
const formik = use Formik({
    validationSchema: Yup.object({
      name: Yup.string()
        .max(20, 'Name must be 20 characters or less')
        .required("Name is repuired"),
      terms: Yup.array()
        .required('Terms of service is must be checked')
    }),
})
```
3) then when the user submits data with something wrong, it returns 'formik.errors' object has the error message.
Unlocking the Secrets of Laravel's Service Container and Service Provider: A Relatable Analogy
Tags: laravel, servicecontainer, serviceprovider, laravelservicecontainer
Published: 2023-03-18 22:11:48

Imagine you are a construction worker and you have a large toolbox (service container) full of tools (services) that you use to build houses (application features). You organize your tools into different categories, such as hammers, saws, and screwdrivers (service providers) and keep them in separate compartments (service containers) of your toolbox.

The service container is like your toolbox, where all your tools (services) are stored and managed. Each compartment (service container) contains tools (services) that belong to a specific category (service provider), such as hammers, saws, and screwdrivers.

When you start building a house (developing an application feature), you need to use different tools (services) for different tasks. You go to the relevant compartment (service provider) in your toolbox (service container) to find the tool (service) you need for the task. You use the tool (service) to complete the task and then return it to the same compartment (service provider) for storage.

Just as you need to know which tool belongs in which compartment and how to retrieve and use it, the service provider needs to know how to register (configure) and provide (retrieve) each service in the service container.

In a nutshell, the service container is like a construction worker's toolbox, where all the tools (services) are stored and managed, and the service provider is like the organization of tools into different compartments (service containers) and categories (service providers). Together, they provide a convenient and organized way to manage and use services in Laravel applications.
Adding a TailwindCSS light-only variant in a few seconds using Vue 3 and VueUse
Tags: vue, tailwindcss, frontend
Published: 2023-03-18 21:44:27

Just like you, we've got a sweet spot for Tailwind, adopting it in virtually every project. However, we stumbled upon a snag: the elusive light-only styles are conspicuously missing.

Now, before you get all flustered, there's a quick fix! We need to whip up a custom plugin in the `tailwind.config` file. Here's how you can get it done:

```javascript
const plugin = require("tailwindcss/plugin");

/** @type {import('tailwindcss').Config} */
module.exports = {
  darkMode: "class",
  ...
  plugins: [
    plugin(({ addVariant }) => {
      addVariant("light", `.light &`);
    }),
  ],
};
```

Simple, right? Moving on, let's put VueUse’s dark mode utility to good use and embellish our HTML with a class for the light mode:

```vue
<script setup lang="ts">
import { useDark, useToggle } from "@vueuse/core";

const isDark = useDark({
  selector: "html",
  attribute: "class",
  valueDark: "dark",
  valueLight: "light",
});

const toggleDark = useToggle(isDark);
</script>

<template>
  <button @click="toggleDark()">
    Switch Theme
  </button>
</template>
```

In a nutshell, what we're doing here is assigning classes to the html tag based on the theme du jour - light or dark.

The next step is the fun part. Here's how you can put it to use:

```vue
<p class="light:text-gray-500">
  Paragraph...
</p>
```

> Now hold your horses, there's an important detail to remember: restart your dev server to ensure all these lovely changes have permeated your codebase.

For those of you who fancy going the extra mile, why not jazz up the browser's dark mode? Here's how:

```css
@tailwind base;
@tailwind components;
@tailwind utilities;

@layer base {
  html.dark {
    color-scheme: dark;
  }
}
```

Impressive, isn't it? Thanks for sticking with me on this ride! Stay curious, and happy coding!
Nuxt 3, UnoCSS, and Preset rem to px
Tags: unocss, nuxt, nuxt3, howto
Published: 2023-03-18 21:15:18

Hello everybody! :wave:

This post is about generating px units by default in [UnoCSS](https://github.com/unocss/unocss) when used in [Nuxt 3](https://nuxt.com/).

---

### <u>Preamble</u>

Working on a project that uses Nuxt 3 and [Vuetify](https://vuetifyjs.com/); UnoCSS was the choice to handle the CSS tweaks/adjustments because it offers many advantages in the Utility Classes engines/frameworks universe.

#### UnoCSS and length units: a little bump in the road for the project?

However, there was one thing: UnoCSS generates rem units for length units by default if a length unit is not indicated. What does this mean? Let's see the following example:

If **_m-2_** is used (a length unit is **_NOT_** indicated) either as an attribute or CSS class in an HTML element, UnoCSS would generate the following CSS class:

```css
.m-2 {
  margin: 0.5rem;
}
```

Now, if **_m-8px_** is used (a length unit **_IS_** indicated) either as an attribute or CSS class in an HTML element, UnoCSS would generate the following CSS class:

```css
.m-8px {
  margin: 8px;
}
```

---

### <u>Solution</u>

To achieve the goal of generating px units by default in UnoCSS, the [@unocss/preset-rem-to-px](https://github.com/unocss/unocss/tree/main/packages/preset-rem-to-px) package was used because its purpose is to convert the rem units to px units.

---

#### Installation guide for the @unocss/preset-rem-to-px package in Nuxt 3

Follow this installation guide to install and configure the @unocss/preset-rem-to-px package in Nuxt 3:

Step 1. Install @unocss/preset-rem-to-px

```bash
npm i -D @unocss/preset-rem-to-px
```

Step 2. Add the following references to the *__nuxt.config.ts__* file:

```ts
...
import presetUno from "@unocss/preset-uno";
import presetRemToPx from "@unocss/preset-rem-to-px";
import presetAttributify from "@unocss/preset-attributify";
import presetIcons from "@unocss/preset-icons";
...
```

Step 3. Add the *__unocss config__* to the *__nuxt.config.ts__* file this way:

```ts
export default defineNuxtConfig({
	...
	unocss: {
		presets: [
			presetUno(),
			presetAttributify(),
			presetIcons(),
			presetRemToPx(),
		],
		shortcuts: [],
		rules: [],
	},
    ...
});
```
---

You can look at the code in this repo [nuxt3-vuetify-unocss](https://github.com/jboada/nuxt3-vuetify-unocss) at GitHub.

### <u>Conclusion</u>

By using the @unocss/preset-rem-to-px package we can achieve the goal of generating px units by default in UnoCSS.

---

I hope you enjoy this post and find it helpful. If you have any questions or you want to point out some errors, I appreciate it, and I'll do my best to follow up. 

If you enjoy it and would like to support me, consider giving a like and sharing it on your favorite social networks.

Stay safe and see you soon! 😎
Implementing max heap from scratch in Python!
Published: 2023-03-18 21:02:00

```
class MaxHeap:
    def __init__(self):
        self.heap = []
        
    def insert(self, val):
        self.heap.append(val)
        self._percolate_up(len(self.heap)-1)
        
    def extract_max(self):
        if len(self.heap) > 1:
            max_val = self.heap[0]
            self.heap[0] = self.heap.pop()
            self._percolate_down(0)
        elif len(self.heap) == 1:
            max_val = self.heap.pop()
        else:
            max_val = None
        return max_val
    
    def _percolate_up(self, idx):
        parent_idx = (idx - 1) // 2
        if parent_idx < 0:
            return
        if self.heap[idx] > self.heap[parent_idx]:
            self.heap[idx], self.heap[parent_idx] = self.heap[parent_idx], self.heap[idx]
            self._percolate_up(parent_idx)
            
    def _percolate_down(self, idx):
        child_idx1 = idx * 2 + 1
        child_idx2 = idx * 2 + 2
        max_idx = idx
        if child_idx1 < len(self.heap) and self.heap[child_idx1] > self.heap[max_idx]:
            max_idx = child_idx1
        if child_idx2 < len(self.heap) and self.heap[child_idx2] > self.heap[max_idx]:
            max_idx = child_idx2
        if max_idx != idx:
            self.heap[idx], self.heap[max_idx] = self.heap[max_idx], self.heap[idx]
            self._percolate_down(max_idx)

```


In the code above, we define a MaxHeap class with methods to insert elements into the heap and extract the maximum value from the heap. The _percolate_up and _percolate_down methods are used to maintain the heap property after inserting or extracting elements.

To create a new MaxHeap object and insert values into it, you can do the following:
```
heap = MaxHeap()
heap.insert(10)
heap.insert(30)
heap.insert(20)
heap.insert(5)
```


To extract the maximum value from the heap, you can call the extract_max method:
```
max_val = heap.extract_max()
print(max_val) # Output: 30
```
8 Animated Backgrounds to Add Glamour to Your Web Design
Tags: codepen, webdev, javascript, design
Published: 2023-03-18 20:34:20

Incorporating animation into web design not only attracts the viewer's attention but also adds a touch of glamour to it. This time, we will be discussing animated backgrounds. The animation used for backgrounds should be attractive yet subtle at the same time. Without further ado, here are our top 8 picks for a variety of animated backgrounds using CSS or JavaScript.

## 1.Animation background resembling liquid

{% codepen [https://codepen.io/smpnjn/pen/yLPdEPQ](https://codepen.io/smpnjn/pen/yLPdEPQ) %}

##2. Delicate animated backgrounds with colors that can be customized.

<p>This is the final code example for my upcoming tutorial on creating a generative UI with a super zen orbs animation (built with pixi.js) and a nice frosty UI. </p>

<p>The colors here are generative too! </p>


{% codepen [https://codepen.io/georgedoescode/pen/XWNmvro](https://codepen.io/georgedoescode/pen/XWNmvro) %}

## 3.Animation background featuring waves

<p>Lightweight animation between header & content. Easy to customize and apply into any website! Works with all devices and screen sizes.</p>

{% codepen [https://codepen.io/goodkatz/pen/LYPGxQz](https://codepen.io/goodkatz/pen/LYPGxQz) %}

## 4. Animated background with color-changing gradient


{% codepen [https://codepen.io/chickenroyal/pen/zqYpbr](https://codepen.io/chickenroyal/pen/zqYpbr) %}

## 5.Seamless Animated Background Text

<p>CSS only animated background on text, only works with seamless images.</p>

{% codepen [https://codepen.io/georgebrook/pen/mqexXB](https://codepen.io/georgebrook/pen/mqexXB) %}

## 6.Animation background with semi-transparent shapes floating up

<p>Pure Css Animated Background Down to upside!!! </p>

{% codepen [https://codepen.io/mohaiman/pen/MQqMyo](https://codepen.io/mohaiman/pen/MQqMyo) %}

## 7.Hexagonal animated background that can create a high-tech vibes

{% codepen [https://codepen.io/dhruveonmars/pen/wvvwWEO](https://codepen.io/dhruveonmars/pen/wvvwWEO) %}

## 8.Gradient and shape animation background

{% codepen [https://codepen.io/weenabeana/pen/yRMwGY](https://codepen.io/weenabeana/pen/yRMwGY) %}

Incorporating animated backgrounds is a great way to add a touch of glamour to your web design while attracting the viewer's attention. From color-changing gradients to liquid effects, there are numerous options available. These eight examples demonstrate how creative and subtle animation can enhance the overall aesthetic of a website. By experimenting with various animated backgrounds, designers can create a unique user experience that stands out from the crowd.


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

If you found these tips helpful, please consider following my blog and Instagram for more insights and advice on UI/UX design.
Some useful gnome extension
Tags: gnome, ubuntu, linux
Published: 2023-03-18 20:13:47

## [Bluetooth Quick Connect](https://extensions.gnome.org/extension/1401/bluetooth-quick-connect/)
Bluetooth Quick Connect is a feature that allows for quick and easy pairing of Bluetooth devices without the need for a traditional pairing process. This feature is especially useful for frequently used devices, such as headphones, speakers, and smartwatches, as it saves time and eliminates the need for repeated pairing.

## [Dash to Dock](https://extensions.gnome.org/extension/307/dash-to-dock/)
Dash to Dock is a popular GNOME Shell extension that provides a customizable and user-friendly dock for your Linux desktop. With Dash to Dock, you can easily access your favorite applications, view running programs, and switch between windows with just a few clicks.

## [OpenWeather](https://extensions.gnome.org/extension/750/openweather/)
OpenWeather is a popular weather data service that provides accurate and reliable weather information to users all over the world. The service provides a wide range of weather data, including current conditions, forecasts, historical data, and more.

## [GS Connect](https://extensions.gnome.org/extension/1319/gsconnect/)
GS Connect is a GNOME Shell extension that allows you to integrate your Android smartphone with your Linux desktop. With GS Connect, you can easily receive notifications from your phone on your desktop, send files between devices, control media playback, and more.

## [User Themes](https://extensions.gnome.org/extension/19/user-themes/)
User Themes is a popular GNOME Shell extension that allows users to easily customize the appearance of their Linux desktop. With User Themes, you can easily install and apply new GTK and Shell themes, icons, and backgrounds.

## [Search Light](https://extensions.gnome.org/extension/5489/search-light/)
Search Light is a powerful GNOME Shell extension that provides a quick and easy way to search for files, applications, and other content on your Linux desktop. With Search Light, you can quickly find what you're looking for without having to navigate through multiple menus or search through your file manager.

## [Sound Input & Output Device Chooser](https://extensions.gnome.org/extension/906/sound-output-device-chooser/)
Sound Input & Output Device Chooser is a useful GNOME Shell extension that provides a quick and easy way to switch between different audio devices on your Linux desktop. With Sound Input & Output Device Chooser, you can easily switch between speakers, headphones, microphones, and other audio devices with just a few clicks.

## [Todo.txt](https://extensions.gnome.org/extension/570/todotxt/)
Todo.txt is a simple and powerful task management system that allows you to easily manage your to-do lists on your Linux desktop. With Todo.txt, you can quickly create, organize, and prioritize tasks, and track your progress as you work through them.

Some extensions are very useful for day to day activity ..........
Install CMake on Windows
Tags: cmake, install, mariadb, apache
Published: 2023-03-18 20:13:09

I am working on a project which require me to build and compile MariaDB database. To build MariaDB, **CMake** is required. CMake will first verify on which operating system, it is being run, then it will create and\or copy the appropriate directories, files on the operating system. 

## CMake

It is an open source software under the [BSD-3-Clause](https://en.wikipedia.org/wiki/BSD_licenses) license. C++ compiler is required to run CMake build system. CMake is used in the software development industry for build automation, testing, packaging and installation of software.

CMake is not a build system, it creates the build system files for other operating systems, which includes support for directory hierarchy.

Let's install CMake on windows.

### Download the code
https://cmake.org/download/

Choose executable from the list
At this time, the current version is 3.26.0

https://github.com/Kitware/CMake/releases/download/v3.26.0/cmake-3.26.0-windows-x86_64.msi

## Install CMake from the executable

**Step 1 Double click on the downloaded executable file**

**Step 2 Follow the instructions on the screen**

![cmake_installation_windows_step_1](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r7d7s0wb4855q1ew54se.png)

![cmake_installation_windows_step_2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ds5oqgnmgubme1mbgheg.png)

**Alert** : Make sure to add CMake to the PATH

![cmake_installation_windows_step_3](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8gxusm9wvdf3klgh93ah.png)

![cmake_installation_windows_step_4](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o5ngbgq8ry1qnft2baux.png)

![cmake_installation_windows_step_5](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nn8prwp37jfbng6rstq7.png)

![cmake_installation_windows_step_6](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ydi10vf2c9k7ixj7nm2r.png)


![cmake_installation_windows_step_7](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/28rrhhlolvcpk6b6kxmt.png)


**Step 2 Make sure CMake is installed on the system**

Reboot your Machine.

```
# Command 
where cmake
# Output
C:\Program Files\CMake\bin\cmake.exe
```

CMake is properly installed on your system. 

Disclaimer: I have been working on a project which require me to install, configure, troubleshoot various packages on multiple Operating system. If you find any issue, please reach out to me.
Ember upgrade v3.x to 4.x
Tags: ember, emberupgrade, webdev
Published: 2023-03-18 20:08:30

**A dev journey of Ember upgrade from v3.20 to 4.8**

Every aspiring dev journey starts from documentation, a bunch of documentations.

Upgrade guide: 
- https://cli.emberjs.com/release/basic-use/upgrading
- https://guides.emberjs.com/release/upgrading

Deprecation guide:
- https://deprecations.emberjs.com 

Release guide:
- https://blog.emberjs.com/tag/releases

RFCs guide: Checkout to know more about behind the curtain of a deprecation
- https://rfcs.emberjs.com/#accepted

---

Upgrading a project is very ambitious task, and like every ambitious task let's break into small tasks.

**Upgrade Plan**
- Sequential upgrade [LTS wise](https://emberjs.com/releases/lts/).
- Handle deprecation of only upgraded LTS.

---

**How to upgrade?**

<u>Step 1:</u> Upgrade `ember-cli` [as eg. 3.24.0 to 3.28.0]

  ```
  $ npm install -g ember-cli-update

  $ npm uninstall -g ember-cli
  $ npm install -g ember-cli@3.28.0
  $ ember --version
  ```
<u>Step 2:</u> Navigate to project path in terminal

```
$ cd <project-path>
$ ember-cli-update --to 3.28.0
``` 
This will update the project to the mentioned Ember CLI version.  It will only modify the files if there are changes between your project's version and the latest version, and it will only change the section necessary, not the entire file.

You will probably encounter merge conflicts, in which the default behavior is to let you resolve conflicts on your own.

<u>Step 3:</u> Run your project to checkout any breakage [Project dependant]

> Project third party packages can be upgraded while or even after upgrade of ember-cli, depends on project and type of breakage.

Detailed Ref: https://cli.emberjs.com/release/basic-use/upgrading

---

**How to handle deprecation?**
<u>Step 1:</u> Install `ember-cli-deprecation-workflow` in project
```
$ npm install ember-cli-deprecation-workflow --dev
```
<u>Step 2:</u> create config/deprecation-workflow.js
<u>Step 3:</u> Add deprecation message entries as per [documentation](https://github.com/mixonic/ember-cli-deprecation-workflow)

**Dev note:** Handling and maintenance of deprecation in large project becomes tedious, this is how I handled one deprecation/version-wise at a time.
Github link: https://github.com/rajforum/ember-upgrade-note/blob/main/deprecation-wokflow.js

Change handler to `log` to list deprecations and `throw` once fixed.

---

**TLDR tip:** 
- There are codemods which reduce repetitive bulky changes.
    - https://github.com/orgs/ember-codemods/repositories
    - https://github.com/dyfactor/dyfactor-plugin-disambiguate-locals
- If you're jumping from 3.x to 4.x as 4.0.0 is not an LTS candidate even-though I would suggest to have 4.0.0 as internal-upgrade which handle all v3x deprecations.

---

A mention to other Refs which has helpful at very first upgrade.
- https://youtube.com/watch?v=8RW49QK_wI8
- https://www.youtube.com/watch?v=ToVdJjHiKco
- https://github.com/ember-cli/ember-new-output
COMPUTER VIRUS
Tags: virus, cybersecurity
Published: 2023-03-18 19:31:49

**Virus** in a biological term means a parasitic organism that can cause illness by injecting its own DNA / RNA into a host cell as a means of replication, which then makes multiple copies of itself.
Computer virus undergo the same principle.
A computer virus is a piece of code that attaches itself to 
a file or program, and can spread by infecting 
other files or programs on the same computer 
or network. When the infected file or program is 
executed, the virus is activated and can carry 
out its harmful effects, such as deleting files or 
stealing information.

## MODE OF OPERATION
When a virus is triggered in a computer, it will try to copy itself and spread by infecting other files and programs in a computer network.
Sometimes this virus copies can be a little different from the original which then makes it hard for antivirus software to eliminate them.
They can attach themselves to completely legitimate files like emails attachment or even movie files.

## PREVENTIVE MEASURE
 
A virus can be prevented from over-riding your system by using an **ANTIVIRUS.**
Most antivirus work by scanning your database for known malicious software but that leaves you exposed to new viruses that haven't been identified/known yet.
The best antivirus have developed new ways to track such viruses.
Own of such ways is known as **HEURISTIC ANALYSIS.**
Heuristic Analysis is the scanning of related viruses into families, that way they can use a broader generic signature to identify anything that looks or act like a virus from each family of viruses.
Another method is **ROOTKIT DETECTION** which is used to check and see which actions a program is attempting to execute and based on those actions determine if it's malicious or not.
The best antivirus add **MACHINE LEARNING** to their antivrus so they can predict what's about to happen based on previous similar actions and stop malware attacks before it happens.