Microsoft azure – WordPress hosting tuning

How to configure rewrite rules:

It’s necessary to connect via FTP to azure VM and update ftp://host/site/wwwroot/web.config file.

<rewrite>
			<rules>
				<rule name="Rewrite tcS3_media">
					<match url="^tcS3_media/(.*)" />
					<action type="Redirect" url="http://downloads.vodnici.net/{R:1}" appendQueryString="false" redirectType="Permanent" />
				</rule>
			</rules>
		</rewrite>

How to migrate other blogs to WordPress on Azure

 Mass delete all images from media library

  • install SQL Executioner
  • run DELETE FROM `wp_posts` WHERE `post_type` = “attachment”

Update Samsung Galaxy S3 – I9300 to Android 5.0.3 Lollipop

Step by step for installation

Rom managers

Root telefon

Clockwork mod

Enable debugging

Android SDK

Other

CyanogenMod 

Disable sudo password on Jenkins build machines

edit file sudoers

sudo nano /etc/sudoers

or

sudo visudo

and modify

%sudo ALL=(ALL) ALL

to

%sudo ALL=(ALL) NOPASSWD: ALL

and add following line to the end of the file:

user ALL=NOPASSWD: ALL

Be careful!

When editing sudoers, it’s necessary to be very careful. Any error cause that you will not be able to edit this file anymore and also not to use sudo ;-).

Here are links how to fix it (verified 😉 )

Remote links

Autossh forward ports to whole network

Use -g swith after -L section to forward ports to whole network

autossh -M 40008 -f -N user@server -L 33061:127.0.0.1:3306 -g -L 6380:127.0.0.1:6380 -o "ServerAliveInterval 60" -o "ServerAliveCountMax 3" -o BatchMode=yes -o StrictHostKeyChecking=no -i /root/.ssh/id_rsa

Other notes

Configuration file : /etc/init/autossh.conf

Start service:

sudo service autossh start

 

Other links

Enabling SSL on Mongoose http server

 

 

pstrReturn = mg_set_option(serverHttps, "listening_port", "ssl://443:ssl.pem");  // Open port 443 with ssl.pem certificate

 

# openssl version
OpenSSL 1.0.0-beta2 21 Apr 2009

# openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 1000 -nodes

# cat key.pem > ssl.pem; cat cert.pem >> ssl.pem

Testing mongoose server via command line (curl), Switch -k allow to use self-signed certificates.

curl -X OPTIONS --header "Access-Control-Request-Method:GET" --header "Access-Control-Request-Headers: accept, x-coral-api-key" https://server.a18/v1/service/method -k

UML tools and c++ code generators

List of UML modellers

UML tools

Windows 8.1 tuning (to look and behave like win7)

Use Windows 8.1 in default configuration as developer machine is hell on the earth. So, here are the steps how to turn Windows 8.1 back to classic…

 

  • Configure your user as TRUE administrator (link)
  • Replace metro by classic start menu (link)
  • split monitor to more areas (WinSplit revolution, alternative ownload link)
  • Windows firewall extension to notify about outgoing connections (link)
  • Disable local http server on port 80 (after visual studio installation!!) (link) HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\HTTP\start =  4
  • Enable administrative sharing for c$,d$, … (superuserHKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\LocalAccountTokenFilterPolicy=
  • Disable top left/right corner clip HKEY_CURRENT_USER\Control Panel\Desktop\MouseCornerClipLength=0

Qt5 application hangs-up when QNetworkAccessManager and QEventLoop is used on Mac OS

To be more specific, problem occurs only in very specific circumstances. It’s in situation, when application is compiled as console-app and it’s compiled on Mac OS X version older than 10.9:

CONFIG -= gui
CONFIG -= console

and when you’re using QEventLoop::exec in mode processing all events except user events (QEventLoop::ExcludeUserInputEvents):


//it's only demonstration, not full code...
QNetworkAccessManager manager; ...
QNetworkRequest request; ...
QNetworkReply *reply = manager->post(request,arData);
...

eventLoop.exec(QEventLoop::ExcludeUserInputEvents);

In this situation, application hangs-up. When the application is compiled with GUI mode or when application is compiled on Linux/Windows (no matter if gui or console), everything works find. To fix this problem, it’s necessary to implement hack similar to this (simplified version):

   bool bAllowUserInputEvents = false;

#if defined(PLATFORM_MACOS) && defined(AX_APP_CONSOLE)
   bAllowUserInputEvents = true;
#endif

  if ( bAllowUserInputEvents == false )
    eventLoop.exec(QEventLoop::ExcludeUserInputEvents);
  else
    eventLoop.exec(QEventLoop::AllEvents);

Qt5 application crashed with error 0xc0000005

This is very interesting crash and I think it should be considered as Qt bug. This problem arise only under very special circumstances. But one after another.

You will identify this problem when your application stopped/exited immediately after the start without any visible error message. It looks like the application isn’t executed at all. When you check application log (Computer -> manage -> Event viewer -> Windows logs -> Application), you will see Error logs:

Windows applications logs

The most interesting part of this log is crash location: ntdll.dll

Faulting application name: Skipper.exe, version: 3.0.1.1120, time stamp: 0x53e9c8d7
Faulting module name: ntdll.dll, version: 6.1.7601.18247, time stamp: 0x521ea8e7
Exception code: 0xc0000005
Fault offset: 0x0002e3be
Faulting process id: 0x1c88
Faulting application start time: 0x01cfb606553e594b
Faulting application path: T:\S2\Skipper.exe
Faulting module path: C:\Windows\SysWOW64\ntdll.dll
Report Id: 98cc8228-21f9-11e4-ab5d-005056c00008

At first sight it seems like some problem inside the windows. But the opposite is true, the problem (as almost always) is inside your app ;-).

