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.
Derive your objects from this class and implement doSomething():

class Element
{
    public:
        Element();
        ~Element();

        virtual void doSomething()=0;

        Element* next;

        static void addElement( Element* el )
        {
            el->next = first;
            first = el;
        }

        static Element* first=nullptr;
};

And to use it:

    // Adding one element to the list:
    Element::addElement( &myObject );

    // Iterating over the objects:
    Element* el = Element::first;
    while( el )
    {
        el->doSomething();
        el = el->next;
    }


Find file in folder recursive with Qt.


This function returns the absolute path of a file in a folder (or subfolder).
It searchs recursively in all subfolders until it finds the file or return an empty QString if the file is not found.


QString findFile( QString dir, QString fileName )
{
    QDir pathDir( dir );
    for( QFileInfo fileInfo : pathDir.entryInfoList() )
    {
        if( fileInfo.isFile() )
        {
            if( fileInfo.fileName() == fileName ) 
                return fileInfo.absoluteFilePath();
        }
        else if( !fileInfo.fileName().endsWith(".") )
        {
            QString found = findFile( fileInfo.absoluteFilePath(), fileName );
            if( !found.isEmpty() ) return found;
        }
    }
    return "";
}



Connect QObject signal to non QObject class.

Usually you need to derive from QObject and use the Q_OBJECT macro to connect to some slot in your class.
But sometimes you want to connect a QObject signal to do something in a non QObject class.

There are several posible reasons to not derive from QObject or use the Q_OBJECT macro, but in any case you can connect to a non QObejct class using lambdas:

```c
  // Connect to menu action

  QMenu* menu:

  QAction* myAction = menu->addAction( QIcon(":/myIcon.svg"), "Do something" );

  QObject::connect( myAction, &QAction::triggered, [=](){ myFuncion(); });



  // Connect to QPushButton

  QPushButton* button = new QPushButton();

  QObject::connect( button, &QPushButton::released, [=](){ onButtonReleased(); });
```


Submenu in a QMenu.

Adding a submenu to a QMenu is really easy, and you add nested submenus if you want:
```c
	QMenu* mainMenu;
	
	QAction* action1 = mainMenu->addAction(QIcon(":/icon1.png"),"Entry1" );
    connect( action1, &QAction::triggered,
                this, &MyClasss::mySlot1, Qt::UniqueConnection );

    QAction* action2 = mainMenu->addAction(QIcon(":/icon2.png"), "Entry2" );
    connect( action2, &QAction::triggered,
                this, &MyClasss::mySlot2, Qt::UniqueConnection );

	// --- SUBMENU --------------------------------------------------------
	
	QMenu* subMenu = mainMenu->addMenu( QIcon(":/menuIcon.png"), "SubMenu Title" );
	
	QAction* subAction1 = mainMenu->addAction(QIcon(":/subIcon1.png"),"subEntry1" );
    connect( subAction1, &QAction::triggered,
                   this, &MyClasss::subSlot1, Qt::UniqueConnection );

    QAction* subAction2 = mainMenu->addAction(QIcon(":/subIcon2.png"), "subEntry2" );
    connect( subAction2, &QAction::triggered,
                   this, &MyClasss::subSlot2, Qt::UniqueConnection );

	// --------------------------------------------------------------------
	
	
	QAction* action3 = mainMenu->addAction(QIcon(":/icon3.png"),"Entry3" );
    connect( action3, &QAction::triggered,
                this, &MyClasss::mySlot3, Qt::UniqueConnection );

    QAction* action4 = mainMenu->addAction(QIcon(":/icon4.png"), "Entry4" );
    connect( action4, &QAction::triggered,
                this, &MyClasss::mySlot4, Qt::UniqueConnection );
```

Simple and fast signal-slot system in C++.

 This is a simple and fast implementation of a signal-slot system in C++.

It's goal is to be simple and as fast as possible.

For that, we create a signal-slot system tha is specific for our use case, that's the price we pay for a fast system.
In this case we create callbacks that take an integer value, but it could be adapted for any oyhter use case.

First we need a base class for our callbacks.
We need this class to virtualize the call() function and easily link callbacks in order to create a list.
It is implemented as a linked list: each callbacks holds a pointer to the function to call and a pointer to the next callback.

```c
class CallBackBase
{
    public:
        CallBackBase(){;}
        virtual ~CallBackBase(){;}

        virtual void call( int ){;}

        CallBackBase* nextCallBack;
};
```

