teleren/devto huggingface dataset:
Mean, Median, Mode
Tags: python, datascience, statistics, beginners
Published: 2020-07-14 19:03:21

In this article, we are talking about the common methods to **measure the central tendency of the data**, that is a way to explain our data in some manner. Although these measurements are quite simple, they are a foundation for a lot of other more complex measurements.

We will use this fake list of grades of a class below to demonstrate the concepts:
<table>
<thead>
  <tr>
    <th>Grades</th>
  </tr>
</thead>
<tbody>
  <tr>
    <td>9.2</td>
  </tr>
  <tr>
    <td>7.5</td>
  </tr>
  <tr>
    <td>8</td>
  </tr>
  <tr>
     <td>9</td>
  </tr>
  <tr>
     <td>8.5</td>
  </tr>
  <tr>
     <td>8</td>
  </tr>
  <tr>
     <td>2.5</td>
  </tr>
</tbody>
</table>

We create a Python variable to store the grades:
```python
grades = [9.2, 7.5, 8, 9, 8.5, 8, 2.5]
```

## Mean
The first one is the **mean**, which is the arithmetic average of the data. To calculate the mean of a set of numeric data, we take the sum of all observations divided by the number of observations.

In Python:
```python
from typing import List

def mean(xs: List[float]) -> float:
  return sum(xs)/len(xs)
```
So, applying in our grades data: `mean(grades)` gives us `~7.52`.

## Median
The second one is the **median**, which gives us something more *positional*. The median is the exact central value of a data, so to calculate it we need to:
- Sort data from smaller to largest, and
- If ODD length: pick up the middle value
- If EVEN length: calculate the mean of the two middle values

So, in Python could be like this:
```python
def median(xs: List[float]) -> float:
  s = sorted(xs)
  # If odd lenght, just pick up the middle value
  if len(xs) % 2:
    p = len(xs)//2
    return xs[p]
  # If even lenght, take the mean of the left and right middle values
  else:
    l_p = (len(xs) // 2) - 1
    r_p = len(xs) // 2
    mid_values = [l_p, r_p]
    return mean(mid_values)
```
This way, the grades sorted looks like this: `[2.5, 7.5, 8, 8, 8.5, 9, 9.2]` and their median, `median(grades)`, is `8`.

## Mode
Finally, we have the **mode**, i.e., the observation that occurs the most in a dataset. Thus, a dataset may have *one*, *multiple*, or even *none* mode.

Python mode function:
```python
from collections import Counter
def mode(xs: List[float]) -> List[float]:
  counter = Counter(xs)
  return [x_i for x_i, count in counter.items() if count == max(counter.values())]
```
The grade that occurs the most in our dataset is `[8]` as we can see calling `mode(grades)`

