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;
2011
04.28

For a project I was working on I was in desperate need for a tool to generate slugs. Of course there are like million functions that can do that. We have the Mootools function String.Slugify, we have cakePHP’s function Inflector::slug et cetera. But there are no commandline or online tools that use these functions. So I created them! The commandline version is write in PHP and looks like this:

< ?php
setlocale(LC_ALL, 'en_US.UTF8');

if ($argc < 2)
{
  echo $argv&#91;0&#93;." <to slug text>\n";
  exit(1);
}

$words = $argv;
array_shift($words);

echo "\n";
echo toAscii(implode(' ', $words));
echo "\n\n";

function toAscii($str, $replace = array(), $delimiter = '-')
{
  if( !empty($replace) )
  {
    $str = str_replace((array)$replace, ' ', $str);
  }

  $clean = iconv('UTF-8', 'ASCII//TRANSLIT', $str);
  $clean = preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $clean);
  $clean = strtolower(trim($clean, '-'));
  $clean = preg_replace("/[\/_|+ -]+/", $delimiter, $clean);

  return $clean;
}
?>

And this is how you use it:

php slugify.php A string to slugify

# ouput
a-string-to-slugify

non PHP version, but this way I could also use it online. And that’s what I did. Slugify, my online slug generator uses the same function.

References:

2011
04.13

While R can be used in batch mode:

R --no-save --no-restore --quiet < myRprog.r > myRprog.log 2>&1

Much more fancy things can be done by means of littler. Littler (pronounced ‘little R’ and written ‘r’) provides hash-bang (i.e. script starting with #!/foo/bar) capability for GNU R, as well as simple command-line and piping use. For all the example take a look at http://dirk.eddelbuettel.com/code/littler.html.

This is how I use it mostly:

# cat test.R | r
[1]  1  2  3  4  5  6  7  8  9 10

or

# echo "print(1:10)" | r
[1]  1  2  3  4  5  6  7  8  9 10
2010
12.19

A few weeks ago I bought a new laptop: an ASUS N53JN.

After having some trouble finding the HDD which I wanted to replace by an OCZ Vertex 2 I also had difficulty getting my speakers to work. The headphones worked fine but no sound from the speakers. After searching for quite some time I finally found the solution:

sudo nano /etc/modprobe.d/alsa-base
options snd-hda-intel model=auto

I also added the ubuntu-audio-dev repository but I’m quite sure this is not what fixed my problem…

2010
12.19

By default the N900 does not allow us to see the duration of a call. This little fix will  😉

First, login via ssh and change directory:

cd /home/user/.rtcom-eventlogger;

Make a backup of your ‘call’ database:

cp -a el-v1.db el-v1.db.ori;

Download the SQL patch:

wget 'http://talk.maemo.org/attachment.php?attachmentid=10495&amp;d=1275242093' -O triggers.txt;

Apply it:

sqlite3 -batch /home/user/.rtcom-eventlogger/el-v1.db < triggers.txt;[/code]

Install the ‘Extended Call Log‘ package from Maemo.org or the ‘extras‘ repository. Open it and you will now be able to see the duration of a call.

Extended Call Log

Call duration

References:

2010
07.24

While using all sorts of browser plug-ins (java, flash, shockwave, quicktime, silverlight, et cetera) can be extreme helpful and/or even necessary. History has thought us that using them, especially when outdated, can be quite a security hazard (in Dutch).

For us, “power” users, keeping them all up-to-date isn’t too complicated. For “normal” users however this can be quite the struggle. Mozilla has developed a nifty tools that can do all the heavy lifting for them: Mozilla Plugin Check.Using it is as easy as visiting the website and following the instructions. Fully supported browsers include Apple Safari, Google Chrome, Mozilla Firefox and Opera. Microsoft Explorer, due to technical limitations of the platform, has limited. I would encourage everybody to have a look and in particular help to spread the word!

We can check your plugins and stuff

2010
07.24

Last week I created a VMware instance of our online treatment application for developers to work on. Deploying that instance on VMware player for Linux wasn’t a problem, but when doing it on Windows 7 there was a problem with the vmnet8 (NAT) interface. Developers would get networking connection (to the virtual machine), but not from the machine to the internet. After googling for a while I read that Windows 7 isn’t officially supported :-?, nevertheless I wanted it to work. I already noticed that the VMware “Virtual Network Editor” wasn’t present. Having that present, probably would be my best chance to getting a working NAT interface. I read somewhere that however the vmnetcfg.exe is included in the installer, it won’t be installed. Getting it there would involve:

Running the installer with /e option:

VMware-player-3.0.0-197124.exe /e extract

All the content of the installer would then be extracted to the extract folder. After that, open network.cab (using 7-zip) and copy vmnetcfg.exe to your installation folder (typically C:\Program Files\VMware\VMware Player\. Now open vmnetcfg.exe and make sure the NAT interface is configured correctly. You should have internet connection in your virtual machine by now!