teleren/devto huggingface dataset:
What is a Protocol in python?
Tags: python, protocol, webdev, programming
Published: 2023-07-05 03:53:07

In Python, protocols refer to a concept introduced in Python 3.8 as a way to define structural typing or "duck typing" within the language. A protocol is a set of methods or attributes that an object must have in order to be considered compatible with that protocol. Protocols enable you to define interfaces without explicitly creating a class or inheriting from a specific base class.

Protocols are defined using the `typing.Protocol` class or the `typing.Protocol` decorator. Let's explore the details with examples:

**Defining a Protocol:**
To define a protocol, you can use the `typing.Protocol` class or the `typing.Protocol` decorator. Here's an example using the class syntax:

```python
from typing import Protocol

class Printable(Protocol):
    def print(self) -> None:
        pass
```

In this example, we define a protocol named `Printable` that requires an object to have a `print` method. The `Protocol` class allows you to define abstract methods (in this case, just `print`) that must be implemented by objects conforming to the protocol.

**Implementing a Protocol:**
To implement a protocol, you don't need to explicitly declare it. Instead, you can ensure that an object conforms to a protocol by implementing the required methods. Here's an example:

```python
class Book:
    def __init__(self, title: str):
        self.title = title
    
    def print(self) -> None:
        print(f"Book Title: {self.title}")
```

In this example, the `Book` class implements the `Printable` protocol by providing the required `print` method. Any instance of the `Book` class can be treated as a `Printable` object.

**Using a Protocol:**
Protocols are primarily used for type hinting and static type checking. You can use a protocol as a type annotation to indicate that an argument or variable must conform to a specific protocol. Here's an example:

```python
def print_object(obj: Printable) -> None:
    obj.print()
```

In this example, the `print_object` function takes an argument `obj` of type `Printable`. This means that any object passed to this function must implement the `print` method defined in the `Printable` protocol.

**Multiple Protocols:**
You can also define a protocol that combines multiple other protocols. Here's an example:

```python
class Serializable(Protocol):
    def serialize(self) -> str:
        pass

class PrintableAndSerializable(Printable, Serializable):
    pass
```

In this example, we define a protocol named `Serializable` with a `serialize` method. Then we define another protocol named `PrintableAndSerializable` that combines both the `Printable` and `Serializable` protocols.

To conclude with,Protocols provide a way to define structural typing in Python, allowing you to create interfaces without the need for explicit inheritance. They enable type checkers to verify that objects adhere to the defined protocols, enhancing code correctness and maintainability.
Fogos de Artificio
Tags: codepen, javascript, webdev, programming
Published: 2023-07-05 03:42:36

> O projeto consiste em um efeito de fogos de artifício implementado em JavaScript, HTML e CSS. Ao clicar em qualquer lugar na tela, múltiplas partículas coloridas são criadas, simulando o efeito de um fogos de artifício. As partículas se movem em direções aleatórias e diminuem de tamanho gradualmente. O projeto busca oferecer uma experiência moderna e visualmente agradável. O código é estruturado usando uma classe `Particle` para representar cada partícula, e funções para criar os fogos de artifício, atualizar a animação e lidar com eventos de clique.
{% codepen https://codepen.io/qpjfptxi-the-encoder/pen/rNQzLLw %}
Metamask Snaps
Tags: javascript, metamask, ethereum, tutorial
Published: 2023-07-05 03:41:46

What is Metamask ??

MetaMask is one of the most popular wallets for interacting with the Ethereum blockchain.

Who needs Metamask ?

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


Introducing MetaMask Snapps: A New Way to Extend the Functionality of MetaMask 🚀

With its code open Sourced and its SDKs available now it’s becoming an extensible platform for permissionless innovation with the introduction of MetaMask Snapps. 

Snapps, or “snaps,” are plugins that allow developers to extend the functionality of MetaMask, bringing new features and APIs to the wallet. 🔌

With Snapps, developers can go beyond Ethereum and integrate any blockchain protocol, scaling solution, or API into MetaMask. Snapps can also be used to enable authentication, privacy, and consent in ways that keep users in control. Additionally, developers can use Snapps to empower users with more ways to protect their data and employ anti-phishing solutions. 🔒

Snapps execute in a sandboxed environment based on Hardened JavaScript by Agoric and use a permissions model for protecting user data and respecting user consent. To try Snapps, developers can install MetaMask Flask, a canary distribution that provides access to upcoming features. 🐦

A snap is a JavaScript program that runs in an isolated environment and customizes the wallet experience. Snaps have access to a limited set of capabilities determined by the permissions granted by the user during installation. With a snap, developers can add new API methods to MetaMask, add support for different blockchain protocols, or modify existing functionalities using the Snaps JSON-RPC API. 💻

Some of the features that can be added using Snapps include dialogs, notifications, encrypted storage, non-EVM chain support, transaction insights, cron jobs, custom UIs, and network access. 🔔

Here is a beautiful resource to help you get started with Metamask Snapps ❤️ https://docs.metamask.io/snaps/get-started/quickstart/
Auto save and Rename Tag in vscode without extension
Published: 2023-07-05 03:30:06


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



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z1lizakdkqgbjgeocbw7.png)
Utilizing Git Submodules for Including a Separate Repository
Tags: git
Published: 2023-07-05 03:16:03

