teleren/devto huggingface dataset:
Python 101: Introduction to Python for Data Science
Tags: python, datascience
Published: 2023-04-25 10:30:00

Data is the new oil. Not literally, but this means that data is really valuable in this era that we are currently living in. Raw data in itself is not as valuable, but the information extracted from the raw data is very valuable. This extraction of valuable information is done using the discipline of data science.

_**Data Science**_ is the study of data to extract meaningful insights from it. IBM defined data science in this way:

Data science combines math and statistics, specialized programming, advanced analytics, artificial intelligence (AI), and machine learning with specific subject matter expertise to uncover actionable insights hidden in an organization’s data. These insights can be used to guide decision making and strategic planning.

One of the powerful tools that data scientists use is the python programming language, which you are going to get an overview of in this article. There are other tools and languages like R which is used to handle, store and analyze data and for doing data analysis and statistical modeling. In simple terms, R is an environment for statistical analysis. There is also SAS (Statistical Analytical System.) which is a tool for advanced analytics and complex statistical operations.

The big question is: why python? Below are a few reasons why data scientists prefer python:

Python has powerful mathematical and statistical tools for data analysis and exploration. This is one of the primary reasons that data scientists prefer to use Python.

Data scientists prefer Python because of its ability to handle large data sets, and also incorporate machine learning and modeling because of its rich machine learning libraries.

Python is easy to learn and use, due to its focus on simplicity and readability.

Python Libraries for Data Analysis.

The following are examples of the top 20 python libraries that are essential for data analysis and are you need to import them to work with them.

- NumPy
- Pandas
- Matplotlib
- SciKit-Learn
- TensorFlow
- SciPy
- Keras
- PyTorch
- Scrappy
- BeautifulSoup
- LightGBM
- ELI5
- Theano
- NuPIC
- Ramp
- Pipenv
- Bob
- PyBrain
- Caffe2
- Chainer

Let’s have a look at the first four libraries as they are very important in beginning to learn about data analysis.

## Numpy
NumPy is the most fundamental library for scientific computing with Python and is mostly used for finding solutions to matrix problems.

## Pandas
Pandas is used for data manipulation and analysis.

## Matplotlib

Matplotlib is a powerful library for Data Visualization using histograms, pie charts, and bar graphs.

## SciKit-Learn
SciKit-Learn is a library that focuses on building machine learning models and provides a range of supervised and unsupervised Machine Learning Algorithms.

## Seaborn
Seaborn is a data visualization library based on matplotlib and it provides a high-level interface for drawing attractive and informative statistical graphics.

The above libraries can be imported as follows:

![code for the imports](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dkgra69h8c88g7vziubx.jpg)
safe-signer: creating an ethers.Signer from the third party secret storages
Tags: ethereum, web3, wallet, security
Published: 2023-04-25 10:15:36

**If you need a wallet or singer in your backend server, this project is for you.**