As the next step, you can try to debug this executable via Visual Studio to see what happens inside. Simply open executable as project together with .pdb files and execute it. Now you can see that application is correctly executed but crashes as soon as it touches Qt library. The location of crash is inside ntdll.dll in RtlHeapFree() function.

Debuging crash in VisualStudio 2013

So the problem is inside the Qt, right? Almost true, but not for the 100%. When I tried to run this application on computers of my colleagues, everything works ok. So why the application doesn’t work on my computer too?

Resolution

The problem is in new Qt5 plugin system. Besides the common Qt5*.dll files which are loaded immediately after the application start, Qt5 is also loading plugins/platform-plugins dynamically when the application is executed. To locate this plugins, Qt5 uses following method to identify directories where to search for plugins:

QStringList QCoreApplication::libraryPaths()

For some strange reason this library returns as first directory path where Qt5 libraries were compiled and after that location based on the executable. So if your Qt5 path is C:\Qt5, this will be the first path where all plugins are searched for, no matter if the correct version of plugin is located in APP\plugins or APP\platforms. I think this is serious bug in Qt5.

Where is the problem?

And here we’re getting to the core of the whole problem.

If application is compiled on computer with one compiler and used on second  computer which contains the same path to which original computer has installed Qt, the application will load all plugins from your folder instead of itself folder.

In case your computer will contain different version of Qt, different compiler or different platform, application loads incorrect libraries and crashes. Completely, silently and without easy way to determine what’s wrong.

Solution?

The solution is simple, but it isn’t achievable from outside of the Qt library. It would be necessary to Qt as first tried to load libraries from application directory. And only if no plugins were found in application directory, the application would try to search for plugins in Qt directory.

Qt change solution

The simplest way how to fix this issue inside the Qt library would be to rename/update appendApplicationPathToLibraryPaths  function to prependApplicationPathToLibraryPaths and change

void QCoreApplicationPrivate::prependApplicationPathToLibraryPaths()
{
#ifndef QT_NO_LIBRARY
    QStringList *app_libpaths = coreappdata()->app_libpaths;
    if (!app_libpaths)
        coreappdata()->app_libpaths = app_libpaths = new QStringList;
    QString app_location = QCoreApplication::applicationFilePath();
    app_location.truncate(app_location.lastIndexOf(QLatin1Char('/')));
#ifdef Q_OS_WINRT
    if (app_location.isEmpty())
        app_location.append(QLatin1Char('/'));
#endif
    app_location = QDir(app_location).canonicalPath();
    if (QFile::exists(app_location) && !app_libpaths->contains(app_location))
        //CHANGE THIS ROW: app_libpaths->append(app_location);
        //TO FOLLOWING
        app_libpaths->prepend(app_location);
#endif
}

InApp solution

Unfortunately it isn’t possible to simply change this behavior from your app. All of these operations happen directly in QCoreApplication constructor so if you try to change it after, it’s too late.

The temporary solution before this problem will be resolved is to reinitialize library paths before QCoreApplication is initialized. It’s necessary to clean libray paths, compute new paths and re-initialize QCoreApplication::libraryPaths before QCoreApplication object is initialized. This can be done in main.cpp of your application before you will create QApplication/QCoreApplication object.

  QString executable = argv[0];
  QString executablePath = executable.mid(0,executable.lastIndexOf("\\"));
  QString installPathPlugins = QLibraryInfo::location(QLibraryInfo::PluginsPath);
  QCoreApplication::removeLibraryPath(installPathPlugins);
  QCoreApplication::addLibraryPath(installPathPlugins);
  QCoreApplication::addLibraryPath(executablePath);

It’s not a nice solution, but it works. I tried  to report this issue also to bugreports.QtProject, so maybe in later version this will be fixed.

How to create .pdb files also for Release version of Qt library

For debugging purposes it’s a good idea to keep .pdb files also for release version of your libraries. Unfortunately in default configuration Qt library doesn’t generate .pdb files. It’s a not big deal, create .pdb files for release version it’s pretty simple.

1) Add compilation flags to .pro file

The easiest way how to create pdb files is pass /Zi switch to compiler and /Debug to linker.

QMAKE_CXXFLAGS+=/Zi
QMAKE_LFLAGS+= /INCREMENTAL:NO /Debug

2) Solution via mkspec

As pointed out in this QtProject article, another way is to edit mkspec so any future compilations will have this option turned on. It’s necessary to modify correct mkspec file, for example

Qt</span>\mkspecs\win32-msvc2005\qmake.conf

and add following lines (it should be sufficient to add only /Zi and /Debug switch):

QMAKE_CFLAGS_RELEASE += /Zi
QMAKE_LFLAGS_RELEASE += /INCREMENTAL:NO /DEBUG