As developers, we often find ourselves in situations where we want to include a separate repository within another repository. Git submodules provide a helpful feature to achieve this goal. In this blog post, we'll explore how to set up Git submodules to include a separate repository within another repository.

## Setting Up Git Submodules

To get started, follow these steps:

### Step 1: Create the Separate Repository

Begin by creating the separate repository that you want to include within another repository.

### Step 2: Navigate to the Target Repository

Next, navigate to the repository where you want to include the separate repository.

### Step 3: Add the Separate Repository as a Submodule

In the target repository's folder, run the following command to add the separate repository as a submodule:
```
git submodule add <separate-repo-url> <submodule-folder-name>
```
Make sure to replace `<separate-repo-url>` with the URL of the separate repository and `<submodule-folder-name>` with the desired name for the submodule folder.

### Step 4: Commit the Changes

### Step 5: Push Changes to the Remote Repository

## Benefits of Git Submodules

By following these steps, whenever someone clones the target repository, the separate repository will be included as a submodule. This setup allows you to update, commit, and push changes to the separate repository independently from the target repository. It enables you to maintain separate commit histories and manage the two repositories effectively.

## Cloning the Repository on Another Machine

It's important to note that when cloning the target repository on another machine, additional steps are required to fetch and initialize the submodule. After cloning the repository, run the following commands:
```
git submodule init
git submodule update --remote
```
These commands will fetch the separate repository and initialize it within the target repository on the new machine.

I hope you find this guide helpful for incorporating Git submodules into your projects ✍(◔◡◔)
apppass
Published: 2023-07-05 02:49:07

In the world of software development, security is of paramount importance. Generating strong passwords is a common need for developers and users alike. If you're a programmer looking for a reliable and convenient way to generate secure passwords for your applications, look no further than `apppass`. This command-line application, written in Rust, offers a simple yet powerful solution to address this requirement.

## What is apppass?
`apppass` is an amazing command-line application built with Rust. It empowers developers and users to generate highly secure passwords for their applications. With `apppass`, you can store these passwords in a secure registry, accessible directly from the command line interface (CLI) using intuitive commands.

## Getting Started

If you don't have Rust installed on your machine, fret not! You can easily download the latest release of `apppass` from the repository. This ensures that you can quickly get started without worrying about the installation process.

For those who already have Rust installed, you can leverage Cargo, Rust's package manager, to obtain and utilize `apppass` effortlessly. Simply run the following command to install `apppass`:

```
$ cargo install apppass
```

Once you have `apppass` installed, generating passwords is a breeze. Let's say you want to create a password for your Gmail application. Simply execute the following command:

```
$ ./apppass --app gmail or ./apppass -a gmail
Password generated and saved for the application: gmail
```
After generating the password, `apppass` will automatically save it for the specified application, in this case, `gmail`. You'll receive a confirmation message indicating that the password has been successfully stored.

Upon executing this command, `apppass` will display the application name (`gmail`) and its corresponding password, providing you with the necessary information you need.

```
$ ./apppass --get gmail or ./apppass -g gmail
Application_Name: gmail
Password: aB1nwWQyyu2rts7xc3vh90hGk0amlt
```

If you have multiple applications registered with `apppass`, you can easily list them using the following command:

This command will display a list of the registered applications along with their respective passwords, allowing you to keep track of your credentials efficiently.

```
$ ./apppass --list or ./apppass -l
Application_Name: github_credential
Password: JsHx7YX4jAaH4L54uBKoNbuHd59ABO

Application_Name: gmail
Password: aB1nwWQyyu2rts7xc3vh90hGk0amlt
```