It aims to create an [ethers.Signer](https://docs.ethers.org/v5/api/signer/#Signer) from the third party secret storages. Currently, it supports:

- Private key
  - This is only for testing purposes, not recommend in production environments.
- Environment variables
- AWS Secrets Manager
- AWS Key Management Service (KMS)
- Hashicorp Vault

NOTE:

> Currently it supports `ethers@^5` only.

## How to use

### Install

Node >= 16.

```sh
npm i @dteam/safe-signer
```

### Import

Javascript:

```js
const SafeSigner = require('@dteam/safe-signer');
```

Typescript:

```ts
import SafeSigner from '@dteam/safe-signer';
```

### Examples

1. `fromPrivateKey` will return a Wallet.

```ts
const privateKeyWallet = await SafeSigner.fromPrivateKey('YOUR_PRIVATE_KEY');
```

2. `fromEnv` will return a Wallet.

```ts
const envWallet = await SafeSigner.fromEnv('ENV_VAR_FOR_PRIVATE_KEY');
```

3. `fromAwsSecretsManager` will return a Wallet.

```ts
const awsSecretsManagerWallet = await SafeSigner.fromAwsSecretsManager(
  {
    SecretId: 'FULL_ARN_FOR_SECRET',
    SecretKeyName: 'KEY_NAME_STORED_PRIVATE_KEY',
  },
  {
    credentials: {
      accessKeyId: 'YOUR_AWS_ACCESS_KEY_ID',
      secretAccessKey: 'YOUR_AWS_SECRET_ACCESS_KEY',
    },
    region: 'YOUR_REGION',
  }
);
```

4. `fromHashicorpVault` will return a Wallet.

```ts
const hashicorpVaultWallet = await SafeSigner.fromHashicorpVault(
  {
    // you can set to your own vault server
    // baseUrl: 'http://127.0.0.1:8200/v1',
    rootPath: 'secret',
    timeout: 6000,
    secretName: 'wallet-secret',
    secretKey: 'privateKey',
  },
  // login method can be any of the following:
  // {token: 'plaintext-token'}
  // {appRole: {roleId: 'roleId', secretId: 'secretId'}}
  // {cert: {certName: 'certName'}}
  // {k8s: {role: 'role', jwt: 'jwt'}}
  // {ldap: {username: 'user', password: 'password'}}
  // {userpass: {username: 'user', password: 'password'}}
  {token: 'vault-plaintext-token'},
  {secretName: 'wallet-secret', secretKey: 'privateKey'}
);
```

5. `fromAwsKms` will return a Signer because you can't get the raw private key from AWS KMS.

```ts
const awsKmsSigner = await SafeSigner.fromAwsKms('YOUR_AWS_KMS_KEY_ARN', {
  credentials: {
    accessKeyId: 'YOUR_AWS_ACCESS_KEY_ID',
    secretAccessKey: 'YOUR_AWS_SECRET_ACCESS_KEY',
  },
  region: 'YOUR_REGION',
});
```

For more details, you can check its github repo: https://github.com/DTeam-Top/safe-signer
The War on Bots: Best Practices to Secure Your Contact Form.
Tags: digitalidentitymanagement, adaptiveauthentication, consumeriamsolutions, identityproofing
Published: 2023-04-25 10:15:28

## **Introduction**

Bot attacks on contact forms can have serious consequences for website owners, including compromised user data and damaged reputation. It is imperative to take proactive steps to safeguard your contact form against these threats. In this blog, we will share practical tips and techniques to strengthen the security of your contact form and keep bot attacks at bay.

## **What Is a Spambot?**

Spambots pose a significant threat to the security and integrity of contact forms. These malicious programs can collect email addresses and other information, leading to spamming activities and data abuse. 

As [contact forms](https://www.loginradius.com/blog/identity/bot-attacks/) are commonly used for communication and data collection purposes, it is crucial to take steps to protect them from spambots and ensure the confidentiality and security of user data.

![secure-your-contact-form-from-bot-attacks](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lhttbrfyewbwxwhdu8uj.jpg)

**Form Fortification: Top 12 Techniques to Stop Bot Intrusions**

1. Add Google reCAPTCHA.
2. Secure contact forms using a double opt-in form.
3. Add a test question to your contact form.
4. Add Honeypots.
5. Implement time-analysis.
6. Hide target request.
7. Form validation after geolocation of the IP address.
8. Use a web application firewall.
9. Blacklist IPs and limited IP addresses.
10. Beware of Cross-Site Request Forgery (CSRF).
11. Validate email addresses and phone numbers.
12. Block copy and paste in your forms.

## **Conclusion**

In summary, spambots may continue to be a threat, but by implementing these strategies, you can effectively defend your forms and prevent unauthorized submissions.
Android App with Button Click Event and Toast Message
Tags: android, mobile, learning, beginners
Published: 2023-04-25 10:05:18

This code is an example of an Android app that demonstrates the use of a button click event and a Toast message. The app contains a layout with a button and a text field.

🔺The **onCreate()** method initializes the button and text field.

🔺The **setOnClickListener()** method is used to set an event listener on the button that listens for click events.

🔺When the button is clicked, a Toast message is displayed with the text entered in the text field.

🔺The **findViewById()** method is used to get a reference to the button and text field views, using their resource IDs.

🔺The **getText().toString()** method is used to get the text entered in the text field and store it in a string variable.

🔺Finally, the **makeText()** method is used to create a Toast message that displays the entered text, and the show() method is called to display the message.

This code can be used as a starting point for building more complex Android apps that require event handling and user input.

```
package com.example.parttime;

import android.annotation.SuppressLint;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {


    private Button buttonOB;
    private TextView editTextOB;



    @SuppressLint("MissingInflatedId")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toast.makeText(this, "On Create", Toast.LENGTH_SHORT).show();
        buttonOB=findViewById(R.id.ClickMeBtn);
        editTextOB=findViewById(R.id.editText);

        buttonOB.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                String nameStr;
                nameStr=editTextOB.getText().toString();

                Toast.makeText(MainActivity.this, nameStr, Toast.LENGTH_SHORT).show();
            }
        });
    }

```
django.contrib.auth.models
Tags: django, beginners, backend, python
Published: 2023-04-25 04:29:06



The django.contrib.auth.models path is an essential part of Django's built-in authentication system, providing models and functionality for user authentication, permissions, groups, and user profiles.

this is a module in django that provides the models for user authentication and authorization

this module provides a couple of models:

1. User  - This  model represents a user account and stores information such as username and password, email. it also includes authentication, password management and user permissions methods.
2. Group - This model represents a user group which is used to manage user permissions and assign permissions as a group
3. Permission - This model represents a user permission that can be granted to a user
4. AbstractUser - This model represents a base class that provides a customizeable user model. it includes fields such as username, email and password as well as customizable  fields for addtional data
5. AbstractBaseUser - This model represents another base class that provides a more customized user model, it includes fields such as username(custom username field), email and password.
6. PermissionMixin - This is a mixin class that can be used to add permissions to custom user models it includes fields for permissions and methods for checking permissions
7. BaseUserManager - This is a base class that for custom user managers which are used to customize the creation of and management of user accounts

One of the most significant advantages of using the django.contrib.auth.models path is that it is highly customizable. Developers can extend the User model to include additional fields or functionality, or they can create custom authentication backends to authenticate users against custom data sources.

Another advantage of using the built-in authentication system in Django is that it integrates well with other Django modules and functionality, such as the admin site, forms, and templates.

 the django.contrib.auth.models path in Django provides a solid foundation for user authentication and authorization in Django applications. Its comprehensive set of models and functionality allow developers to easily implement user management features, such as permissions, groups, and user profiles, while its customizable nature allows for flexibility and extensibility.

By using the django.contrib.auth.models path, developers can ensure that their Django applications have a reliable and secure authentication system that integrates well with other Django modules and functionality. With its ease of use and flexibility, the built-in authentication system in Django can save developers time and effort in implementing user authentication and authorization features, enabling them to focus on building other core features of their application.
Simple Android App to understand Activity Lifecycle
Tags: android, mobile, learning, beginners
Published: 2023-04-25 09:35:43

This code is an example of a simple Android app that demonstrates the Activity Lifecycle using Toast Messages. The app contains a layout with a button, two text views, and a text field.

The onCreate() method initializes the button, text views, and text field. The setOnClickListener() method is used to set an event listener on the button that listens for click events. When the button is clicked, a Toast message is displayed with the text entered in the text field, and the text is also displayed in the second text view.


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



The app also includes five other methods that demonstrate the Activity Lifecycle: **onStart(), onResume(), onPause(), onStop(), and onRestart().**

Each method displays a Toast message when the corresponding lifecycle event occurs. Finally, the onDestroy() method displays a Toast message when the activity is destroyed.

This code can be used as a starting point for building more complex Android apps that require event handling and interaction with the Activity Lifecycle.

```
 private Button button;
    private TextView text;
    private TextView textView;

    @SuppressLint("MissingInflatedId")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        button=findViewById(R.id.button);
        text=findViewById(R.id.text1);
        textView=findViewById(R.id.textView3);


        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                String nameStr;
                nameStr=text.getText().toString();
                Toast.makeText(MainActivity.this, nameStr, Toast.LENGTH_SHORT).show();

                textView.setText(nameStr);


            }
        });


    }

    @Override
    protected void onStart() {
        super.onStart();
        Toast.makeText(this, "On Start", Toast.LENGTH_SHORT).show();
    }

    @Override
    protected void onResume() {
        super.onResume();
        Toast.makeText(this, "On Resume", Toast.LENGTH_SHORT).show();
    }

    @Override
    protected void onPause() {
        super.onPause();
        Toast.makeText(this, "On Pause", Toast.LENGTH_SHORT).show();
    }

    @Override
    protected void onStop() {
        super.onStop();
        Toast.makeText(this, "On Stop", Toast.LENGTH_SHORT).show();
    }

    @Override
    protected void onRestart() {
        super.onRestart();
        Toast.makeText(this, "On Restart", Toast.LENGTH_SHORT).show();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        Toast.makeText(this, "On Destroy", Toast.LENGTH_SHORT).show();
    }
}
```
React Native vs Flutter 2023- Which is Best For Your Project
Published: 2023-04-25 09:06:01


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kxmvz0ect4ashcanqgug.png)
React Native vs Flutter: Two of the best frameworks to develop cross-platform mobile applications today. Techies all around the world love talking about the frameworks, their differences, and which one is better than the other. And why not? Mobile development is a huge industry with over 6 billion active mobile users worldwide. And according to Statista, 42% of the developers pick React Native vs Flutter over other conventional frameworks. Comparably, Cordova, the 3rd most popular mobile framework, is only preferred by 16% of developers.

React Native vs Flutter has been a massive success ever since their parent companies launched them- Facebook and Google, respectively, two of the largest tech conglomerates in the world. According to reports from Comscore, Users spend up to 87% of their time using apps daily, and smartphone app usage is constantly growing. The market is cutthroat, and every company wants to grab a piece of this pie, including startups and developers building their applications to enter the market. 

This article will discuss the two most popular frameworks these app developers and companies use- React Native vs Flutter, and how they compete. Let’s start with a general introduction to each.

Want to learn more about React Native vs Flutter visit - [React Native vs Flutter](https://optymize.io/blog/react-native-vs-flutter-2023/)
Struct vs Class
Tags: ios, swift, class, struct
Published: 2023-04-25 08:49:41

struct and class are the pillars of any Object Oriented Language. Main part is deciding when to use which one. To get the answer of this question we need know how they differ in properties. Let’s check one by one - 

**1. Reference vs Copy** - Classes work on reference type whereas Structs work on Copy type. Suppose you create an instance A and later you create another instance B by assigning A to it. Now check their effects based on their types - 
    1. _Class_  -> Change in A or B will show change in other one also because they are pointing to same address.
    2. _Struct_ -> change in A or B will not affect other because both the instances are separate. B is like a independent copy of A.

**2.  Inheritance** - Classes allow us to inherit other classes whereas Structs don’t support inheritance. 

_Class inheritance_ - Below code snippet shows how class B has inherited class A.

```Swift
class classA{
    var name = ""
}
class classB:classA{
    let type = ""
    
    func updateName(){
        //accessing property of inherited class A
      name = "updated name"
    }
}
```
_Struct inheritance_ - Structs don't support inheritance hence complier will give error if we go for it. 

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

**3. init** -  Structs come with a default init function including all the properties which is known as _property-wise initialisation_. Whereas in Class you need to write your own init function.

```Swift
class classA:NSObject{
    var name:String
    
    init(userName:String){
        name = userName
    }
}

struct structA{
    var name:String
    var skills:String
}

func demoOfInit(){
    let classObj = classA(userName: "class")
    let structObj = structA(name: "struct", skills: "default init")
}
```

**4. deinit function** - Class provides us the deinit function whereas in struct there is no such function. 

```Swift
class classA:NSObject{
    var name:String

    init(userName:String){
        name = userName
    }
    
    deinit{
        
    }
}
```
 
Now based on above differences you can easily decide our preference for specific case.

One example can be Modals -> In modals we go for Structs because we generally don't need their references or inheritance as they are usually used as independent objects.
HTML Email image cut in half?
Published: 2023-04-25 08:24:05

## TL:DR

Set the line height of the container to 1.

```css
div {
	line-hieght: 1;
}
```

You might need to add “display: block;”

```css
div {
	display: block; 
	line-height: 1;
}
```

## Long version:

If you are creating an HTML email that is to be sent to an Outlook email client, you may see in test emails that an image is being cut in half. Like so:

![Logo image cut in half](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g0wq2usvmz6t1lm35avd.png)

Even when you have set the height and width of a html image manually and inline , outlook still seems to have issues displaying the image correctly depending on what you emails markup may look like.

You may have to deal with WYSIWYG editors that are auto generating the email and they can also face errors that come out of no where.

Putting, inline “display: block; line-height: 1;” like so can force outlook to display the image correct.

```html
<img style="display: block; line-height: 1;" src=""/>
```
You may have to experiment with different inline styles depending on your email. Like so.

```html
<td width="156" height="42" align="right" valign="bottom" style="line-height: 1;">
	<table width="156" border="0" cellspacing="0" cellpadding="0" style="line-height: 1;">
		<a href="https://www.example.com/" target="_blank" style="display: block; line-height: 1;" >
			<img style="display: block; line-height: 1;" src="https://www.example.com/emarketing/logo.jpg" width="196" height="42">
		</a>
	</table>
</td>
```
## Result:

![Image of the fixed logo](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8cqi36joss122b7zx7z2.png)

The reason for this is due to Outlook not respecting the height attribute if line-height is not set to at least 1.

## Sources:

[https://stackoverflow.com/a/21603951](https://stackoverflow.com/a/21603951)

[https://www.campaignmonitor.com/css/](https://www.campaignmonitor.com/css/)
Identifying Outliers in a data set
Tags: datascience, python, machinelearning, programming
Published: 2023-04-25 07:58:50

**What are Outliers**

An Outlier is an extremely high or extremely low value in our data .It can be identify if it is greater than Q3 + 1.5(IQR) or lower tha Q1 - 1.5(IQR).

IQR = Q3 - Q1

_Note:_ 

- IQR means Interquartile Range 

- Q1 means first quartile

- Q3 means third quartile


`import numpy as np
  
data = [32, 36, 46, 47, 56, 69, 75, 79, 79, 88, 89, 91, 92, 93, 96, 97, 
        101, 105, 112, 116]

Q1 = np.median(data[:10])

Q3 = np.median(data[10:])
  

IQR = Q3 - Q1
  
print(IQR)

`

Other example 

```
import numpy as np
import pandas as pd
df = pd.DataFrame({'rating': [90, 85, 82, 88, 94, 90, 76, 75, 87, 86],
                   'points': [25, 20, 14, 16, 27, 20, 12, 15, 14, 19],
                   'assists': [5, 7, 7, 8, 5, 7, 6, 9, 9, 5],
                   'rebounds': [11, 8, 10, 6, 6, 9, 6, 10, 10, 7]})


q75, q25 = np.percentile(df['points'], [75 ,25])
iqr = q75 - q25


iqr

5.75
```