teleren/devto huggingface dataset:
Shorthand Comparisons in PHP
Tags: php
Published: 2020-06-13 20:23:13

In Programming, shorthand is writing same piece of code in shorter way. Shorthand comparisons in PHP comprise of minimal use of code for better reading & usability.

In this tutorial, we’ll learn which shorthand syntax PHP has added and will understand usability of it with practical approach.

First, we’ll understand the most basic and most important condition which we regularly use in day to day coding. The if statement.



https://programmingdive.com/shorthand-comparisons-in-php/
File Uploading in PHP
Tags: php
Published: 2020-06-13 20:22:45

File uploading is the common functionality in many applications.

In this post, we’ll see how we can upload files using PHP. In the next post we will see how can we upload an image using an ajax?

Uploading files requires following steps-

Select a file to be uploaded.
Validate uploaded file.
Move uploaded file from temporary location to desired location.
Show the success message of the uploaded file to the user.
Let’s look into working example first and then we’ll look into its detail-

https://programmingdive.com/file-uploading-in-php/
How to upload Image using AJAX and Javascript?

Tags: php
Published: 2020-06-13 20:22:15

In the previous post, we learned how to upload Image using AJAX and PHP and now in this post we’ll learn How to upload Image using AJAX and Javascript. We will also look into uploading file(s) via AJAX and JQuery in the very next post.

So, in this case we require .html file for creating form and write our AJAX code in Javascript and one .php file to write server side code for uploading a file & storing it at the desired location.

In the previous post, we performed all the validation operations in .php file itself which is called as server side validation. Here, in the post we’ll apply same validation as a client side validation on uploaded file.

First, we’ll go through the HTML code from which we’ll upload file.

https://programmingdive.com/how-to-upload-image-using-ajax-and-javascript/
is_null vs null in php

Tags: php
Published: 2020-06-13 20:21:43

As per the php.net site documentation, is_null() function finds whether provided variable is NULL.

Actually, is_null() function works similar like isset() but as its opposite. So it returns TRUE in all the cases except when there is no value assigned to a variable OR assigned as NULL.

https://programmingdive.com/is-null-vs-null-in-php/
Quick Sort implemented in Erlang Analysis
Tags: erlang, computerscience
Published: 2020-06-13 17:32:41

> When you want to **truly** understand what you are studying, you **must** go all the way down in the rabbit hole in order to absorb the content.

This is a step by step analysis of what is happening in a quick sort algorithm implemented in the book _Learn you Some Erlang for Great Good_ [1].

**`recursive.erl`**

```erl
-module(recursive).

-export([partition/4, quick_sort/1]).

quick_sort([]) -> [];
quick_sort([Pivot | Rest]) ->
    {Smaller, Larger} = partition(Pivot, Rest, [], []),
    quick_sort(Smaller) ++ [Pivot] ++ quick_sort(Larger).

partition(_, [], Smaller, Larger) -> {Smaller, Larger};
partition(Pivot, [H | T], Smaller, Larger) ->
    if H =< Pivot ->
           partition(Pivot, T, [H | Smaller], Larger);
       H > Pivot -> partition(Pivot, T, Smaller, [H | Larger])
    end.

```

**Analysis**

```txt
quick_sort([5, 2, 2, 7, 6, 3])
  Pivot = 5
  Rest = [2, 2, 7, 6, 3]
  {Smaller, Larger} = ???

  partition(5, [2, 2, 7, 6, 3], [], [])
    Pivot = 5
    H = 2
    T = [2, 7, 6, 3]
    Smaller = []
    Larger = []

    partition(5, [2, 7, 6, 3], [2, []], [])
      Pivot = 5
      H = 2
      T = [7, 6, 3]
      Smaller = [2, []]
      Larger = []

      partition(5, [7, 6, 3], [2, [2, []]], [])
        Pivot = 5
        H = 7
        T = [6, 3]
        Smaller = [2, [2, []]]
        Larger = []

        partition(5, [6, 3], [2, [2, []]], [7, []])
          Pivot = 5
          H = 6
          T = [3]
          Smaller = [2, [2, []]]
          Larger = [7, []]

          partition(5, [3], [2, [2, []]], [6, [7, []]])
            Pivot = 5
            H = 3
            T = []
            Smaller = [2, [2, []]]
            Larger = [6, [7, []]]

            partition(5, [], [3, [2, [2, []]]], [6, [7, []]])
              Smaller = [3, [2, [2, []]]]
              Larger = [6, [7, []]]

  {Smaller, Larger} = {[3, [2, [2, []]]], [6, [7, []]]}

  %% (1) quick_sort([3, [2, [2, []]]] = Smaller) ++ [5 = Pivot] ++ (2) quick_sort([6, [7, []]] = Larger)
  quick_sort([3, 2, 2]) ++ [5] ++ quick_sort([6, 7])

  %% Solving (1) until the end
  quick_sort([3, 2, 2]) = quick_sort([2, 2]) ++ [3] ++ quick_sort([])
    quick_sort([2, 2]) = quick_sort([2]) ++ [2] ++ quick_sort([])
      quick_sort([2]) = quick_sort([]) ++ [2] ++ quick_sort([])

  %% Solving (2) until the end
  quick_sort([6, 7]) = quick_sort([]) ++ [6] ++ quick_sort([7])
    quick_sort([7]) = quick_sort([]) ++ [7] ++ quick_sort([])

  %% Replacing the values from our first quick_sort run
  %% obs 1: quick_sort([]) == []
  %% obs 2: consider that some values are from the left side quick_sort and other from righ side quick_sort

  %% quick_sort([3, 2, 2]) ++ [5] ++ quick_sort([6, 7])
  [2] ++ [2] ++ [3] ++ [5] ++ [6] ++ [7]

  %% Result
  [2, 2, 3, 5, 6, 7]
```