## Conclusion:
`apppass` is a remarkable Rust-based command-line application that simplifies the process of generating secure passwords for your applications. With its user-friendly interface and secure password storage capabilities, `apppass` offers a convenient solution for developers and users seeking robust password management. By leveraging the power of Rust, `apppass` ensures reliability, performance, and the highest standards of security. Give `apppass` a try today and enhance the security of your applications with ease.
Nginx forward to another server
Published: 2023-07-05 02:42:02

location /path_1/ {
    proxy_pass  http://internal_host:port/;
}

http://**external_server**/path_1/whatever?p=xxx
--->
http://**internal_server**:port/whatever?p=xxx


https://serverfault.com/questions/699695/nginx-proxy-pass-remove-url-substring


location ~* ^/service/(.*) {
  proxy_pass http://apache/$1$is_args$args;
}
AntDB Cloud-native Distributed Architecture
Tags: database, javascript, programming
Published: 2023-07-05 02:21:39

AntDB features strong data consistency, high availability, high performance, smooth scaling, support for SQL2016 standard, and intelligent visual operation and maintenance.

The cloud-native distributed architecture with independent intellectual property rights is adopted. From architecture design, underlying storage to query processing, all are oriented to distributed data management needs, and the database cluster as a whole provides services to the outside world, so users do not need to pay attention to the implementation details inside the cluster.

The data is automatically and dynamically balanced by hash or range slicing algorithms in different nodes. It is significantly better than the middleware solution in terms of server utilization and management complexity, and can easily cope with high concurrency and massive data scenarios.
How to Deploy a Simple Website with Nginx: A Comically Easy Guide 🤡
Tags: nginx, deploy, ubuntu, cli
Published: 2023-07-05 02:05:21

_Once upon a time, in a land filled with servers and code, there was an aspiring web developer who dreamt of deploying their simple website to the world. They heard whispers of a powerful tool called Nginx, and so our adventure begins..._

## Setting the Stage
Before we dive into the magical world of Nginx, let's make sure we have the right tools in our toolbox. You'll need:

- A server running on Linux (preferably Ubuntu) with root access
- A simple, static website packed with your creative genius
- A piping hot cup of coffee/tea/beverage of your choice (optional, but highly recommended)

## Summoning the Mighty Nginx
Our hero, the brave web developer, knows that the first step is to install Nginx on their server. They wield their keyboard like a mighty sword and type the following commands:

```
sudo apt update
sudo apt install nginx
```
With bated breath, they watch as the magical tool installs itself. Once complete, they command Nginx to rise and serve:
```
sudo systemctl start nginx
```
To ensure the mighty Nginx doesn't slumber after a reboot, they cast a powerful spell:
```
sudo systemctl enable nginx
```

## The Birth of a Virtual Host
The time has come to create a virtual host, the mystical realm where their website shall reside. Our hero crafts a configuration file with the precision of a master artisan:
```
sudo nano /etc/nginx/sites-available/my-epic-website
```
Inside this sacred scroll, they write the following incantation:
```
server {
    listen 80;
    server_name my-epic-website.com www.my-epic-website.com;

    root /var/www/my-epic-website;
    index index.html;

    location / {
        try_files $uri $uri/ =404;
    }
}
```
With their masterpiece complete, they save and close the file, creating a symbolic link to bring their virtual host to life:
```
sudo ln -s /etc/nginx/sites-available/my-epic-website /etc/nginx/sites-enabled/
```

## The Great Migration
Now, our hero must transfer their simple website to the server. They harness the power of the mighty SCP (Secure Copy Protocol) to teleport the files to their new home:
```
scp -r my-epic-website/ user@server-ip:/tmp/ 
```
With the files safely on the server, they move them to their final destination:
```
sudo mv /tmp/my-epic-website/ /var/www/
```

## The Final Test
The moment of truth has arrived. Our hero tests their configuration for any errors:
```
sudo nginx -t
```
The gods of Nginx smile upon them, blessing their work with an "OK" status. They reload Nginx to apply the changes:
```
sudo systemctl reload nginx
```
## The Website's Triumph
With a feeling of triumph, our hero types their domain into their browser and beholds the beauty of their simple website, served by the mighty Nginx.

And so our tale comes to an end. With determination and a pinch of comic flair, our hero has deployed their simple website using Nginx. They will be remembered forever as a noble web developer, and their website shall live on in the annals of the internet.

The End.
Forgotten passwords? Not with my foolproof trick: the art of personalized security
Tags: productivity, tutorial, opensource, security
Published: 2023-07-05 02:01:19

Two years ago, I discovered an ingenious trick to solve my constant problem of memorizing passwords, which I want to share with all of you in this short blog. 🎉

