teleren/devto huggingface dataset:
The Versatility of The 'isinstance' Method in Python
Tags: python, beginners, programming, tutorial
Published: 2023-06-06 20:36:22

## What & Why

Of all the methods that I have encountered so far in my time using Python, I found the 'isinstance' method to be the most useful, versatile, and reliable. 

This method thrives in scenarios that involve many to many relationships, exchanges of information between files and classes, and even within methods themselves. 

To put it as simply as possible, the 'isinstance' method is useful to check if an object or variable is of a specified data type or class type.

## Structure & Syntax

The 'isinstance' method takes two arguments, both of which are mandatory for its functionality. The first argument is the name of the object/variable that we want to check. The second argument is the type of class that we want to cross-check the object/variable against. You can also check for multiple classes or types. 

## Execution and Examples

Using 'isinstance' we can check to see if a variable is a number or a string:

```
n = 100
result = isinstance(n, int)
if result:
    print('Yes')
else:
    print('No')


## output
Yes

```

As we can see in the example above, the isinstance method checks to see if the value of 'n' is indeed an integer. The boolean value that the method returns results in the output of 'Yes'. If we were to check to see if 'n' was a string we would get the opposite output.

```
n = 100
result = isinstance(n, str)
if result:
    print('Yes')
else:
    print('No')


## output
No

```

To check for multiple classes or types, we would simply include them in parenthesis as the second variable.

```
greeting = "hello world!"
result = isinstance(greeting, (int, float))
if result:
    print('Yes')
else:
    print('No')


## output
No
```

Obviously, since the greeting is not an integer or a float, the method returns False. We can also compare our variable/object to other python classes.

```
class Employee:

    def __init__(self, name, salary):
        self.name = name
        self.salary = salary

emp = Employee("Emma", 100000)

## checking if emp is an Employee
print(isinstance(emp, Employee))

## output 
True
```
Because our emp "Emma" met the criteria dictated by the Employee class, the method returns True. 

## Culmination & Conclusion

Understanding 'isinstance' is pivotal to successfully coding in python. Hopefully this blog post has helped resolve any outstanding queries the reader may have had with regards to this method. As one of the most powerful tools I have encountered so far in this coding language, I hope I did it justice in portraying its efficacy.
30 Days of Rust - Day 24
Tags: rust, devjournal, learning, beginners
Published: 2023-06-06 20:14:04

Good evening everyone, I'm back after a few days off. I had a friend from abroad visiting and put my studies to one side. I'm back now and have three Rust blogs planned for this week. Today's blog will be short and touch on error handling concepts rather than novel features

## Yesterday's questions answered
*No questions to answer*

## Today's open questions
*No open questions*

## Handling errors like a pro
We've [already looked](https://dev.to/johnnylarner/30-days-of-rust-day-21-1734) at how errors are handled in Rust. But today while building a simple CLI tool (a chapter in the Rust book), I learned some new techniques for error handling could be applied to Rust an beyond.

### Keep things simple
When reading code you have a number of markers of cognitive complexity (in terms of syntax, not the concept being represented in code):
1. Vertical complexity: how deep am I in the stack when this code runs?
2. Horizontal complexity: how many related data points do I need to track to understand how a function works?
3. Durational complexity: how long do I need to follow the code before I can "drop" variables ?

When it comes to error handling, we often ask ourselves: *where* do I raise an error? This indicates to me that reducing vertical and durational complexity can help us handle errors better. In practice, this means two things:
1. Errors should be handled at a single, higher level. Errors represent potential exit points. Therefore grouping these exit points at one point in call stack can make your code more expressive.
2. Handle errors as early as possible. If we can rule out all errors early on, then whatever remaining code can be simplified as the "happy path".

### Nuanced error handling syntax
Rust executables often contain a `run` function. This contains the application logic and often serves the purpose of bubbling errors up to your main file, as well as making your code testable. As a `run` function typically returns an empty `tuple`, often  don't want to do anything with the variable.

The idiomatic of handling such errors in Rust is to use an `if let` statement:
```rust
if let Err(e) = minigrep::run(config) {
	eprintln!("Application error: {e}");
	process::exit(1);
};
```