Here we have our callback class.
We create callbacks with an object and a member funtion to call:
```c
template <class Obj>
class CallBack : public CallBackBase
{
        friend class Signal;

    public:
        CallBack( Obj* object, void (Obj::*func)(int) )
        : CallBackBase()
        {
            m_object = object;
            m_func   = func;
            nextCallBack = 0;
        }
        ~CallBack() {;}

        virtual void call( int val ) override
        { (m_object->*m_func)(val); }

    private:
        Obj* m_object;
        void (Obj::*m_func)(uint8_t);
};
```

And this is our signal class:
We can add callbacks with the function connect() and remove callbacks with the function disconnect().
On emitValue() we call all the callbacks with an integer value as argument:

```c
class Signal
{
    public:
        Signal()
        {
            m_slot = 0;
        }
        ~Signal()       // Free resources created
        {
            CallBackBase* slot = m_slot;
            while( slot ) // delete slots
            {
                CallBackBase* slotDel = slot;
                slot = slot->nextCallBack;
                delete slotDel;
        }   }

        template <class Obj>
        void connect( Obj* obj, void (Obj::*func)(int) )
        {
            CallBack<Obj>* slot = new CallBack<Obj>( obj, func );

            slot->nextCallBack = m_slot;
            m_slot = slot;
        }

        template <class Obj>
        void disconnect( Obj* obj, void (Obj::*func)(int) )
        {
            CallBackBase* preSlot = 0;
            CallBackBase* posSlot = m_slot;
            while( posSlot )
            {
                CallBack<Obj>* cb = dynamic_cast<CallBack<Obj>*>(posSlot);

                if( cb->m_object == obj && cb->m_func == func )
                {
                    if( preSlot ) preSlot->nextCallBack = posSlot->nextCallBack;
                    else          m_slot = posSlot->nextCallBack;
                    delete posSlot;
                    break;
                }
                preSlot = posSlot;
                posSlot = posSlot->nextCallBack;
        }   }

        void emitValue( int val ) // Calls all connected CallBacks 
        {
            CallBackBase* slot = m_slot;
            while( slot )
            {
                slot->call( val );
                slot = slot->nextCallBack;
        }   }

    private:
        CallBackBase* m_slot;
};
```

To use it we create signals, connect callbacks and call emitValue() when needed.

```c
	AnObjectClass*    anObject     = new AnObjectClass();
	OtherObjectClass* otherObject  = new OtherObjectClass();
	ThirdObjectClass* thirdObject  = new ThirdObjectClass();
	OtherObjectClass* otherObject2 = new OtherObjectClass();

    Signal on_write;
    on_write.connect( anObject,    &AnObjectClass::writeFunc );
    on_write.connect( otherObject, &OtherObjectClass::otherFunc );
    
    Signal on_read;
    on_read.connect( thirdObject,  &ThirdObjectClass::readFunc );
    on_read.connect( otherObject2, &OtherObjectClass::someFunc );
    
    
    void on_write_event( int value )
    {
		on_write.emitValue( value );
	}
	
	void on_read_event( int value )
	{
		on_read.emitValue( value );
	}
```

C++ Pointer to member Function.

```c
// Create a data type: "Pointer to MyClass function" with type name: "funcPtr_t"
typedef void (MyClass::*funcPtr_t)();

QList funcList;           // Create a list of pointers

funcPtr_t fp = &MyClass::myFunction; // Create a pointer to function "myFunction" with name "fp"

funcList.append( fp );               // Add to list

for( funcPtr_t func : funcList)      // Call all functions in our list (there is only one)
{
	(this->*func)();                 // We are calling from an object of the same class
}

// ---------------------------------------------------------------------------------------------

Myclass myObject;

for( funcPtr_t func : funcList)      // Call all functions in our list (there is only one)
{
	(myObject.*func)();              // We are calling from outside "MyClass"
}

	// ---------------------------------------------------------------------------------------------

Myclass* myObject = new Myclass();

for( funcPtr_t func : funcList)      // Call all functions in our list (there is only one)
{
	(myObject->*func)();             // We are calling from outside "MyClass"
}
```

Bash script to create gif from ogv video

Adjust FPS to your needs.

If you save it as "ogvtogif" use like this:

$ ogvtogif file.ogv

_____________________________________________________________
#!/bin/bash

INPUT_FILE=$1
FPS=8

TEMP_FILE_PATH="tmp.png"

ffmpeg -i $INPUT_FILE -vf fps=$FPS,palettegen $TEMP_FILE_PATH
ffmpeg -i $INPUT_FILE -i $TEMP_FILE_PATH -loop 0 -filter_complex "fps=$FPS,paletteuse" $INPUT_FILE.gif

rm $TEMP_FILE_PATH
_____________________________________________________________

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;
}
```
.....................................................................................................

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...