Adding unicode glyphs to docutils (ReStructured Text, Sphinx, …) documents.

February 13th, 2013 by exhuma.twn

docutils supports adding a wide range of unicode glyphs into documents, while still keeping the source document readable and plain ASCII.

The character mappings are available in include files, and have to be included into the document before being useful.

For example, adding a horizontal arrow is done by including 'isoamsa.txt' which provides (amongst others) the replacement |hArr|. An example document might be:

.. include:: <isoamsa.txt>

This is some text containing an arrow symbol: |hArr|

Hav a look at the extensions available in the official docutils distribution for more information.

Posted in Coding Voodoo | No Comments »

Getting ENUM DataType to work with Doctrine 2 in Zend Framework 2

January 24th, 2013 by wickeddoc

When using Doctrine 2 with a MySQL Database which has tables with ENUM datatypes, you might run into the following error message:

‘Unknown database type enum requested, Doctrine\DBAL\Platforms\MySqlPlatform may not support it.’

This is because Doctrine 2 doesn’t support the ENUM DataType natively as you can read here: Doctrine Cookbook.

In their Doctrine Cookbook they give a solution how you can resolve this by mapping the ENUM to a STRING datatype. But if you’re using Zend Framework 2 you’ll probably run into the same question as I have: where do I put this stuff for it to work?

This might not be the perfect solution, but it worked for me.

Adding the required code to the onBootstrap() method of the Module.php file of the “default” module did the job.

class Module
{
    public function onBootstrap(MvcEvent $e)
    {
        ...
        $em = $e->getApplication()->getServiceManager()->get('Doctrine\ORM\EntityManager');
        $platform = $em->getConnection()->getDatabasePlatform();
        $platform->registerDoctrineTypeMapping('enum', 'string');
        ...
       
    }

}

Posted in Doctrine, PHP, Zend Framework | 5 Comments »

Format JSON documents on the command line

August 31st, 2012 by exhuma.twn

I tend to test my REST services using curl. Most of the time the JSON responses are not pretty-printed, which makes testing larger documents a pain. Copy pasting the results in online JSON formatters was really getting annoying. So I wrote a few lines of python to do that job for me. Note that this is a two-minute-hack and by no means very generic. It works for me, and with curl. The handling for Headers is especially eerie 😛 But maybe you will still find it useful.

Without further ado, here it is: https://github.com/exhuma/braindump/tree/master/jsonformat

Installation

pip install jsonf

or

easy_install jsonf

Screenshot

Posted in Uncategorized | No Comments »

Tunnel your browser connections (i.e. your web traffic) through an SSH tunnel.

August 24th, 2012 by exhuma.twn

I actually did not believe it’s this simple.

Creating the tunnel is as easy as typing:

ssh -D 1080 user@remote_host

Which can be improved with

ssh -fND 1080 user@remote_host

See the man page on the details of the extra options.

This will open up port 1080 on your local machine, providing a SOCKS proxy (SOCKS5 if I’m right). You can then specify this in any application supporting SOCKS proxies. This includes Firefox and Chrome. With Firefox it’s straight-forward. You can find it in the usual proxy page in the settings.

For chrome it’s a bit more tricky. While you can specify a SOCKS proxy, it seems to ignore it. If you want to enable your tunnel, you have to run chrome with the following command-line flag:

chromium-browser --proxy-server="socks5://localhost:1080"

(or use chrome. Whatever rocks your boat).

Once this is set up, what will happen is that your application/browser will send all requests to your locally running SSH instance. This in turn will forward it to the remote host, where the request will be sent out on the web. The response takes the inverse direction. As stated by linode, this is great if you’re on an untrustworthy network!

Sources:

Posted in Linux, Techno Voodoo | No Comments »

More convenient development with the closure library

August 23rd, 2012 by exhuma.twn

While cleaning up my build process using ‘closure’, I stumbled across plovr. After using it for only 20 minutes, I am convinced that this should be in the toolbox of *everyone* developing with the closure library!

While the documentation is still a bit sparse, you can have it set up in no time! There’s no need to regurgitate a basic setup example in this post. Everything necessary is readily availble over at http://plovr.com/!

Posted in Coding Voodoo, JavaScript | No Comments »

Update to bash completion for fabric tasks.

August 20th, 2012 by exhuma.twn
cURL error 28: Connection timed out after 5001 milliseconds
Fatal error: Uncaught Error: Cannot use object of type WP_Error as array in /var/www/foobar.lu/www/htdocs/wp/wp-content/plugins/embed-github-gist/embed-github-gist.php:86 Stack trace: #0 /var/www/foobar.lu/www/htdocs/wp/wp-content/plugins/embed-github-gist/embed-github-gist.php(164): embed_github_gist('2136677', NULL, '1', NULL) #1 /var/www/foobar.lu/www/htdocs/wp/wp-includes/shortcodes.php(325): handle_embed_github_gist_shortcode(Array, '', 'gist') #2 [internal function]: do_shortcode_tag(Array) #3 /var/www/foobar.lu/www/htdocs/wp/wp-includes/shortcodes.php(199): preg_replace_callback('/\\[(\\[?)(gist)(...', 'do_shortcode_ta...', '<p>In a <a href...') #4 /var/www/foobar.lu/www/htdocs/wp/wp-includes/class-wp-hook.php(286): do_shortcode('<p>In a <a href...') #5 /var/www/foobar.lu/www/htdocs/wp/wp-includes/plugin.php(208): WP_Hook->apply_filters('<p>In a <a href...', Array) #6 /var/www/foobar.lu/www/htdocs/wp/wp-includes/post-template.php(247): apply_filters('the_content', 'In a <a href="h...') #7 /var/www/foobar.lu/www/htd in /var/www/foobar.lu/www/htdocs/wp/wp-content/plugins/embed-github-gist/embed-github-gist.php on line 86