Symple JavaScript applet.

Simple JavaScript applet to do some calculations in a webpage:

```html
	<br />
	This is a JS applet example.<br />
	<br />
	Set "A" value and choose "Multiplier".<br />
	<br />
	Click on "Calculate" to perform the operation.<br />
	<br />
	<hr />
	<br />
	<div>
	  <script>

		function mult(form)
		{
		  var valA = form.A.value;
		  var valM = form.M.value;
		  
		  form.AxM.value = valA*valM;
		}
	  </script> <br />
	<br />
	<form name="multiply">
	<br />
	Number A: <input name="A" style="background-color: white; width: 100px;" value="0" /><br />
	<br />
	Multiplier : <select name="M" style="background-color: white; width: 100px;" value="2">
					 <option value="2">x2</option>
					 <option value="4">x4</option> </select> <br />
	<br />
	<input name="Calc" onclick="mult(this.form)" style="width: 100px;" type="button" value="Calculate" />  <br />
	<br />
	<hr />
	<br />
	A x Multiplier = <input name="AxM" style="width: 95px;" value="" /> <br />
	<br />
	<br />
	<br /></form>
	</div>
```


This is how it looks:
--------------------------------------------------

This is a JS applet example.

Set "A" value and choose "Multiplier".

Click on "Calculate" to perform the operation.






Number A:

Multiplier :





A x Multiplier =



Integer to any base QString

This function takes an integer and returns a QString with the representation in any base < 16.

It uses the val2hex function from previous post:
.....................................................................................................
```c
QString val2hex( int d )
{
    QString Hex="0123456789ABCDEF";

    QString h = Hex.mid( d&15, 1 );

    while( d>15 )
    {
        d >>= 4;
        h = Hex.mid( d&15,1 ) + h;
    }
    return h;
}

QString decToBase( int value, int base, int digits )
{
    QString converted = "";

    for( int i=0; i= base ) converted = val2hex(value%base) + converted;
        else                converted = val2hex(value) + converted;

        value = floor( value/base );
    }
    return converted;
}
```
.....................................................................................................

Integer to Hex QString

This function takes an integer and returns a QString with the exadecimal representation:
.....................................................................................................
```c
QString val2hex( int d )
{
    QString Hex="0123456789ABCDEF";

    QString h = Hex.mid( d&15, 1 );

    while( d>15 )
    {
        d >>= 4;
        h = Hex.mid( d&15,1 ) + h;
    }
    return h;
}
```
.....................................................................................................

File to QString

Read a file and parse whole content to a QString:
.....................................................................................................
```c
QString fileToString( const QString &fileName, const QString &caller )
{
    QFile file( fileName );

    if( !file.open(QFile::ReadOnly | QFile::Text))
    {
        QMessageBox::warning( 0l, caller, 
                              "Cannot read file "
                              +fileName+":\n"
                              +file.errorString());
        return "";
    }

    QTextStream in( &file );
    QString text = in.readAll();
    file.close();

    return text;
}
```
.....................................................................................................

File to QStringList

Read a file and parse each line to a QStringList:

.....................................................................................................

```c
QStringList fileToStringList( const QString &fileName, const QString &caller )
{
    QStringList text;
    QFile file(fileName);

    if( !file.open( QFile::ReadOnly | QFile::Text) )
    {
        QMessageBox::warning( 0l, caller, 
                              "Cannot read file "
                              +fileName+":\n"
                              +file.errorString());
        return text;
    }

    QTextStream in( &file );
    while( !in.atEnd() ) text.append( in.readLine() );
    file.close();

    return text;
}
```

.....................................................................................................

Add entry to QListWidget and resize to content

Sometimes is useful resizing a QListWidget to the size of its content.
This is one way to do it.

Don't forget resizing again when you remove an item.

.....................................................................................................

```c
void addEntry( QString name, QListWidget* list )
{
    QListWidgetItem* item = new QListWidgetItem( name, list, 0 );
  
    QFont font;
    font.setPointSize(10);
    font.setWeight(70);
    item->setFont( font );

    item->setIcon( QIcon(":/icon.png") );
       
    int iconSize = 22;                       // I know icon size

    int size = list->count()*iconSize + 2;

    list->setFixedHeight( size );
}
```

.....................................................................................................

Wemos to InfluxDB via Wifi

This is a simple example of how to send data from a Wemos board to InfluxDB  throught wifi.

Tested with Wemos D1 R2 and Arduino IDE.

You should change ssid, password to your wifi.
Also InfluxDB database name and data you are using.

.....................................................................................................

```c
#include <Arduino.h>

#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>
#include <ESP8266HTTPClient.h>

#define USE_SERIAL // Comment this line for no serial

const char* ssid = "Your_SSID";
const char* password = "Your_Pass";

ESP8266WiFiMulti WiFiMulti;

void setup()
{
    #ifdef USE_SERIAL
    Serial.begin( 115200 );
    #endif

    WiFi.mode( WIFI_STA );
    WiFiMulti.addAP( ssid, password );
}

void loop()
{
    if( WiFiMulti.run() == WL_CONNECTED ) // wait for WiFi connection
    {
        int sensorValue = analogRead( A0 );
       
        // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 3.2V):
        float voltage = sensorValue * (3.2/1023.0);
       
        #ifdef USE_SERIAL
        Serial.println( voltage );
        #endif
       
        HTTPClient http;

        #ifdef USE_SERIAL
        Serial.print( "[HTTP] begin...\n" );
        #endif
       
        // Start writting to influxbd database: mydb
        // Set database, IP and Port you are using
        http.begin( "http://192.168.1.33:8086/write?db=mydb" );
  
        // Send data to influxbd
        // Set data you are using
        int httpCode = http.POST( "Volts,Bat=Lead-Acid,Ser=pruebas value="+String(voltage) );
       
        #ifdef USE_SERIAL
        if(httpCode == 204) // Data Succesfully Written
        {
            Serial.printf( "Data Succesfully Written... code: %d\n", httpCode );

        }
        else // Data Failed
        {
            Serial.printf( "Data Failed... code: %d\n", httpCode );
            Serial.printf( "Error: %s\n", http.errorToString(httpCode).c_str() );
        }
        #endif
       
        http.end();
    }

    delay( 10000 ); // Wait for 10 seconds
}
```

.....................................................................................................

Fast linked list without list

If you need a very fast way to iterate over a list of objects and call the same method on all of them, then here is a posible solution. Der...