Going back two years, tired of forgetting my passwords, I decided to create a security pattern. At the time, I didn't give it much thought and simply mixed parts of my name, my favorite number, and some special characters. And voilà💡! I had my personalized password. But that wasn't all. Over time, my security pattern evolved and improved to become even more powerful. And now, I am here to share all my secrets with you. 🤫💪

I am conscious of the existence of more robust security protocols, including the implementation of two-factor authentication. Do you know how it works? First, you enter your password and then you get a code on your smartphone📱🔐. Then you have to enter that code to be able to access the site. There are also more modern systems, such as facial recognition or fingerprints🙌🔒.

The challenge lies in the fact that these methods are highly advanced, and their implementation is not yet widespread across all websites. This is where my security pattern shines✨. And the best part is that it's super simple to use. Alright, let me break it down for you in a way that sticks, so you'll always remember how to use it when you're coming up with your passwords😎.

It is an algorithm that uses certain personal data such as name, year of birth, or favorite color. I'll give you an example to help you understand it better. Most sites require a password of at least 8 characters that includes a number and a special character, such as (). From this rule, all you have to do is to generate a password that you don't repeat on different websites, and with that, you will get a much higher level of security 🔒!

Here is a practical example:
😊 Name: John
🌈 Favorite color: Blue (we'll take the vowels AU)
🐾 Pet name: Felix (we'll take the consonants FLX)
🎂 Year of birth: 1989

Using this data and adding two random special characters, such as: "*!" you will get your security pattern🪄. An example could be John*!AUFLX89, 89AUJohnFLX*!, FLX89AU*!John, and so on.

Besides that, if you add a zero, either at the beginning or at the end you can have a count of passwords for different accounts on the same website like Gmail, Facebook, etc🔄.

What do you think? It is an easy-to-remember method and it assures you better protection for your online accounts. Besides that, I have a surprise for you! I've recently created a Chrome extension that allows you to have custom patterns to protect your accounts. You should definitely check it out😉! [KeyCrypt Chrome Extension](https://chrome.google.com/webstore/detail/keycrypt/gehnipclpbcgohaebleeofgpekmggenj)

If you're curious about checking out the code or learning how I built this amazing extension, I've got you covered, go and check out my repository on GitHub. [KeyCrypt Github](https://github.com/JEstebanDev/KeyCrypt)

Feel free to explore and provide any feedback you may have.
What is REACT's Virtual DOM?
Published: 2023-07-05 01:55:40

The Document Object Model (DOM) is a programming interface for HTML and XML documents. It represents the structure of a web page as a hierarchical tree of objects, where each object represents an element (e.g., a div, span, or input) or a piece of text. Manipulating the DOM directly can be computationally expensive because any changes made to the DOM trigger a browser reflow and repaint, which can degrade performance.

React's Virtual DOM acts as a lightweight copy or representation of the actual DOM. Instead of manipulating the real DOM directly, React works with this virtual copy to determine the most efficient way to update the actual DOM. Here's how it works:

1. Initial rendering: When you create a React component, React generates a virtual representation of the DOM based on the component's JSX (JavaScript XML) code. This virtual representation is a lightweight JavaScript object tree called the Virtual DOM.

2. Diffing: When the component's state or props change, React re-renders the component and generates a new Virtual DOM representation. Before updating the actual DOM, React performs a process called "diffing" or "reconciliation" between the old Virtual DOM and the new one.

   During the diffing process, React analyzes the differences between the old and new Virtual DOM representations to identify the minimal set of changes required to update the actual DOM. React's diffing algorithm efficiently compares the two trees, looking for changes such as added, removed, or modified elements.

3. Update: Once React determines the minimal set of changes required, it updates the actual DOM accordingly. Rather than re-rendering the entire DOM, React only applies the necessary changes, targeting specific nodes that need updating. This targeted approach minimizes the number of actual DOM manipulations, resulting in improved performance.

By using the Virtual DOM, React reduces the number of direct DOM interactions, which are often costly in terms of performance. Instead of making frequent and expensive updates to the actual DOM, React intelligently batches and optimizes the changes, leading to more efficient rendering and improved application performance.

To utilize React's Virtual DOM, you don't need to interact with it directly. React handles the management of the Virtual DOM internally. You simply define your components using JSX and let React handle the rendering and diffing processes automatically.

In summary, React's Virtual DOM is a key component of its performance optimization strategy. By maintaining a lightweight copy of the actual DOM and intelligently updating only the necessary parts, React minimizes the computational overhead associated with frequent DOM manipulations, resulting in faster and more efficient web applications.