Haxe: Setting up hx-debugger in a .hxp project file

Enabling hxcpp debugging in a haxe or openfl project is easy if you use the standard xml project file. It’s also no rocket science to activate it in a .hxp file, just undocumented.

Here’s a quick example on how to enable the haxe debugger:

haxelibs.push(new Haxelib("hxcpp"));
haxedefs.set("HXCPP_CHECK_POINTER",1);
haxeflags.push("-D HXCPP_DEBUGGER");
haxelibs.push(new Haxelib("debugger"));
haxeflags.push ("-debug");

Tested on Windows but should work on any platform or system that’s using hxcpp.

Problem/Fix: Using the PHP header() function in Fat Free Framework (F3) has no effect, it stil outputs “text/html”

If you use the Fat Free Framework to deliver javascript, you need to set the contents mime type to ‘application/javascript’ (‘text/javascript for IE 8 and previous versions).

You tried to use PHPs header() function to do so but the header type still is wrong.

How not to set the headers mime type for F3 Views

header('Content-Type: application/javascript');
echo View::instance()->render('profile_js.js');

How to set the header mime type using Fat Free Framework

The reason for the wrong mime type most likely is the script calling View->render() which has a single parameter in most but examples but also has an optional second parameter to pass the mime type. This parameter defaults to text/html, the call will overwrite the previously set header. If you set the second parameter the mime type will be correctly output:

echo View::instance()->render('profile_js.js','application/javascript');

Officials documentation on setting the header mime type in Fat Free Framework

http://fatfreeframework.com/views-and-templates#AllKindsofTemplates

Adding library (swf) using haxe/openfl project.hxp

I was getting tired of using Haxe/OpenFL’s application.xml file because it was too unflexible for what I needed to do. I did some research and noticed that you now can actually write real build scripts using the Haxe language.

The process was easy and straight forward since the new building scripts are documented well:

http://www.openfl.org/documentation/projects/project-files/hxp-format/

The only thing these docs missed was the informations on how to actually add a swf library using the HXP build script. To figure that I checked the source of the new build system. It’s part of lime-tools, so that’s where I had to take a look:

https://github.com/openfl/lime-tools/blob/master/project/HXProject.hx

Oh, hi there:

	public var libraries:Array<library>;
</library>

(Please ignore the closing library tag, wordpress adds it and I don’t have the time right now to figure out how to change that)

So the libraries get saved in an Library typed Array. That’s easy to handle, take this case:

<library path="assets/swf/library.swf">;
 
</library>

With the new HXP bulding system, that line looks like this:

libraries.push(new Library("assets/swf/library.swf"));

And done. That’s one of the things that I really enjoy about Haxe. If you know where to find your sources, you can easily look everything up yourself. Thanks Haxe/OpenFL team!

Accessing hidden font faces when using BMFont

I’ve needed to create a bitmap font for an OpenFL project with BMFont. The font that I wanted to use was Lithos Black. To my surprise that took a lot of effort.

At first I tried selecting the font face, but BMFont has no way to select a spefic font face. Then I tried the .ttf-File option, but BMFont completely ignores what the user configures as font file, it only uses the selected font.

BMFont groups font faces into a single entry

After some research I realized that BMFont grouped several Lithos font faces into a single entry with no way to select a specific font face.

A simple fix: Deleting unneeded font faces from the windows fonts folder

To fix that I could have deleted all font faces that I didn’t need for the bitmap font. But I didn’t want to constantly change active fonts on my development system just because BMFont lacks in the font face field.

The lesser intrusive method: A virtual machine

In the end I decided to use a blank windows 7 virtual machine. I only installed the font face I needed and BMFont. With just one font there’s no grouping that hides font faces. And thanks to VMWare tools, the whole process is manual but fast and easy. I am not happy that I didn’t find a way to fully automate the process but I rarely need to redo bitmap font files, so decided to work with it for now.

m4s0n501

Can’t backup the mysql table with mysqldump. SELECT,LOCK TABL command denied for ‘cond_instances’

When using mysdqldump to export all databases of a server I ran into the error message “Can’t backup the mysql table with mysqldump. SELECT,LOCK TABL command denied for ‘cond_instances'”.

I checked the tables and noticed that I added a few tables too many into the list of tables to be backed up. I excluded them and the error disappeared.

Here’s a list of the tables that I had to remove:

MySQL Dumper Error

Haxe/OpenFL: Class name must start with uppercase error

A few of my old projects stopped working with the latest version of Haxe 3 and OpenFL 2. This was the error message that I got:

Error: Could not process argument format
Class name must start with uppercase character
Build halted with errors (haxelib.exe).
Done(1)

Of course that error message is not really giving any informations on what’s going wrong. My first idea was that haxelib is being called with invalid parameters making haxelib interprete the parameter as the class name. But a quick check made sure that this wasn’t the cause of the uppercase error message.

I had some other ideas on what could be causing the uppercase error, but none of the things that I tried or looked at changed anything about the error message. Finally I had the idea to compare the applications xml files of projects that still work and those that didn’t.

