Jan 13, 2014

Mac OS X MySQL problems

Note: I'm running a brew installation of mysql on Mac OS X Mavericks.

First of all learn how to debug the mysql errors. Usually a tail -f /usr/local/var/mysql/*.err does the trick.

Common problems

Corrupt InnoDB files

2014-01-13 17:32:09 6124 [ERROR] InnoDB: Unable to lock ./ibdata1, error: 35
2014-01-13 17:32:09 6124 [Note] InnoDB: Check that you do not already have another mysqld process using the same InnoDB data or log files.
This problem is usually caused by a corrupted innodb logfile. There files are located in /usr/local/var/mysql and have a "ib" prefix filename (in my case they are named ib_logfile0, ib_logfile1 and ibdata1).
  1. Backup the ib files: mv /usr/local/var/mysql/ib* ~/Desktop/ib_files/
  2. Stop mysqld processes; ps xua | grep mysql, and then: kill -9 PID
  3. Restart the mysql server: mysql.server restart

Bad Permissions

Fatal error: Can't open privilege tables: Can't find file: './mysql/host.frm' (errno: 13)

Possible solution:
sudo chown -R _mysql /usr/local/var/mysql

Errors after brew upgrades

After a brew upgrade that affects MySQL you should reload it:

launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

Mar 14, 2013

Mac OS X 10.8 Mountain Lion write on NTFS

For reading and writing on NTFS drives on Mac OS X 10.8 (Mountain Lion), follow this steps:

  1. Install "FUSE for OS X" (from: - mirror link here)

  2. Install "NTFS-3G" (from: - mirror link here)

    important: please reboot your system now!

  3. Install "NTFS-3G fuse_wait patch" (from: - mirror link here)

You're welcome :)

Dec 21, 2012

SVN create user

As simple as:

htpasswd /etc/subversion/passwd username

Jun 24, 2012

Enabling notification icons on Unity

All you need to do is install gconf-tools, launch dconf-editor an then set desktop > unity > panel > systray-whitelist to ['all'].

 Now restart unity and all the good old notification icons should be where they always were :)


Apr 18, 2012

SVN recursive add all

svn status | grep -v "^.[ \t]*\..*" | grep "^?" | awk '{print $2}' | xargs svn add

Apr 12, 2012

Create a video from an image and mp3 using ffmpeg

If you want to create a video with a static image and a background music (face it, you want to upload a song to youtube!), here's a very easy way using ffmpeg.

ffmpeg -loop 1 -t 242 -i the_image.jpg -i the_song.mp3 target_video.mpg

-t: duration in seconds
-loop 1: puts the image on all frames
-i: input files - the image and the mp3

PS: this is possibly not the best way because for a 242 seconds video I got video:6351kB audio:3782kB wich is.. stupid! I need to find a way to use key-frames so I can drastically reduce the video size! I tried using the -g <int> argument but got the same filesize :\

Dec 19, 2011

Javascript check element visibility

The following function checks if a given element is within browser's viewport:

function isScrolledIntoView(elem)
    var docViewTop = $(window).scrollTop();
    var docViewBottom = docViewTop + $(window).height();

    var elemTop = $(elem).offset().top;
    var elemBottom = elemTop + $(elem).height();

    return ((elemBottom >= docViewTop) && (elemTop <= docViewBottom));

Sample Usage

On this example I'll be loading iframes only when they are on the browsers viewport. For this to work I initially printed all iframe's without the SRC attribute. Instead, I used the REL attribute as a placeholder for the iframe destination:

    var my_interval = setInterval(checkIframesVisibility, 1000);

    function checkIframesVisibility()
        $("iframe").each(function(i) {
            if (isScrolledIntoView($(this)))
                if ($(this).attr('src') == "")
                    $(this).attr('src', $(this).attr('rel'));
                    $(this).iframeAutoHeight({debug: false, diagnostics: false});

    function isScrolledIntoView(elem)
        var docViewTop = $(window).scrollTop();
        var docViewBottom = docViewTop + $(window).height();

        var elemTop = $(elem).offset().top;
        var elemBottom = elemTop + $(elem).height();

        return ((elemBottom >= docViewTop) && (elemTop <= docViewBottom));

PS: The iframeAutoHeight is a plugin that auto resizes the iframe to the content's height.

Hope you find this is useful!

Nov 10, 2011

Global Apache 404 Page

This will setup a single 404 page for all domains on your web server.

1st: create a fancy 404 page like this one:
2nd: put it somewhere on your server:

3rd: edit your apache configuration (/etc/apache2/apache2.conf on ubuntu machines):
Alias /404 /etc/apache2/error-documents/404.html
ErrorDocument 404 /404

Nov 8, 2011

Linux jail/lock/chroot users to homedir

Jailing, Chrooting, Locking users/applications...

Yes, they do give it a lot of names... but if all you want to do is to create a user on your system and give him ssh/ftp access without exposing your whole system - therefore jailing him - just follow this steps. I promise it will take no more than 5 mins!

This as been tested by myself on Ubuntu 10.04

download & extract jailkit, then:
make install

set up the jail path:
sudo mkdir /jail
sudo chown root:root /jail

define the environment
sudo jk_init -v /jail basicshell
sudo jk_init -v /jail editors
sudo jk_init -v /jail extendedshell
sudo jk_init -v /jail netutils
sudo jk_init -v /jail ssh
sudo jk_init -v /jail sftp
sudo jk_init -v /jail jk_lsh

add a user
sudo adduser dummy
sudo jk_jailuser -m -j /jail dummy
sudo mkdir -p /jail/home/dummy
chown dummy:dummy /jail/home/dummy

/jail/etc/group should look like:

/jail/etc/passwd should look like:

Now login via ssh/sftp with the dummy user. You should see a small portion of a filesystem if you change directory do / but you won't be able to see the REAL system files.

Thanks to !