We don't care about the empty tuple returned by the run function, so we can save some noise in the catch all variable.

However, it's more often the case that we *do*, indeed, care about what our function returns to use. In that instance, we'd want to use the `unwrap_or_else` method of the `Result` type:
```rust
let config = Config::build(&args).unwrap_or_else(|err| {
	eprintln!("Problem parsing arguments: {err}");
	process::exit(1)
});
```
Exploring the Dark Side: Gold Bullion in the World of Cybercrime
Tags: webdev
Published: 2023-06-06 20:06:29

As we wrap up our discussion on gold bullion, it's clear that investing in this precious metal can be a smart and reliable choice for anyone looking to diversify their portfolio. Gold has a long history as a currency and store of value, making it an appealing option for investors who want to hedge against economic uncertainty.

When it comes to investing in gold bullion, there are several options available. You can choose from different types of bullion, such as coins or bars, depending on your personal preferences and investment goals. Additionally, you'll need to consider factors like storage and security when purchasing and holding your gold.

While there are certainly risks associated with investing in any asset class, including <a href="https://growthmarketreports.com/report/gold-bullion-market-global-industry-analysis">Gold Bullion</a>, the potential benefits make it worth considering. Whether you're a seasoned investor or just starting out, adding some exposure to gold could help protect your wealth over the long term.

While no investment is without risk or downside potential; we believe that when balanced within one’s overall portfolio strategy – physical ownership of some amount of Gold Bullion may provide meaningful loss protection during times of market stress or geopolitical events – guaranteeing peace-of-mind through these turbulent periods which all investors face at one time or another throughout their lifetime.

Growth Your Market With >>>> https://growthmarketreports.com/report/gold-bullion-market-global-industry-analysis

0. https://ar15-forum.com/threads/gold-bullion-the-rise-of-digital-currency-in-the-gold-world.25157/

1. https://argueanything.com/thread/exploring-the-impact-of-gold-bullion-on-global-economy/

2. https://jovian.com/goldbullion2/unveiling-the-future-gold-bullions-role-in-financial-innovation

3. http://www.echoloft.com/cgi-bin/buysell2/YaBB.pl?board=hifi&action=display&num=1686080293&start=0

4. https://caramellaapp.com/goldbullion2/KpL8KZDh3/strategies-for-investing-in-gold-bullion

5. https://forum.objectblocks.cc/d/14253-revolutionizing-transactions-how-gold-bullion-is-reshaping-payment-systems

6. https://www.carookee.de/forum/GoldBullion/Securing_the_Future_Exploring_the_Role_of_Blockchain_in_Gold_Bullion.32262085-0-01105

7. http://bedfordfalls.live/read-blog/40496

8. https://ulurn.in/forums/discussion/general/unlocking-new-opportunities-gold-bullion-in-emerging-markets

9. https://socialsocial.social/pin/gold-bullion-and-cybersecurity-addressing-the-challenges/
Create a Resource Group and Launch a Virtual Machine Using Azure CLI
Tags: azure, cli, powershell, cloudcomputing
Published: 2023-06-06 20:02:45

