Tuesday, July 23, 2013

Can't watch mpeg-4 aac h.264 video in Linux Firefox

Updated for Fedora 19 - July 2013

Every new Fedora install, I forget how to watch apple trailers in my browser. I get the mpeg-4 aac and h.264 decoder missing message.

This can be solved in three steps:

1) Add the rpmfusion repository.

su -c 'yum localinstall --nogpgcheck http://download1.rpmfusion.org/free/fedora/releases/19/Everything/x86_64/os/rpmfusion-free-release-19-1.noarch.rpm http://download1.rpmfusion.org/nonfree/fedora/releases/19/Everything/x86_64/os/rpmfusion-nonfree-release-19-1.noarch.rpm'

2) Install vlc

sudo yum install vlc

3) Lastly this one extra command allowed the movie to play

sudo yum install gstreamer1-libav

Wednesday, July 10, 2013

Fedora 19 and Gnome 3.8 - Get back your terminal background transparency

Gnome Terminal in 3.8 had the transparency option dropped/removed not because it wasn't a useful feature, but because implementation between new and old code was difficult.

Anyways with Fedora 19 and Gnome 3.8, there is a way to get back this feature. I ended up using the window manager cinnamon as it has advanced features of gnome, yet includes lots of the intuitive right click menu options you expect on any desktop.

Step 1:
sudo yum install devilspie

Step 2:
mkdir ~/.devilspie

Step 3:
// Add any file in this dir ending in .ds and devilspie will process it.

vim ~/.devilspie/terminal-opacity.ds

Step 4:
// In this file add this line of code
// Terminal is what fedora uses as the name of these terminals.

  (matches (window_name) "Terminal")
  (opacity 85)

Step 5:
// Add in .bash_profile the following line. It will
devilspie -a &

Step 6: Logout and log back in.

Any new terminal console windows will now be transparent - including the menu bars.

Sunday, June 2, 2013

Django change the trailing slash url convention to no trailing slash

URL Specs and search engines state that urls with and without trailing can affect your SEO rankings (and a user's ability to type in a link).

eg. example.com/page and example.com/page/

This affects some web frameworks, such as Django, as the regular expression for routing these URLs will be defined for only one of these cases. By convention Django will add a trailing slash, if a non trailing slash url is typed into the browser.

I prefer to not have a trailing slash as it is one less character to type in. I should note that some sites, like stackoverflow.com or twitter.com does not give a crap either way.

We can add this feature to Django by creating a custom middleware class that intercepts the request.path and rewrites it to the non trailing slash url.

What is middleware?

Middleware is a framework of hooks into Django’s request/response processing. It’s a light, low-level “plugin” system for globally altering Django’s input or output.

Or in layman's terms, it processes values/urls before it is sent to Django's views. You can find Django's middleware that redirects to the trailing slash url in:


Which was added to your project in

MIDDLEWARE_CLASSES = (     'django.middleware.common.CommonMiddleware',

How to get Django to redirect trailing slashes to the non trailing slash url if it exists.

Step 1:

Add this line in settings.py


Step 2:

Create these paths and files


Step 3: Add the class to the MIDDLEWARE definition


# It must be the first class as we want to catch it before django does.

Step 4: Add this code to redirect.py

For /admin urls, I have kept the trailing slash as I don't want to break Django's admin methods

from django.conf import settings
from django.core import urlresolvers
from django import http

Based on django/middleware/common.py

Django convention is to add trailing slashes to most urls
This method does the opposite and redirects trailing slashes to the
no trailing slash url if it exists
class RedirectTrailingSlashMiddleware(object):

    def process_request(self, request):
        if settings.APPEND_SLASH:
        if '/admin' in request.path:
            settings.APPEND_SLASH = True         

        new_url = old_url = request.path

        if (old_url.endswith('/')):
            urlconf = getattr(request, 'urlconf', None)
            if (not urlresolvers.is_valid_path(request.path_info, urlconf) and
                urlresolvers.is_valid_path(request.path_info[:-1], urlconf)):
                new_url = new_url[:-1]
                if settings.DEBUG and request.method == 'POST':
                    raise RuntimeError((""
                    "You called this URL via POST, but the URL ends "
                    "in a slash and you have APPEND_SLASH set. Django can't "
                    "redirect to the non-slash URL while maintaining POST data. "
                    "Change your form to point to %s (note no trailing "
                    "slash), or set APPEND_SLASH=True in your Django "
                    "settings.") % (new_url))

        if new_url == old_url:
            # No redirects required.

        return http.HttpResponsePermanentRedirect(new_url)        

Wednesday, April 17, 2013

Basic Master Slave setup on MySQL 5.5

There are more than enough master slave mysql tutorials, and I'm adding another one to the pile for my own personal reference.

Two micro ec2 instances on amazon with mysql55 installed. Make sure port 3306 is open between servers.

Step 1: Edit /etc/my.cnf on master and slave

On master:


On slave


Side Note:  you can't put master-host settings here as they've been deprecated since 5.1.17. MySQL will save the values internally and will automatically reference them when a reboot is done.

Restart Both Servers

service mysqld restart

Step 2: Create Slave User On Master

On Master run the mysql command:


Side Note: mydbname.* will not work, must use *.*

Step 3: Finish current commands and lock the tables

On Master:

flush tables with read lock

This will finish all commands and stop new ones from happening. To release the locks we need to run unlock tables, but not till later.

show master status

| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
| mysql-bin.000002 |     1859 |              |                  |

We'll have to keep track of the file and position if we use
--lock-all-tables instead of --master-data. I'm using the latter

Don't close your mysql console as this will unlock the tables. For the next step create a new terminal on the master server.

Step 4: Create a dump of the data on the master server

On master run:

mysqldump -u root -p --all-databases --master-data > moodle.sql

and copy the file to the slave server.

Step 5: Setup the slave server with the master login info.

On slave go to mysql command prompt

stop slave;

[Fancy Password]';

# MASTER_LOG_FILE='mysql-bin.000002',

On the mysql doc site, these two lines are not needed as they are included in the dump file when use used --master-data

Step 6: Import the dump sql file on the slave server.

Use this to import the dump file. (As mentioned this will add the master log file pos too.)

mysql -u root -p < moodle.sql

Step 7: Start the replication

We still have that mysql command prompt on master so we are now ready to release the lock.

unlock tables;

Then on slave we can begin the replication

start slave;

Step 8: Confirm the slave is working

show slave status\G

and you should see

Slave_IO_Running: Yes
Slave_SQL_Running: Yes