That led me onto the right path, all the broken projects had this line:

<library path="assets/swf/library.swf"></library>

I outcommented it and the error message was gone.

Fixing 404 errors on all subpages of F3 (Fat Free Framework)

I had some fun figuring out why the Fat Free Framework gave 404 errors on every single page except for the start page when testing the micro frame work on a local windows xampp installation. I expected the problem to related to the .htaccess configuration because logs showed that the file index.php wasn’t called on anything but the web root (/).

The Fat Free Framework .htaccess file

# Enable rewrite engine and route requests to framework
RewriteEngine On
 
# Some servers require you to specify the `RewriteBase` directive
# In such cases, it should be the path (relative to the document root)
# containing this .htaccess file
#
#RewriteBase /
 
RewriteRule ^(lib|tmp)\/|\.(ini|php)$ - [R=404]
 
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L,QSA]
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]

This looks correct, time for some extended debugging.

Debugging Apache’s mod_rewrite using LogLevel

I added this debugging code to the apache virtual host entry:

LogLevel warn mod_rewrite.c:trace6

And took a look at the log again:

[Sun Nov 09 17:45:56.592151 2014] [rewrite:trace4] [pid 10812:tid 1728] mod_rewrite.c(475): [client 127.0.0.1:64913] 127.0.0.1 - - [test.auctions.notboring.org/sid#273fc90][rid#9a1a0e0/initial] [perdir D:/work/projects/auctions/httpdocs/] RewriteCond: input='D:/work/projects/auctions/httpdocs/userref' pattern='!-l' => matched, referer: http://test.auctions.notboring.org/
[Sun Nov 09 17:45:56.592151 2014] [rewrite:trace4] [pid 10812:tid 1728] mod_rewrite.c(475): [client 127.0.0.1:64913] 127.0.0.1 - - [test.auctions.notboring.org/sid#273fc90][rid#9a1a0e0/initial] [perdir D:/work/projects/auctions/httpdocs/] RewriteCond: input='D:/work/projects/auctions/httpdocs/userref' pattern='!-f' => matched, referer: http://test.auctions.notboring.org/
[Sun Nov 09 17:45:56.593151 2014] [rewrite:trace4] [pid 10812:tid 1728] mod_rewrite.c(475): [client 127.0.0.1:64913] 127.0.0.1 - - [test.auctions.notboring.org/sid#273fc90][rid#9a1a0e0/initial] [perdir D:/work/projects/auctions/httpdocs/] RewriteCond: input='D:/work/projects/auctions/httpdocs/userref' pattern='!-d' => matched, referer: http://test.auctions.notboring.org/
[Sun Nov 09 17:45:56.593151 2014] [rewrite:trace2] [pid 10812:tid 1728] mod_rewrite.c(475): [client 127.0.0.1:64913] 127.0.0.1 - - [test.auctions.notboring.org/sid#273fc90][rid#9a1a0e0/initial] [perdir D:/work/projects/auctions/httpdocs/] rewrite 'userref' -> 'index.php', referer: http://test.auctions.notboring.org/
[Sun Nov 09 17:45:56.593151 2014] [rewrite:trace3] [pid 10812:tid 1728] mod_rewrite.c(475): [client 127.0.0.1:64913] 127.0.0.1 - - [test.auctions.notboring.org/sid#273fc90][rid#9a1a0e0/initial] [perdir D:/work/projects/auctions/httpdocs/] add per-dir prefix: index.php -> D:/work/projects/auctions/httpdocs/index.php, referer: http://test.auctions.notboring.org/
[Sun Nov 09 17:45:56.593151 2014] [rewrite:trace2] [pid 10812:tid 1728] mod_rewrite.c(475): [client 127.0.0.1:64913] 127.0.0.1 - - [test.auctions.notboring.org/sid#273fc90][rid#9a1a0e0/initial] [perdir D:/work/projects/auctions/httpdocs/] strip document_root prefix: D:/work/projects/auctions/httpdocs/index.php -> /index.php, referer: http://test.auctions.notboring.org/
[Sun Nov 09 17:45:56.593151 2014] [rewrite:trace1] [pid 10812:tid 1728] mod_rewrite.c(475): [client 127.0.0.1:64913] 127.0.0.1 - - [test.auctions.notboring.org/sid#273fc90][rid#9a1a0e0/initial] [perdir D:/work/projects/auctions/httpdocs/] internal redirect with /index.php [INTERNAL REDIRECT], referer: http://test.auctions.notboring.org/
[Sun Nov 09 17:45:56.593151 2014] [rewrite:trace3] [pid 10812:tid 1728] mod_rewrite.c(475): [client 127.0.0.1:64913] 127.0.0.1 - - [test.auctions.notboring.org/sid#273fc90][rid#3754918/initial/redir#1] [perdir D:/work/projects/auctions/httpdocs/] strip per-dir prefix: D:/work/projects/auctions/httpdocs/index.php -> index.php, referer: http://test.auctions.notboring.org/
[Sun Nov 09 17:45:56.593151 2014] [rewrite:trace3] [pid 10812:tid 1728] mod_rewrite.c(475): [client 127.0.0.1:64913] 127.0.0.1 - - [test.auctions.notboring.org/sid#273fc90][rid#3754918/initial/redir#1] [perdir D:/work/projects/auctions/httpdocs/] applying pattern '^(lib|tmp)\\/|\\.(ini|php)$' to uri 'index.php', referer: http://test.auctions.notboring.org/
[Sun Nov 09 17:45:56.593151 2014] [rewrite:trace2] [pid 10812:tid 1728] mod_rewrite.c(475): [client 127.0.0.1:64913] 127.0.0.1 - - [test.auctions.notboring.org/sid#273fc90][rid#3754918/initial/redir#1] [perdir D:/work/projects/auctions/httpdocs/] forcing responsecode 404 for D:/work/projects/auctions/httpdocs/index.php, referer: http://test.auctions.notboring.org/

The mod_rewrite debug log shows that the rewrite rules are being applied. The first step seems to work: It makes sure the URL doesn’t map to a file, folder or link. Then rewrites it to index.php. All good and nice. But what’s that? The system is applying the first rule again, suddenly the forwarding to the index.php file causes an 404 error.

Seems like mod_rewrite handles the [L] flag that is supposed to stop all further checks not in the way I assumed it would. Time to read the docs again and yes, [L] does not work as expect and (suprise, surprise!) I am not the first to have run into this issue:

http://stackoverflow.com/questions/6797998/rewriterule-last-l-flag-not-working

Fixing Fat Free Frameworks 404 error using the REDIRECT_STATUS environment variable

It’s easy to tell mod_rewrite to not apply an rule on internally rewritten URLs. This is how a working .htaccess file could look like:

# Enable rewrite engine and route requests to framework
RewriteEngine On
 
# Some servers require you to specify the `RewriteBase` directive
# In such cases, it should be the path (relative to the document root)
# containing this .htaccess file
#
#RewriteBase /

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^(lib|tmp)\/|\.(ini|php)$ - [R=404]
 
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L,QSA]
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]

Fixing Fat Free Frameworks 404 errors using [END]

You could use the [END] flag:

# Enable rewrite engine and route requests to framework
RewriteEngine On
 
# Some servers require you to specify the `RewriteBase` directive
# In such cases, it should be the path (relative to the document root)
# containing this .htaccess file
#
#RewriteBase /
 
RewriteRule ^(lib|tmp)\/|\.(ini|php)$ - [R=404]
 
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [END,QSA]
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]

And everything is working as expected.

NOTE: the [END] flag only works on Apache 2.4 and newer!

Update:

As pointed out by xfra365, the developers of F3 fixed the issue by removing the check for “php”. Since that’s the official fix, i’d go with it.

Getting the Yoast WordPress SEO Plugin to work with the Gonzo theme

I changed a site running on the Gonzo wordpress theme to run the Yoast SEO plugin instead of AIO SEO since my comparisson test of these two plugins got me better results for yoast. But after switching the plugin the webpage was missing a proper meta description part. I took a look at the Gonzos theme template files, concretely the header.php file.

It looks like this:

	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
 
	<title>< ?php wp_title();?></title>
 
	< ?php if ($omc_favicon !== NULL) { ?><link href="<?php echo $omc_favicon; ?/>" rel="shortcut icon"/>< ?php } ?>
 
	<meta name="description" content="<?php bloginfo('description');?/>">
 
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/> 
 
	< ?php wp_head(); ?>

As you just saw it has wp_title() for the page title and a hardwired meta description built in. While wp_title() is fine with the Yoast SEO add, the hardwired description tag blocks Yoast from writing the tag. ALl I needed to do to fix that, was removing the line:

	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
 
	<title>< ?php wp_title();?></title>
 
	< ?php if ($omc_favicon !== NULL) { ?><link href="<?php echo $omc_favicon; ?/>" rel="shortcut icon"/>< ?php } ?>
 
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/> 
 
	< ?php wp_head(); ?>

Now the Yoast SEO addon can add the description meta tag and everything should work fine.

What does the > (bigger than) sign mean when it comes to CSS selectors?

If you use a < (bigger than) sign when chaining IDs in the CSS selector it means you only want to select the direct child, but not children below the direct child as you would if you only use a space character instead of >.

An example:

<div class="test">
  <div> <!-- direct child -->
    <div></div> <!-- child of direct child -->
  </div>
</div>

As you can see we got an outer div with a class named “test” that is wrapping two nested div tags.

An css selector example for accessing the direct child

If you use

.test > div

you will only select the direct child, but not the children nested below it.

An css selector example for accessing all children

If you use

.test div

you will access the direct child and all children below it.

An css selector example for accessing the child node of the child

If you want to only access the child of the direct child, you can chain the greater then signs:

.test > div > div

Read the stackoverflow posting on the topic for some extrainfos:

http://stackoverflow.com/questions/4459821/css-selector-what-is-it