## References

1. [Book LYSE - chapter: Recursion](https://learnyousomeerlang.com/recursion)
Merge PHP objects

Published: 2020-06-13 20:21:11

While working on Object Oriented Programming Language, we often come in contact with large objects. Sometimes these objects are so big that it comes with one object embedded within another and so on. We’ll look into how to merge two or more PHP Objects in depth and different ways of doing that.

Few days back, I was assigned a task to show particular section of sub-block depending upon some condition.

So legacy codebase was having one API call which fetch data from remote resource and then from the response I got list of key-value pairs in terms of an array. Each individual array is then filtered and collected in separate array depending upon some condition.

https://programmingdive.com/merge-two-or-more-php-objects/
Handle Exception in PHP
Tags: php
Published: 2020-06-13 20:20:41

Runtime Errors or Exception
Runtime Errors OR exceptions mainly occurs when there is an unexpected result while executing the programs. To handle Exception in PHP, we need to make some changes in the code itself to make sure that next time if such errors occur then the program itself, understands it, and operates on it effectively.

An exception was introduced in PHP5 and later it was redesign with many fixes consecutive beta versions



https://programmingdive.com/handle-exception-in-php/
Using Lambda and Closure functions in PHP

Tags: php
Published: 2020-06-13 20:19:51

PHP 5.3 started with adding new features in PHP that change the game forever in the language. These are lambda functions/closures & namespaces. Here in this tutorial, we will explore lambda and closure functions in PHP with some practical examples.

In this tutorial, we’ll take a look into what is lambda function & closure with a coding example to understand easily.

So back in 2008, an RFC (Request for Comments) was proposed by Christian Seiler, Dmitry Stogov in which it is suggested that without support for closures, lambda functions are not useful enough to add them to PHP.

Lambda function plays an important role in the development of the closure function. First, we’ll understand about lambda function, and then we’ll see the relationship of it with closure.

https://programmingdive.com/lambda-and-closure-functions-in-php/
Prevent Window From Closing in React.js
Tags: react, webdev, browsers
Published: 2020-06-13 20:17:00

Let's say you want to prevent your webpage or the browser from being exited when the user clicks on the Close button, how would you do it in React.js?

We want to put in place an event that triggers a confirmation dialogue asking the user if they "really" want to leave the page. If the user confirms, the browser either navigates to the new page or closes the tab or the browser, depending on the action of the user.

To be clear, this is what we want to put in place. 

![Chrome exit warning](https://dev-to-uploads.s3.amazonaws.com/i/z13hpzmz6acdqj5vs897.png "Chrome exit warning")
![Firefox exit warning](https://dev-to-uploads.s3.amazonaws.com/i/ojyhmb7h9at62lph7r72.png "Firefox exit warning")

This syntax below shows how to do it once the page loads in react.js.

```javascript
 useEffect(() => {
            window.onbeforeunload = confirmExit;
            function confirmExit()
            {
              return "show warning";
            }
    }, [])
```
You can set it to display after the user triggers an event.
```javascript
const triggerThis = () => {
        window.onbeforeunload = confirmExit;
        function confirmExit()
        {
          return "show message";
        }
    }



// The button to trigger the action

<button onClick={()=>  triggerThis()}> Click here</button>
```

The warning message displays if the user clicks on the button first before trying to exit the page or the browser. If the user does not click on the button, the warning message will not display on page exit.

###Digging Deeper
The `onbeforeunload` property of the `WindowEventHandlers` mixin is the `EventHandler` for processing `beforeunload` events. These events fire when a window or a document is about to unload its resources. At this point, the document is still visible and the event can be cancelled.

To combat unwanted pop-ups, some browsers don't display prompts created in `beforeunload` event handlers unless the page has been interacted with. Moreover, some don't display them at all.

If the `onbeforeunload` function returns null instead of a string, it will not be displayed on page exit. 

For older browsers, you can display a custom message. But that feature has been deprecated in recent browsers.

###Conclusion
This feature comes handy on a page that has a form with may fields. The user can be requested to confirm an exit.

###References
* [WindowEventHandlers.onbeforeunload](https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onbeforeunload)
* [Window: beforeunload event](https://developer.mozilla.org/en-US/docs/Web/API/Window/beforeunload_event)
Package Managers in python 🚀
Tags: python, beginners, productivity
Published: 2020-06-13 19:50:40

![Hola](https://media.giphy.com/media/fTI9mBoWLef8k/giphy.gif)

Hey everyone welcome back to the third post of the series `can-python-do-that`. Wow it's already the third week and I am enjoying to do this 👨🏻‍💻

### Github Repository ⭐️
The repository that holds the assets for the series.
{% github Rohithgilla12/can-python-do-that no-readme %}

To all the JS folks out there, how many time did you feel it would be great if python also has package manager like `npm` or `yarn` with those `*.lock` files. I'm `yarn` fan 😛 btw.

How many times have you encountered problems managing versions in python projects 🤔?

How many times have you hit stackoverflow searching for version mismatch problems?

Well today in our series we are going to talk about the package mangers in `python`.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/4oouli693n589z405673.gif)

Libraries that we sail over today 🚢

- Poetry
- Pipenv
- Virtualenv

## [Poetry](https://python-poetry.org/)
![Poetry Logo](https://python-poetry.org/images/logo-origami.svg)
Poetry is a tool for dependency management and packaging in Python. It allows you to declare the libraries your project depends on and it will manage (install/update) them for you

This is my personal favourite library. I tried different libraries for dependecy management but finally stuck to this.

![asciicast](https://asciinema.org/a/LvH2fjr76qH9CXXV2RjTneCTz.svg)

_[PYPI](https://pypi.org/project/poetry/)_
_[Docs](https://python-poetry.org/docs/)_
_[Asciinema](https://asciinema.org/a/LvH2fjr76qH9CXXV2RjTneCTz)_

P.S: If you are thinking what `toml` means it stands for **Tom's Obvious, Minimal Language.**

## [Pipenv](https://github.com/pypa/pipenv)
![Pipenv Logo](https://pipenv-fork.readthedocs.io/en/latest/_static/pipenv.png)
**Pipenv** is a tool that aims to bring the best of all packaging worlds (bundler, composer, npm, cargo, yarn, etc.) to the Python world. 

It automatically creates and manages a virtualenv for your projects, as well as adds/removes packages from your `Pipfile` as you install/uninstall packages. It also generates the ever-important `Pipfile.lock`, which is used to produce deterministic builds.

![asciicast](https://asciinema.org/a/jLNAFiM8IhMibSJCoLI5FQyKV.svg)

_[PYPI](https://pypi.org/project/pipenv/)_
_[Docs](https://pipenv.pypa.io/en/latest/)_
_[Asciinema](https://asciinema.org/a/jLNAFiM8IhMibSJCoLI5FQyKV)_

## [Virtualenv](https://github.com/pypa/virtualenv)
`virtualenv` is used to manage Python packages for different projects. Using virtualenv allows you to avoid installing Python packages globally which could break system tools or other projects. You can install virtualenv using pip.

![asciicast](https://asciinema.org/a/338930.svg)

_[PYPI] (https://pypi.org/project/virtualenv/)_
_[Docs] (https://virtualenv.pypa.io/en/latest/)_
_[Asciinema] (https://asciinema.org/a/338930)_

![Thanks](https://media.giphy.com/media/VObHs6oqEWFNe/source.gif)


Peace ✌🏻,
Rohith Gilla

_Spoiler Alert: Next week it is going to be about AI/ML libraries_ 🍩
Converting unix epoch time to timestamps in PostgreSQL
Tags: postgres, webdev, beginners
Published: 2020-06-13 20:09:10

Today we will see how to convert the unix epoch strings to timestamps in PostgreSQL directly.

Let's say we are storing the unix epoch time in database in the `timestamp` column.

```sql
> select timestamp from events;

timestamp   | 
------------+
 1591876140
 1591876200
 1591876260
 1591876320
 1591876380
```

When querying the database, timestamps in this format are not very useful as we can't figure out which date and time this string is representing. 

If we could get a date and time representation, it will be easier to debug the data.

PostgreSQL has `to_timestamp` function which can be used for this exact purpose.

```sql
prathamesh=# select to_timestamp(1591876380);
       to_timestamp
---------------------------
 2020-06-11 17:23:00+05:30
(1 row
```

As you can see this returns the timestamp in system's timezone. In my case, it returns the timestamp in IST. 
If I want the timestamp in some different timezone, I can do that easily using the timezone function.

```sql
prathamesh=# select timezone('America/New_york', to_timestamp(1591876380));
      timezone
---------------------
 2020-06-11 07:53:00
(1 row)
```

The earlier query foe `events` table can be changes as follows.

```sql
> select timezone('America/New_york', to_timestamp(timestamp) from events;
```

The `to_timestamp` function also accepts second argument which decides the format of the output. The complete list of formats can be found [here](https://www.postgresql.org/docs/current/functions-formatting.html#FUNCTIONS-FORMATTING-DATETIME-TABLE).

----

I had written a post earlier about [converting unix epoch strings to Ruby objects](https://prathamesh.tech/2020/03/02/converting-timestamps-to-ruby-objects/) earlier. This is useful to convert timestamps to Ruby objects in a Ruby on Rails application.
Azure Architecture Maps
Tags: azure, architecture, maps
Published: 2020-06-13 20:08:08

<sub>Photo by AbsolutVision on Unsplash</sub>

This just a quick post to remind us that many Azure maps exists displaying what at least should be considered when talking about subjects like:
 - [The OpenID Connect (OIDC) Architecture Map](https://techcommunity.microsoft.com/t5/azure-developer-community-blog/the-openid-connect-oidc-architecture-map/ba-p/1119450)
 - [The Azure Kubernetes Service (AKS) Architecture Map](https://techcommunity.microsoft.com/t5/azure-developer-community-blog/the-azure-kubernetes-service-aks-architecture-map/ba-p/1078714)
 - [The Cloud-native Azure Application Architect Map](https://techcommunity.microsoft.com/t5/azure-developer-community-blog/the-cloud-native-azure-application-architect-map/ba-p/812242)
 - [The Azure Infrastructure Architect Map](https://techcommunity.microsoft.com/t5/azure-developer-community-blog/the-azure-infrastructure-architect-map/ba-p/766268)
 - [The Azure Security Architect Map](https://techcommunity.microsoft.com/t5/azure-developer-community-blog/the-azure-security-architect-map/ba-p/714091)
 - [The Azure Solution Architect Map](https://techcommunity.microsoft.com/t5/azure-developer-community-blog/the-azure-solution-architect-map/ba-p/689700)

Hope this helps
volatile vs const in cpp
Tags: cpp, coding
Published: 2020-06-13 19:53:33

__volatile__ and __const__ keywords are very confusing from there implementation perspective. Today we will see the basic fundamental difference between the two.
__const__ is pretty straight forward, we will declare a variable __const__ if the value of the variable is not changing during the runtime of the program. It helps in fast execution of the program as compiler caches the value in the cache memory of the CPU.
__Eg:
void foo()
{
const int a = 100;
}__ 

Whereas the purpose of __volatile__ is different, when you declare any variable with __volatile__ keyword compiler will not perform any kind of optimization for that variable. The optimization is not done because the value for that variable may change by some external factors which compiler can't detect at runtime.
__Eg:
void foo()
{
 volatile int a = 100;
 while(a)
 {
  //operation
 }
}__ 

In the above example the execution condition of the while loop is constant, if the value of __a__ is not changing inside the loop. Then compiler will try to optimize this conditional statement inorder to minimize the data fetching overhead for the CPU. It will try to replace the above code with something like below.

__void foo()
{
 volatile int a = 100;
 while(1)
 {
  //code
 }
}__

But imagine the senario when the value of __a__ is getting changed by some external factors like threading, hardware register of the CPU or by some other means. Then it will end up on giving us some garbage value or even leads to crashing of the program.
So, it's always advisable to use volatile very carefully.

To read more about volatile keyword refer this,
https://en.wikipedia.org/wiki/Volatile_(computer_programming)
Sending emails using smtp in deno
Tags: deno, tutorial, gmail
Published: 2020-06-13 19:52:00

Hey Developers! 

I have created a tutorial for sending emails from your deno project using third party module called smtp.

{% youtube _1tpxFcpCBI %}
-----
## Introduction

* You can send email from your deno application.
* Where we use this thing?
   * Sending verification email to the user after his registration on our project.
   * Sending emails like monthly newsletter, blogs, etc.

## Getting Started

* Packages: 
   * SMTP third party module - https://deno.land/x/smtp/
   * Dotenv third party module - https://deno.land/x/dotenv

* Importing packages
``` TypeScript
import { SmtpClient } from "https://deno.land/x/smtp/mod.ts";
import "https://deno.land/x/dotenv/load.ts";
```
* Creating an instance of SmtpClient
``` TypeScript
const client = new SmtpClient();
```
* Accessing environmental variables
``` TypeScript
const { SEND_EMAIL, PWD, RECV_EMAIL } = Deno.env.toObject();
```
* Configuring & Creating the connection
``` TypeScript
const connectConfig: any = {
  hostname: "smtp.gmail.com",
  port: 465,
  username: SEND_EMAIL,
  password: PWD,
};
await client.connectTLS(connectConfig);
```
* Sending the e-mail to the rec. account
``` TypeScript
await client.send({
  from: SEND_EMAIL,
  to: RECV_EMAIL,
  subject: "Welcome!",
  content: "Hi from Vuelancer!",
});
```
* Finally, closing the smtp client connection
``` Typescript
await client.close();
```
## Run the app

``` sh
$ deno run --allow-read --allow-env --allow-net server.ts
```
# Or else clone this repo and sculpt it!

* you can find the entire code on my github account
{% github Vuelancer/deno-email-smtp %}

~ Thank You! 

### Support Me
* Youtube Channel -https://www.youtube.com/channel/UC0hmXRqXYVO0mocVt5D3GkQ

* Github - https://github.com/vuelancer

* Scrimba - https://scrimba.com/@selvakumardhivakar

* Patreon - https://patreon.com/vuelancer
I'm A Speaker at Ioniconf
Tags: ionic, javascript, react, angular
Published: 2020-06-13 19:35:28


## Signup for Ionic #ioniconf2020 

A one day, single-track online event celebrating the future of cross-platform app development — and the developer community powering the movement.

June 24, 2020

 - I will be speaking about state management in ReactJS using the Context API

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


https://ionicframework.com/ioniconf
What projects should somebody have and experience to be a senior?
Tags: discuss, healthydebate, webdev, career
Published: 2020-06-13 19:08:47

Hi everyone,

What projects(any language) should somebody have to be considered:

- junior?

- mid-level?

- senior?

- senior ahitect?

- tech lead?

Thanks in advance

Credits:
Thinking statue [link](![Thinking statue](https://www.google.com/url?sa=i&url=https%3A%2F%2Fpxhere.com%2Fen%2Fphoto%2F1089623&psig=AOvVaw01zcaSKpz4ZGUl4yqQRWc1&ust=1592161776535000&source=images&cd=vfe&ved=0CAIQjRxqFwoTCNCo6vq-_-kCFQAAAAAdAAAAABAE))
Making EDA easy
Published: 2020-06-13 18:57:01

A package has recently come to my attention that makes performing a blanket EDA of a new dataset easier. This package is pandas_profiling.
To install the package the command is 
```
pip install pandas-profiling[notebook]
```
So what does it do?
These points were taken from the documentation [here](https://pandas-profiling.github.io/pandas-profiling/docs/master/rtd/)

-Type inference: detect the types of columns in a dataframe.
-Essentials: type, unique values, missing values
-Quantile statistics like minimum value, Q1, median, Q3, maximum, range, interquartile range
-Descriptive statistics like mean, mode, standard deviation, sum, median absolute deviation, coefficient of variation, kurtosis, skewness
-Most frequent values
-Histograms
-Correlations highlighting of highly correlated variables, Spearman, Pearson and Kendall matrices
-Missing values matrix, count, heatmap and dendrogram of missing values
-Duplicate rows Lists the most occurring duplicate rows
-Text analysis learn about categories (Uppercase, Space), scripts (Latin, Cyrillic) and blocks (ASCII) of text data

All this is done with one command 
```python
from pandas_profiling import ProfileReport
ProfileReport(df, title="Pandas Profiling Report")
```
df in the above code being a Pandas DataFrame object.

If you have a large dataset (1000000,20) you may be better served by passing the kwarg
```python
ProfileReport(large_dataset, minimal=True)
```
So while good knowledge of your data is ideal, I think pandas_profile is a good first step to building that knowledge.