Limit per request bandwidth using Apache 2.4

Apache 2.4 has a module called mod_ratelimit. This module gives you the ability to limit the bandwidth of your requests posted to the web server. The usage is quite simple (read the docs):

First load the module (Apache 2.4 on FreeBSD). Uncomment following line in /usr/local/etc/apache24/httpd.conf

LoadModule ratelimit_module libexec/apache24/mod_ratelimit.so

This will load the module during next startup. Now how do i use it? Well, let's say you want the whole server to limit every request to 5MB/s, then use this:

<IfModule mod_ratelimit.c>
    SetOutputFilter RATE_LIMIT
    SetEnv rate-limit 5120
</IfModule>

The same can be applied to only specific directories if you need to:

<IfModule mod_ratelimit.c>
    <Location "/downloads">
        SetOutputFilter RATE_LIMIT
        SetEnv rate-limit 5120
    </Location>
</IfModule>

Last step, as apache needs to load a new module, restart your webserver, not reload:

# service apache24 restart

Enabling shared folders with open-vm-tools

First install following package  when using Ubuntu:

sudo apt-get install open-vm-tools-desktop

Manual mountafterwards:

sudo mount -t fuse.vmhgfs-fuse .host:/ /mnt/hgfs -o allow_other

Auto-mount at startup (/etc/fstab):

.host:/ /mnt/hgfs fuse.vmhgfs-fuse allow_other 0 0

Fixing PyInstaller on OSX when using PySide

When using PyInstaller to package my PySide application  i had following errors in the command-line:

3513 INFO: Looking for dynamic libraries
3663 ERROR: Can not find path ./libpyside-python2.7.1.2.dylib (needed by /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PySide/QtGui.so)
3664 ERROR: Can not find path ./libshiboken-python2.7.1.2.dylib (needed by /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PySide/QtGui.so)
3670 ERROR: Can not find path ./libpyside-python2.7.1.2.dylib (needed by /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PySide/QtNetwork.so)
3670 ERROR: Can not find path ./libshiboken-python2.7.1.2.dylib (needed by /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PySide/QtNetwork.so)
3680 ERROR: Can not find path ./libpyside-python2.7.1.2.dylib (needed by /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PySide/QtCore.so)
3680 ERROR: Can not find path ./libshiboken-python2.7.1.2.dylib (needed by /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PySide/QtCore.so)

My application did start on my own machine but not on others where PySide was not installed. Here is a simple fix which worked for me to get my app running on another mac:

Open following file:

/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PyInstaller/depend/bindepend.py

and look for the function _getImports_macholib()… inside that function find following loop:

# Try multiple locations.
for run_path in run_paths:
    # @rpath may contain relative value. Use exec_path as
    # base path.
    if not os.path.isabs(run_path):
        run_path = os.path.join(exec_path, run_path)
    # Stop looking for lib when found in first location.
    if os.path.exists(os.path.join(run_path, lib)):
        final_lib = os.path.abspath(os.path.join(run_path, lib))
        rslt.add(final_lib)
        break

and change the loop to

# Try multiple locations.
for run_path in run_paths:
    # @rpath may contain relative value. Use exec_path as
    # base path.
    if not os.path.isabs(run_path):
        run_path = os.path.join(exec_path, run_path)
    # Fix path problems for PySide install on OSX
    if "PySide" in run_path:
        run_path = run_path.replace("../../../", "") 
    # Stop looking for lib when found in first location.
    if os.path.exists(os.path.join(run_path, lib)):
        final_lib = os.path.abspath(os.path.join(run_path, lib))
        rslt.add(final_lib)
        break

That's it, save the file and package your app. For me that fixed all other errors.

Here my setup when fixing: PySide 1.2.4 (PyPi), Qt 4.8.7 (stock binary), Python 2.7.12, PyInstaller 3.3-dev

Happy coding.