How to upload files to a web app using App Inventor

When you want to create an app that points to an existing website, a web app can be the right solution, and the App inventor tool made available by MIT makes the creation of this kind of app very easy.
However, the basic mechanism of the App Inventor web app allows only to read the content of the and not to upload or download files. To fix this situation, an extension called CustomWebView has been made available, which allows files to be downloaded and uploaded.

To download CustomWebViewer extension simply click the download button on the Github page. You will obtain back an *.aix file, that is the extension. To install it, simply click “Import extension” at the bottom of the left menu in App Inventor, like showed in image. This is the standard way to import almost all the extensions.

Then simply drag the installed extension in to the interactive screen of App Inventor, like you do with all other objects.

Components

In our main screen (named “Screen1“) we’ll have a Vertical Arrangment container, an Activity Starter and a Sound Recorder.

Blocks

Let’s look to the blocks now. We’ll grant read permissions to read files. Then we create a web app view using CustomWebView, and we put the web app in to a vertical container. We then set file access to true, and let the web app connect to the desired website.

In a second block we specify what to do when we click an upload button on our webapp. We call an activity , specify data type and start the activity.

In the third and last block we tell what to do when the activity is started: call a file upload a set the path of the file as a result. Doing that way we’ll be able to upload our files in to our web app.

How to bulk publish or bulk delete pending posts in WordPress

Do you have many posts to edit on your WordPress website and you do not know how to do it? Actually, the WordPress editor doesn’t offer much in bulk editing: it only allows you to edit 10 posts at a time. Therefore, when there are a lot of pending posts to publish or delete this can be a problem. There is, anyway, a quick way to bulk edit posts.

Bulk edit from PhpMyAdmin

As you all know WordPress is a CMS that is installed on your server and which put the data in a database. Therefore you just have to go to the control panel (usually Cpanel) of your hosting provider and search PhpMyAdmin in the search bar (PhpMyAdmin is the app controlling databases of your sites, so we are going to bulk delete posts directly from there). So enter in PhpMyAdmin and search the database of your WordPress site (usually there is one database for each one of your WordPress websites). Once found the database containing your website posts you will find there are many tables in it. You should click in the one named “wp_posts” or “wpkn_posts”. In that table you will find the list of your wordpress posts and their current status, if published, pending or draft.

click to enlarge

So let’s do some edit. Click on the button SQL from the menu at the top of the page (see previous image to find it).

So once clicked, run this code in the white table:

UPDATE wpkn_posts (or wp_posts) SET post_status = ‘publish’ WHERE post_status = ‘pending’

in the case you want to bulk publish many posts.

When you want to bulk delete many posts run this other code:

DELETE FROM wpkn_posts (or wp_posts) WHERE post_status = ‘pending’  (or ‘publish’, or ‘draft’)

Calcolare la distanza euclidea tra due sequenze numeriche in php

In questo articolo calcoliamo la distanza euclidea di due serie numeriche molto semplici:

A (0,1,0)

B (0,5,10)

La distanza euclidea ci dice quanto le due serie sono simili tra di loro. Nel caso in cui il risultato è zero,le due serie sono uguali. Più la distanza euclidea è maggiore, più le due serie differiscono.

In php definiamo le serie come array:

$seqA=array(10,1,0);
$seqB=array(0,5,10);

Possiamo stampare uno qualsiasi dei valori degli array indicando il numero tra parentesi quadre accanto alla sequenza: Se per esempio vogliamo mostrare il primo valore della sequenza A, dobbiamo chiamare il valore 0 (cioè il primo valore) dell’array seqA.

echo $seqA[0] darà come risultato 10.

Ora stabiliamo delle coppie di array per ogni valore numerico (3) degli array di partenza:

$arraycoppia1= array($seqA[0],$seqB[0]);
$arraycoppia2= array($seqA[1],$seqB[1]);
$arraycoppia3= array($seqA[2],$seqB[2]);

Modifichiamo l’ordine dei valori degli array in base alla grandezza:

sort($arraycoppia1);
sort($arraycoppia2);
sort($arraycoppia3);

Ora calcoliamo le singoli distanze euclidee per ogni valore degli array coppia:

$de1=$arraycoppia1[1]-$arraycoppia1[0];
$de2=$arraycoppia2[1]-$arraycoppia2[0];
$de3=$arraycoppia3[1]-$arraycoppia3[0];

Per trovare la distanza euclidea tra i due array di partenza basta sommare le distanze euclidee singole:

$de= $de1+$de2+$de3;

Per trovare la distanza euclidea tra sequenze lunghe:

$seqA=array(0,1,0,5,4,…,n);
$seqB=array(0,5,10,4,5,..,n);

for($x = 0; $x <= 5; $x++) {

if(isset($de0)){

}else{ $de0 = 0;
}

$arraycoppia= array($seqA[$x],$seqB[$x]);
sort($arraycoppia);
$de= $arraycoppia[1]-$arraycoppia[0];
$de1=$de+$de0;
$de0=$de1;

}

echo $de1;