## Python mean, median, and mode
In this article, we made some Python code to illustrate our measurements, just as didactic purposes. By the way, we already have functions in Python libraries that make the job. Bellow, some of them:
- Mean: [numpy.mean](https://numpy.org/doc/stable/reference/generated/numpy.mean.html)
- Median: [numpy.median](https://numpy.org/doc/stable/reference/generated/numpy.median.html?highlight=median#numpy.median)
- Mode: [statistics.mode](https://docs.python.org/3.4/library/statistics.html#statistics.mode)
Android Custom Toast With Example
Tags: android, java
Published: 2020-07-14 18:58:30

Hello World, today we will be going to see how we can make custom toast and in this tutorial, we will see custom toast with an example. See below as an example.

![Custom Toast gif](https://dev-to-uploads.s3.amazonaws.com/i/29v9aj5m4txnvkoqseux.gif)

Before starting let’s see.

##What is Toast? When to use it?

Toast is a view that contains text which notifies the user with some information.

We can use toast when we want to notify the user.

##Making Custom Toast with Example

To make custom toast we need to follow certain steps as follows.

###Step 1. Create a Custom Layout for Toast

the first step is to make a layout file for our toast.

To make a layout file, right-click on layout folder under res and select new -> layout resource file.

we will name this file as custom_toast.xml and in this file, we will make our layout which will b shown in the toast. Check the below code for the layout file.

```xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/customToastContainer"
    android:background="#E39D9D"
    android:padding="10sp"
    >

    <ImageView
        android:layout_width="50sp"
        android:layout_height="50sp"
        android:src="@drawable/ic_android"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        android:id="@+id/toastImage"
        android:tint="@color/colorPrimaryDark"
        />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/toastText"
        android:text="Custom Toast"
        android:textSize="30sp"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintLeft_toRightOf="@id/toastImage"
        app:layout_constraintBottom_toBottomOf="@id/toastImage"

        />

</androidx.constraintlayout.widget.ConstraintLayout>
```

In the above code, we set the id to the parent view and we added an imageview and a textview.

We are keeping things simple so that you can understand better.

our layout looks like this below.

![Custom toast layout](https://miro.medium.com/max/184/0*j6i7FVgUNZ_73gf7.png)

###Step 2. Set layout file to the Toast

To trigger the toast we made a button in the activity layout and calling the makeToast function on click.

Let’s see the code in the makeToast function.

Hey if you want to read full article read here: [Android Custom Toast With Example](https://www.akshayrana.in/2020/07/custom-toast-with-example-in-android.html)
Why Software Engineering?
Published: 2020-07-14 18:57:34

In December of 2019, I graduated Suffolk County Community College with an Associates in Business Administration and had commited to NYIT to obtain a masters degree in Computer Science. I was extremely excited to start my journey in the world of computers until I saw how much it would cost me and everything else I had to learn in order to obtain my degree. For me to obtain Master degree in C.S., I would end up with $60,000, before interest, in students loans. After realizing that I really didn’t want the burden of student loans to follow me for the rest of my life, so I started researching other career paths on the internet!

Websites and how the internet works in general has always interested me. I created a few shopify websites before and truly loved being able to design a website without coding because I was scarred of code. Personally, code was scary. I always thought that I wasn’t smart enough for it, it was an extremely long process to learn the skill. I never took the time to look into it until about a month before starting this bootcamp. I had found some Youtube videos about coding that mention coding bootcamps and how people were getting full time Software Engineering/Full-stack jobs in less than year without any prior knowledge of coding. This blew my mind!

I found my self doing countless hours of research about coding, bootcamps and what people had to say during the bootcamp and after the bootcamp. Everything seemed do able with hard work and a well devloped bootcamp. I eventually narrowed my bootcamp choices down to Lambda School, Kenzie Academy and Flatiron. Flatiron appealed the most to me because of how short it was compared to other bootcamps and how they are focused on changing your way of thinking to think like a problem solver which is what Software Engineers ultimately are!

I choose Software Engineering for mainy reasons. I wanted a skill that was going to age well with time and gives me the freedom to be creative on the internet. Web Dev would help me land a job that provides me job fulfillment, fair pay and the opportunity to be creative!
Generic Test Cases for Testing.
Tags: testing, github, tutorial
Published: 2020-07-14 18:51:58

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/qv2rqfhwj4u77eeumhi1.png)

<p>&nbsp;</p>

Recently I was reviewing the test cases of one of my colleague who has joined as a fresher in testing team. Though he had tried his best to cover up all the test cases as per the functionality and WireFrame provided in the Business Requirement Specification, I found that cases written were not descriptive to be understood in one go. I had to ask him multiple times what he meant to say in Case 1, then in Case 3 and so on...

A thought came to my mind that why should I not create some sample test cases which could help beginners giving a fair idea about writing test cases descriptively. This could help them in writing test cases effectively considering what all things are necessary while drafting test cases to test an application.  

Read about this [more on my website...][my_website]

[my_website]:https://mfaisalkhatri.github.io/2020/07/11/testcases/
ExecutorService in Java
Tags: java, tutorial
Published: 2020-07-14 18:50:29

ExecutorService ( Java's thread pool framework) -

In java, its always being easy to run a method or a piece of code asynchronously. 

For Example - 

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/jqlwzh0k1yudr857su70.PNG)


In java, thread can be created in two ways,
1) By extending Thread class
2) By implementing Runnable Interface

If we want to execute a task asynchronously, than we can create a new instance of thread and assign the task to it. And start the thread, it will execute asynchronously.

Task can be executed asynchronously using threads. But, if suppose we want to execute 100000 tasks than we have to create 100000 threads. And each thread can execute one task at a time asynchronously. But, creating 100000 threads for each task is not the feasibile solution.


The Java ExecutorService is the interface which allows us to execute tasks on threads asynchronously. The Java ExecutorService interface is present in the java.util.concurrent package. The ExecutorService helps in maintaining a pool of threads and assigns them tasks. It also provides the facility to queue up tasks until there is a free thread available if the number of tasks is more than the threads available.

By using Executor service, we can create the pool of threads.

ExecutorService executorService = Executors.newFixedThreadPool(10);

Here, we are creating a pool of 10 threads. And 100000 tasks are submitted to the executor service. Internally, it assigns each task to the threads present in the thread pool. Max 10 threads can execute the task at a time. And the tasks are stored in the blocking queue.

Why Blocking Queue ? - Because No two threads can access the queue at the same time.

Once the threads execution completes, it fetches the next task from the blocking queue. And subsequently, all the threads present in the thread pool do the same.
git Cheat Sheet
Tags: github, git, githunt
Published: 2020-07-14 18:39:18


# What is git?
Git is a version control management system.
# Why git?
   Git helps in keeping track of changes made to code.  
   It also synchronize code between different people.  
   Helps in testing the changes to code without losing the 
   original.  
   Able to revert back to any older versions of code. 
# What is GitHub?
   GitHub is a online platform which allows to store git 
   repositories.
   There are other websites like GitHub such as Gitlab, 
   BitBucket, GitBucket etc.. 
# What is Repository?
   Repository is simply a place to keep track of code and all 
   the changes to code.
   There are two kinds of repositories, **Local** and 
   **Remote**. **Local repository** is the one that is in your 
   local machine and **Remote repository** is stored on a server like github.  
#Now will jump into **Git commands**
* `git clone 'url' ` : downloads the remote repository from server into the local machine 
* ` git init` : to initialize git to the current working directory
* `git status` : shows the current activity on the repository
* `git add 'filename' // 'filenames' // '.' `: add the files to staging area which needs to be included in the next commit
* `git commit -m "message" `: saves the changes made to the repository with the message
* `git push` : pushes local repository to remote repository
* `git pull` : pulls remote repository to local repository 
(for any remote changes)
* `git log` : lists all the commits that have been made to the repository
* `git reset --hard 'commit'` : revert backs the repository to the given commit
* `git branch 'branch name'` : creates a new branch 
* `git checkout 'branch name'` : to switch between the branches of the repository
* `git merge `: to merge the branch and master  



Still there are other git commands but I listed down some of the important and commonly used.
How to preview emails with ActionMailer::Preview on Rails
Tags: rails, ruby
Published: 2020-07-14 18:36:17

We know how it's a pain to test ** e-mails** in our dev environment. Thinking of it, on Rails 4.1, the **ActionMailer::Preview** was released, making it possible to view e-mails without actually sending them. Let's learn how to use this tool.

First of all, we need to create a new mailer in our project.

```
rails generate mailer Welcome
Running via Spring preloader in process 5087
      create  app/mailers/welcome_mailer.rb
      invoke  erb
      create    app/views/welcome_mailer
      invoke  test_unit
      create    test/mailers/welcome_mailer_test.rb
      create    test/mailers/previews/welcome_mailer_preview.rb
```

It's possible to see that Rails created to files inside test filter: _test/mailers/welcome_mailer_test.rb_ and _test/mailers/previews/welcome_mailer_preview.rb_. In our case, we are going to use **_test/mailers/previews/welcome_mailer_preview.rb_** to preview our templates.

Now let's create a method inside **WelcomeMailer** that will be responsible for sending a welcome message to users that signup in our system, assuming we have a model User with an e-mail attribute. To do that, we need to open the file _app/mailers/welcome_mailer.rb_

```ruby
class WelcomeMailer < ApplicationMailer

  def send_welcome_email(user)
    @user = user
    mail({
      to: user.email,
      from: 'eu@mauricioackermann.com.br',
      subject: 'Seja bem-vindo ao sistema Maurício Ackermann'
      })
  end

end
```
Since **WelcomeMailer** is inheriting from ApplicationMailer, he will use the _mailer_ default layout
```ruby
class ApplicationMailer < ActionMailer::Base
  default from: 'from@example.com'
  layout 'mailer'
end
```

_app/layouts/mailer.html.erb_
```erb
<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <style>
      /* Email styles need to be inline */
    </style>
  </head>

  <body>
    <%= yield %>
  </body>
</html>
```

At last, we need to create an e-mail template. Let's create a file __*send_welcome_email.html.erb*__ inside the folder _app/views/welcome_mailer_, which will be our e-mail view.

```erb
<p>Hello, <%= @user.name %></p>
<p><strong>Thank you</strong> for registering in our system!</p>
```

Now that we have our mailer and template done let's test it. All **e-mail previews** are in _test/mailers/previews_. Open the file created by our generator, **_welcome_mailer_preview.html.erb_**.
```ruby
class WelcomeMailerPreview < ActionMailer::Preview

  def send_welcome_email
    WelcomeMailer.send_welcome_email(User.new(name: 'Maurício Ackermann', email: 'eu@mauricioackermann.com.br'))
  end

end
```
Now to visualize the e-mail, we start the server and access the **link**
http://localhost:3000/rails/mailers/welcome_mailer/send_welcome_email

Did you know about this Rails feature? I hope this post helps you debugging your **projects**
Laravel GitHub Profile View Counter
Tags: laravel, github, tutorial, productivity
Published: 2020-07-14 18:27:36

**[This package](https://github.com/caneco/laravel-github-profile-view-counter) allows you to track Github profile views and display them in your profile readme, for free.**

This project was inspired Artem Golubin's post [**How to track and display profile views on GitHub**](https://rushter.com/blog/github-profile-markdown).

> As part of recent design changes, GitHub has introduced READMEs for profiles. By creating a repo with your name and adding README.md file with markdown to it, you can now add a rich description of yourself.

## Installation

You can install the package via composer:

```
composer require caneco/laravel-github-profile-view-counter
```

You can publish and run the migrations with:

```
php artisan vendor:publish --provider="Caneco\GithubProfileViewCounter\GithubProfileViewCounterServiceProvider" --tag="migrations"
php artisan migrate
```

## Usage

Just visit `yourdomain.com/github-profile-view-counter.svg`, you should see your badge with `visits++`.

## Done

![GitHub Profile example with badge](https://dev-to-uploads.s3.amazonaws.com/i/8qoxefrcorwk5lhzzuip.png)

## Cheating

You can always fill your table with a lot of rows to make yourself famous! **But, play nice** 😉.

## Contributing?

Please see [CONTRIBUTING](https://github.com/caneco/laravel-github-profile-view-counter/blob/master/CONTRIBUTING.md) doc for details.
Daily Challenge #269 - Decompose n!
Tags: challenge
Published: 2020-07-14 18:02:44

---
title: Daily Challenge #269 - Decompose n!
published: true
series: Daily Challenge
description: Decompose n! into its prime factors. 
tags: challenge
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/mfbue7trbvpibpc44p02.png
---
The goal of this challenge is to decompose n! (factorial n) into its prime factors. The function decomp(n) should return the decomposition of n! into its prime factors in increasing order of the primes, as a string. The factorial can be a very big number (4000! has 12674 digits, n will go from 300 to 4000).

**Examples:**
`n = 12; decomp(12) -> "2^10 * 3^5 * 5^2 * 7 * 11"`
since 12! is divisible by 2 ten times, by 3 five times, by 5 two times and by 7 and 11 only once.

`n = 22; decomp(22) -> "2^19 * 3^9 * 5^4 * 7^3 * 11^2 * 13 * 17 * 19"`
`n = 25; decomp(25) -> 2^22 * 3^10 * 5^6 * 7^3 * 11^2 * 13 * 17 * 19 * 23`

Prime numbers should be in increasing order. When the exponent of a prime is 1 don't write the exponent.

**Tests:**
decomp(17)
decomp(5)
decomp(22)
decomp(14)
decomp(25)

Good luck!

***
_This [challenge](https://www.codewars.com/kata/5a045fee46d843effa000070) comes from g964 on CodeWars. Thank you to [CodeWars](<https://codewars.com/>), who has licensed redistribution of this challenge under the [2-Clause BSD License](<https://opensource.org/licenses/BSD-2-Clause>)!_

_Want to propose a challenge idea for a future post?  Email **yo+challenge@dev.to** with your suggestions!_
EF Core Community Standup: Blazor
Tags: webdev, database, csharp, blazor
Published: 2020-07-14 18:02:04

---
title: EF Core Community Standup: Blazor
published: true
description: In this episode, Jeremy Likness provides guidance for using Entity Framework Core in Blazor Server projects. Includes full filtering, paging, and sorting, with automatic audits and optimistic concurrency.
tags: webdev, database, csharp, blazor
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/lmole5vg7gnttw3zrgsb.jpg
---

[Blazor](https://jlik.me/h4k) is a powerful platform for building Single Page Applications (SPA) using C# and .NET. It allows you to build reusable components and access existing .NET Standard libraries. [Blazor Server](https://jlik.me/h4l) is a hosting model that manages rendering and processes events on the server and communicates with your browser via a lightweight JavaScript shim and SignalR.

This episode walks through a reference [line of business application](https://github.com/jeremylikness/blazorserverefcoreexample). It features dynamic filtering, paging, and sorting, with add, edit, and delete capabilities. It implements optimistic concurrency for the case when two users edit the same information at the same time. It features a background audit that both timestamps entities as they are modified and generates a historic snapshot of properties.

{% youtube HNJYIqeBLQc %}

All of the links for the show are available here:

- [https://www.theurlist.com/efcore-standup-2020-06-24](https://www.theurlist.com/efcore-standup-2020-06-24)
How I got 100+ ⭐️ in just less than a day on GitHub?!
Tags: showdev, github, opensource
Published: 2020-07-14 17:58:06

My Github Repo [awesome-github-profile-readme](https://github.com/abhisheknaiidu/awesome-github-profile-readme) got 100+ 🌟 in just less than a day, I will explain how this repo is helping people to get more insights regarding the new cool feature, launched by GitHub i.e Github Profile README.

 {% github https://github.com/abhisheknaiidu/awesome-github-profile-readme %} 

###**So, what exactly is a Github Profile README? :thinking:**

Since the release of the Github Profile README, which happened just about a couple of days ago, there have been a lots and lots of tweets and articles on Twitter and [DEV](dev.to) about what the Github Profile README is about and how you can set up your own. I found this awesome article by [Monica Powell](https://dev.to/m0nica) to get you started:

{% link https://dev.to/m0nica/how-to-create-a-github-profile-readme-1paj %}

###**So, what does *Awesome Github Profile README* has to do with it?👀**
It's actually a place, where you'll find a list of all the awesome Github Profile READMEs, which **Tools** they have used to make it more interactive, and also a few bunch of famous known **Articles**, which give insights and more ideas on how you can set up your own. 

 **Tweets**
 {% twitter 1282743861371039745 %} 



 {% twitter 1282970531759677441 %} 

That's it :D
I hope you guys like it. And make sure to give it a star on [Github](https://github.com/abhisheknaiidu/awesome-github-profile-readme)

P.S - If anyone, who thinks that their README is beautiful or stands out in some way, then they can showcase their GitHub profile readme in the discussion section 😉.
What is the Output of this
Tags: challenge, java, backend
Published: 2020-07-14 17:45:15

---
title: What is the Output of this
published: true
description: Find the output of this program
tags: #challenge , #Java, #backend
#cover_image: https://gitlab.com/techpaadam/java-quiz/-/raw/master/obj.png
---

Find the output of this Java program

![program](https://gitlab.com/techpaadam/java-quiz/-/raw/master/obj.png)

This is very simple program.

An JSONObject is created with key as key1 and value as value1.
Then its passed to the method;
In that method for the passed JSONObject we will be putting the key as key1 and value as value2.

What will be the output of this program ?

[Source Twitter](https://twitter.com/TechPaadam/status/1283088886080495616)