2011
06.16

Today I ran into some Trac problems when trying to view a SVN changeset in the SVN browser. I read that these problems were caused by MySQL? so I tried `the suggested`. Because I had to do this for 3 Trac instances I created a little php (commandline) script to do the job.

< ?php
if ($argc != 2)
{
  echo $argv&#91;0&#93;." <DATABASE>\n";
  exit(1);
}

$db = trim($argv[1]);

if (!$link = mysql_connect('127.0.0.1', 'root', ''))
{
  die(mysql_error());
}

if (!$db_selected = mysql_select_db($db))
{
}

echo "ALTER DATABASE `$db` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;\n";

if (!($result = mysql_query("SHOW TABLES;")))
{
  die (mysql_error());
}

while ($row = mysql_fetch_assoc($result))
{
  $table = array_shift($row);
  echo "ALTER TABLE `$table` ENGINE = InnoDB;\n";
  echo "ALTER TABLE `$table` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;\n";
}
?>

Usage:

php convert_trac_db.php trac;

Output:

ALTER DATABASE `trac` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE `attachment` ENGINE = InnoDB;
ALTER TABLE `attachment` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE `auth_cookie` ENGINE = InnoDB;
ALTER TABLE `auth_cookie` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE `component` ENGINE = InnoDB;
ALTER TABLE `component` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE `enum` ENGINE = InnoDB;
ALTER TABLE `enum` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE `fullblog_comments` ENGINE = InnoDB;
ALTER TABLE `fullblog_comments` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE `fullblog_posts` ENGINE = InnoDB;
ALTER TABLE `fullblog_posts` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE `mastertickets` ENGINE = InnoDB;
ALTER TABLE `mastertickets` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE `milestone` ENGINE = InnoDB;
ALTER TABLE `milestone` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE `node_change` ENGINE = InnoDB;
ALTER TABLE `node_change` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE `permission` ENGINE = InnoDB;
ALTER TABLE `permission` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE `report` ENGINE = InnoDB;
ALTER TABLE `report` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE `revision` ENGINE = InnoDB;
ALTER TABLE `revision` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE `session` ENGINE = InnoDB;
ALTER TABLE `session` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE `session_attribute` ENGINE = InnoDB;
ALTER TABLE `session_attribute` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE `system` ENGINE = InnoDB;
ALTER TABLE `system` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE `tags` ENGINE = InnoDB;
ALTER TABLE `tags` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE `team_availability` ENGINE = InnoDB;
ALTER TABLE `team_availability` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE `ticket` ENGINE = InnoDB;
ALTER TABLE `ticket` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE `ticket_change` ENGINE = InnoDB;
ALTER TABLE `ticket_change` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE `ticket_completion` ENGINE = InnoDB;
ALTER TABLE `ticket_completion` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE `ticket_custom` ENGINE = InnoDB;
ALTER TABLE `ticket_custom` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE `version` ENGINE = InnoDB;
ALTER TABLE `version` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE `wiki` ENGINE = InnoDB;
ALTER TABLE `wiki` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;

Run this SQL via phpMyAdmin or pipe it to MySql directly:

php convert_trac_db.php trac | mysql -uroot -p trac;
2011
06.14

A while ago I was migrating an old physical server install to a new virtual one. On this install was an Arabic website running and for that site to work (in Arabic) I needed to add a locale (ar ISO-8859-6 to be specific). Unfortunately there was not much documentation on that subject… Eventually I found a solution:

  • First I installed `All locales`:

    dpkg-reconfigure locales
    
  • Then I compiled the locale definition files:

    localedef ar -i ar_SA -f ISO-8859-6
    

    After that everything worked nicely (لطيف) …

    References:

2011
06.12

A while ago I was working on a piece of R code for the data analysis of my Master These project. While experiencing some encoding issues running the code on different platforms I decided to build in OS detection. After some Googling I found out there are several ways to do so. First of all we can search in the `version` variable:

> version

platform       x86_64-pc-linux-gnu          
arch           x86_64                       
os             linux-gnu                    
system         x86_64, linux-gnu            
status                                      
major          2                            
minor          10.1                         
year           2009                         
month          12                           
day            14                           
svn rev        50720                        
language       R                            
version.string R version 2.10.1 (2009-12-14)

version$os

or `.Platform`

> .Platform
$OS.type
[1] "unix"

$file.sep
[1] "/"

$dynlib.ext
[1] ".so"

$GUI
[1] "X11"

$endian
[1] "little"

$pkgType
[1] "source"

$path.sep
[1] ":"

$r_arch
[1] ""

.Platform$OS.type

or even `Sys.info()`

> Sys.info()

                                     sysname 
                                     "Linux" 
                                     release 
                         "2.6.32-30-generic" 
                                     version 
"#59-Ubuntu SMP Tue Mar 1 21:30:46 UTC 2011" 
                                    nodename 
                                "foo.bar.nl" 
                                     machine 
                                    "x86_64" 
                                       login 
                               "mtersmitten" 
                                        user 
                               "mtersmitten"

In my code I would use this like:

toUtf8 = function(column) 
{
  return (
    switch(class(column), 
      "character" = iconv(column, "LATIN1", "UTF-8"),
      "data.frame" = as.data.frame(apply(column, 2, iconv, "LATIN1", "UTF-8")),
    )
  );
}

if (Sys.info()["sysname"] == "Linux")
{
  items15["question"] = toUtf8(items15["question"])
}

I know, it’s not pretty but it works…

PS: am I the only one having encoding issues working on multiple OSses by the way?

2011
06.12

While debugging SQL queries with:

< ?php echo $this->element('sql_dump'); ?>

(in your layout) or DebugKit works great, you have to `render` for it to work. In this particular case that was a problem because I had an `exit;` statement in the middle of my controller to prevent redirection.

The following statement was my rescue:

$log = $this->Model->getDataSource()->getLog(false, false);
debug($log);

I leaves you a nice SQL log in array format!

PS: make sure to replace Model with an actual model name…

2011
06.12

I was trying to convert .svg files to .png. No problems with that, but when doing so I lost the transparency of the originals. Not that that really mattered because I had a white background-color anyway, but I had to find out!

  • First be sure to install imagemagick:

    sudo apt-get install imagemagick;
  • And use `convert` to convert:

    convert +antialias -background transparent \
            media-playback-start.svg media-playback-start.png;