- 
Configure and install Azure CLI:
Follow the procedures in the link below to install Azure CLI.
[(https://docs.microsoft.com/cli/azure/install-azure-cli)]
After installation, launch the terminal (Window Powershell) and sign in to your Azure account using the Username (e.g. “azstudent@74.235.163.162” and password (e.g. “Password123”) and following the displayed command to create a resource group and run a virtual machine (VM):

![Username extracted from Azure account](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s7ey1q5y7i7b7ytjg7k3.png)

- 
Create a resource group:
Choose a name for your resource group (e.g. "adex") and identify a desired Azure Region as location (e.g. "eastUS") and input the following command to create the resource group: az group create --name adex --location eastUS

![Command for creating resource group](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dj36ggfurr7gfdy2r0py.png)

- 
Create a virtual machine:
Choose a name for your virtual Machine (e.g. “matrix”) and input the following command to create the virtual machine within the resource group by replacing resource-group (e.g. “adex”), (e.g. name “matrix”), and image (“UbuntuLTS”): az vm create --resource-group adex --name matrix --image UbuntuLTS  --generate-ssh-keys

![Command for creating VM](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/owm3xfl6nofmchm9geg6.png)

- 
After the installation and configuration, you will have a resource group and a virtual machine set up in your Azure environment. To minimize expenses, keep in mind to delete resources when they are no longer needed.
#DEVDiscuss: Optimizing Dockerfiles
Tags: devdiscuss, docker, programming
Published: 2023-06-06 19:56:00

Time for #DEVDiscuss — right here on DEV 😎

{% embed https://dev.to/er_dward/dockerfile-optimization-using-multistage-builds-caching-and-lightweight-images-2ec6 %}

Inspired by @er_dward's [Top 7](https://dev.to/devteam/top-7-featured-dev-posts-from-the-past-week-34h0) post, tonight’s topic is...optimizing Dockerfiles 🐳

According to the post...

> Leveraging Docker's caching mechanism and multistage builds can result in significant enhancements in Dockerfile efficiency for a Laravel PHP application using Yarn and Nginx. With a better understanding of these mechanisms, developers can craft Dockerfiles that build faster, produce smaller images, and thus, reduce resource usage.

### Questions:

- **What tools, tips, and tricks have you used to optimize Dockerfiles?**
- **Have you used any non-Docker solutions for efficient container development?**
- **Any triumphs, fail whales, or other stories you'd like to share on this topic?**
High Quality Dev Clothing
Published: 2023-06-06 19:22:35

🌟 Calling all developers! 🌟

Get ready to rock the coding world in style with CodeWear! Discover our trendy collection of embroidered and printed hoodies, t-shirts, mugs, and more. Join our community of front-end enthusiasts and let your code shine! 

Visit [https://codewear.store](codewear.store) 
and use the discount code "AndiiCodes" to get $5 off your purchase.

📦 Free international shipping 
✅ High Quality, 30 days return available.
🥰 Check our store for more items.



![JS Hoodie](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jo9m6b656w1ynvtcic6f.jpg)
![JS Hoodie](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q9i8s2u23bw4qr06wbqu.jpg)
Automating Code Comments with GPTDoc: A Step-by-Step Guide
Published: 2023-06-06 19:05:41

As developers, we are always looking for ways to improve the efficiency of our workflow while maintaining the quality of our code. One essential aspect of any well-organized codebase is its documentation. Good documentation ensures that the intent and purpose of the code are well understood by both present team members and future maintainers of the codebase.

However, writing comprehensive and accurate documentation is a time-consuming process. What if we could automate the process of generating code comments for our functions? This is where GPTDoc comes in. GPTDoc is a code comment generator tool that leverages OpenAI models to generate documentation for your code automatically.


&nbsp;

## Requirements

* Node `>=18.0.0`
* npm `>=8.0.0`

## Using

* [gptdoc](https://github.com/matiasvlevi/gptdoc)


&nbsp;

## Getting Started with GPTDoc

Install gptdoc as a dev dependency in the project you want to document



&nbsp;

### Installing


```
npm i --save-dev gptdoc
```



&nbsp;

### Configuring

Create a configuration file named `.gptdoc` in the root of your project

```
{
    "DEBUG": false,
    "framework": "JSDOC",
    "language": "JS",
    "files": {
        "src": "./src",
        "dest": "./gpt",
        "recursive": true
    },
    "openai": {
        "temperature": 0.7,
        "top_p": 1,
        "max_tokens": 256,
        "model": "text-davinci-003"
    },
    "prompt": "Add property tags with @prop"
}
```

Change the src directory to your directory holding your project's source code. 



&nbsp;

### OpenAI API Key

You need to have access to OpenAI's private beta API, and provide a token.

Create a file named `.env` in the root of your project

```env
OPENAI_API_KEY="your-key-here"
```

You can find your token [here](https://platform.openai.com/account/api-keys)

<br/>

### Auto-Document

Every method or class with a `/** @gpt */` code comment will be documented

```js
/** @gpt */
function foo(x) {
    let sum = 0;
    for (let i = 0; i < x.length; i++) {
        sum += x[i];
    }
    return sum;
}
```

Run the script to document

```
node node_modules/gptdoc
```


If everything was configured properly, you should see a copy of your codebase in `./gpt` which holds all the documentation comments


Here is an example of the output

```js
/**
 * @autogenerated
 * @description Calculate the sum of all elements in an array.
 * @function foo
 * @param {number[]} x - An array of numbers to sum up.
 * @returns {number} The sum of all elements in the input array.
 */
function foo(x) {
    let sum = 0;
    for (let i = 0; i < x.length; i++) {
        sum += x[i];
    }
    return sum;
}
```


&nbsp;

We learned how to automate the generation of code comments using GPTDoc. By following these steps, you can save valuable time in maintaining your codebase and focus on other important tasks in your project. Don't forget to always review the autogenerated comments to ensure their accuracy and to maintain a high level of quality in your documentation. Keep a Human in the loop!
hw-13
Published: 2023-04-10 02:04:46

AARON'S ARTICLE HERE -> https://dev.to/aaronlobitana/ist-256-project-2-done-5d1g


1. How many elements did you end up going with? Why did you break it up that way?

We had a total of 4 elements, each serving a different purpose around the cards. The badge-template element was the smallest in terms of the scope, this contained the badge cards themselves. Each badge card had unique properties like title, creator, icon, category etc. Then there is the search-bar element. This element is used to store a variable that contains the user input, which is parsed through the search bar and stored. Then there is the badge-list element, which is used to store an array of type badge-template (or cards as previously mentioned). This array is responsible for storing and filtering the different badges based on what was input via the search bar element. Finally, we have a badge-search element. This element is used to glue all of the above elements into one solid page. 


2. What was the hardest aspect of this?

The hardest aspect was most definitely being able to envision the way that the different elements were to interact with one another. It feels easier to look at a certain idea and recreate it than it is to map out exactly how the idea will function. Additionally, it was challenging to envision how the different elements were to encapsulate one another, and where to begin (or what the most basic steps were vs. the higher up steps are). 

3. What part of this project was easier than you expected?

I think that the icons were easier than expected, initially the idea of importing objects via the internet / a link with a library stored was a bit intimidating. However, using the professor's code helped me envision the different ways that the non .js files interact with the project as a whole.
New Array Methods are Awesome
Tags: javascript, webdev, programming, news
Published: 2023-06-06 18:44:02


The ECMAScript 2023 (ES2023) specification includes some new methods on the Array object that bring added benefits to our JavaScript programs. These methods provide immutability by default, offering improved predictability and maintainability. Additionally, they can help save time and enhance performance. These exciting additions empower us to write more reliable and efficient code. Let's explore these methods and see how they can elevate our JavaScript development experience. These methods are:  

- toSorted()
- toReversed()
- toSpliced()
- with()

## toSorted()
The toSorted() method returns a new array that is a sorted copy of the original array. The sort order is determined by the compareFn argument, which is a function that takes two elements of the array and returns a negative number, zero, or a positive number, depending on whether the first element is less than, equal to, or greater than the second element.

For example, the following code sorts an array of numbers in ascending order key here is the original array never mutates:


```
const numbers = [10, 5, 2, 7, 3];
const sortedNumbers = numbers.toSorted((a, b) => a - b);
console.log(sortedNumbers); // [2, 3, 5, 7, 10]
console.log(number) = // [10, 5, 2, 7, 3] no changes in original array
```

## toReversed()
The toReversed() method returns a new array that is a reversed copy of the original array.

For example, the following code reverses an array of strings:


```
const strings = ["hello", "world"];
const reversedStrings = strings.toReversed();
console.log(reversedStrings); // ["world", "hello"]
console.log(strings); // ["hello", "world"] no changes in original array
```

## toSpliced()
The toSpliced() method returns a new array that is a copy of the original array with the specified elements removed or inserted. The first argument to toSpliced() is the index at which to start removing or inserting elements. The second argument is the number of elements to remove or insert. The third argument is an iterable of elements to insert.

For example, the following code removes the first two elements from an array and then inserts a new element at the end:


```
const numbers = [1, 2, 3, 4, 5];
const newNumbers = numbers.toSpliced(0, 2, 6);
console.log(newNumbers); // [3, 4, 5, 6]
console.log(numbers); // [1, 2, 3, 4, 5] no changes in original array
```

## with()
The with() method returns a new array that is a copy of the original array with the specified element replaced with a new value. The first argument to with() is the index of the element to replace. The second argument is the new value.

For example, the following code replaces the first element in an array with a new value:


```
const numbers = [1, 2, 3, 4, 5];
const newNumbers = numbers.with(0, 6);
console.log(newNumbers); // [6, 2, 3, 4, 5]
console.log(numbers); // [1, 2, 3, 4, 5] no changes in original array
```

These new array methods are a welcome addition to the JavaScript language. They make it easier to work with arrays in a predictable and maintainable way.
Swiftmailer on PHP 8.2
Tags: php, symfony, opensource, mail
Published: 2023-06-06 18:50:25

One of the essential requirements for software to be maintained is the ability to upgrade the internals, hardware, operating system etc. to the latest possible versions. Long-term.

Lately, I've been working on a few legacy apps that needed new life breathed into them. Some ran 7.4, some even older versions of PHP.

One of external dependencies that these apps had in common was now long abandoned [Swiftmailer by Symfony](https://swiftmailer.symfony.com/docs/introduction.html).

The original Swiftmailer runs on PHP versions up to 8.1, and no later. PHP 8.1 will be [end-of-life](https://www.php.net/supported-versions.php) by the end of 2024.

For some reason I've had trouble finding a fork that would reliably support PHP 8.2.

Without further ado, here is a Swiftmailer fork that can be **run without any deprecation warnings on PHP 8.2**: {% embed https://github.com/viaaurea/swiftmailer-legacy %}

All anyone willing to upgrade to PHP 8.2 has to do is type
```
composer require viaaurea/swiftmailer-legacy -W
```

This will replace the original package **without breaking requirements** by other packages that rely on Swiftmailer being installed.

The fork is a fully compatible drop-in replacement of the original Swiftmailer with minimal code changes to support PHP 8.2.
Anyone help with this React/NextJS error?
Published: 2023-06-06 18:47:06


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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/01zapkc32mo7xiie3q6b.png)
How to create normalizer to make case in sensitive on ElasticSearch
Tags: elasticsearch, programming, nosql, backend
Published: 2023-06-06 18:45:56

---
title: How to create normalizer to make case in sensitive on ElasticSearch

description: By default if you add field on index elasticsearch with keyword data type, you cannot querying or sorting the field with case insensitive, because it is not supported by default

published: true

tags: elasticsearch, programming, nosql, backend
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xs7pams6ya7dotgwx8iy.png
---
By default if you add field on index elasticsearch with keyword data type, you cannot **querying** or **sorting** the field with case insensitive, because it is not supported by default, the solution is you can add normalizer like this using kibana: 

``` sh 
PUT your_awesome_index_name
{
  "settings": {
    "analysis": {
      "normalizer": {
        "lowercase_normalizer": {
          "type": "custom",
          "filter": ["lowercase"]
        }
      }
    }
  },
  "mappings": {
      "properties": {
        "name": {
          "type": "keyword",
          "normalizer": "lowercase_normalizer"
        }
      }
  }
}
``` 
And now you can querying the index data with case insensitive keyword: 

``` sh 
GET your_awesome_index_name/_search
{
  "query": {
    "query_string": {
      "default_field": "name.keyword",
      "query": "*reza*"
    }
  }
}
```
ApexCharts: The underrated charts library
Tags: javascript, apexcharts, highcharts
Published: 2023-06-06 18:43:51

ApexCharts is a library that hardly ever appears in "The Top 10 Chart Libraries" posts. 

I like it very much, because the API looks like a copy of HighCharts, a very powerful (paid) charts library. 

This post is more a note for myself, I will not go over why I use this chart library for most of my projects. See for yourself.

https://apexcharts.com/