yet another lighthouse for Linux geeks and code monkeys
noisebleed
This user hasn't shared any biographical information
Posts by noisebleed
Don't let updatedb take your Linux down
May 1st
Coffee break everyone?
Everyday morning was the same: updatedb came and took my Gentoo away. The symptoms were clear, X/KDE applications starting to become slow and unresponsive, and then the two inevitable choices: go for a coffee and wait or pkill the bastard.
Asking updatedb to be nice (the wrong way)
To fix this came to my mind the nice command. This is well known to Gentoo users because of the PORTAGE_NICENESS feature include in make.conf. Nice is a program that adjusts the process scheduling (aka niceness) of the desired programs so setting a value of 19 (the maximum) would make updatedb to be “nicer” to other applications and therefore being less bossy. So I’ve edited /etc/cron.daily/slocate, placed “nice -n 19″ before the updatedb command and waited. But, once again, updatedb came and owned my computer.
Asking updatedb to be I/O-nice (the right way)
So. what’s wrong here? Updatedb is not a CPU-intensive application so nice won’t change a thing. The bottleneck is disk access so what we need here is a nice for I/O. The solution? Ionice.
Ionice is able to set the I/O scheduling class and priority for a given program. To give updatedb a low priority we pick the class 3, the idle one.
Again, let’s go to crontab and edit the slocate entry.
# vim /etc/cron.daily/slocate
Put ionice -c 3 before the updatedb command.
#! /bin/sh
if [ -x /usr/bin/updatedb ]
then
if [ -f /etc/updatedb.conf ]
then
ionice -c 3 /usr/bin/updatedb
else
ionice -c 3 /usr/bin/updatedb -f proc
fi
fi
And if you’re asking where (in Gentoo) is this ionice program, the solution is sys-apps/util-linux, which I’m pretty sure is already installed. If not: emerge -a sys-apps/util-linux.
This is all good but… what’s this updatedb thing?
Updatedb is a tool ran daily by cron to update the slocate database. And Slocate (Secure Locate) is a security enhanced version of the GNU Locate, which is used to index all the files of your system allowing a (very) quick search of them. In Gentoo Linux the slocate is available in Portage through sys-apps/slocate.
Meme Miner: the translation tool I've been looking for
Mar 14th
No, this will not replace Google Translate or Babel Fish. But it does something that these tools simply can’t offer.
For some time I’ve been using Wikipedia to translate expressions that a normal translator couldn’t give exact results, because they use literal translations. Now there is a faster way.
MemeMiner, brought to us by Fred Rocha, is a Web tool that does this work and gives us a easy and fast way to get this translations.
From the author own words:
For most of it’s articles, Wikipedia provides the equivalent expression of that concept in other languages.
With MemeMiner you can effortlessly find out how a certain idea is expressed across the language spectrum.
Now go ahead and try this tool at http://fredrocha.net/MemeMiner/
Thanks Fred!
tar: file name is too long (max 99)
Feb 27th
I was doing the usual make dist process to launch a tarball for one of my apps when tar died with the following message:
tar: file name is too long (max 99); not dumped tar: Error exit delayed from previous errors
If you happen to see the same error message it is quite likely that you (and by you I mean Automake)Â are using the old V7 tar format.
Just want the solution? It’s here
V7 and other tar formats
By default Automake is pulling the historical V7 format to generate the tarball with make dist. This tar format supports file names only up to 99 characters and that’s why tar is refusing to build the tarball.
Since automake 1.9, th tar format can be chosen with the options tar-v7, tar-ustar, and tar-pax.
This is what the Automake manual says about each option:
- tar-v7
This is the historical default. This antiquated format is understood by all tar implementations and supports file names with up to 99 characters. When given longer file names some tar implementations will diagnose the problem while other will generate broken tarballs or use non-portable extensions. Furthermore, the V7 format cannot store empty directories.
- tar-ustar
(…) format defined by POSIX 1003.1-1988. This format is believed to be old enough to be portable. It fully supports empty directories. It can store file names with up to 256 characters, provided that the file name can be split at directory separator in two parts, first of them being at most 155 bytes long. So, in most cases the maximum file name length will be shorter than 256 characters. However you may run against broken tar implementations that incorrectly handle file names longer than 99 characters.
- tar-pax
(…) the new pax interchange format defined by POSIX 1003.1-2001. It does not limit the length of file names. However, this format is very young and should probably be restricted to packages that target only very modern platforms. There are moves to change the pax format in an upward-compatible way, so this option may refer to a more recent version in the future.
How to fix it?
The solution is to pick a newer and better tar implementation like tar-pax. Go to configure.ac or configure.in and change the AM_INIT_AUTOMAKE macro so it specifies the tar format and requires automake version to be 1.9 or better as tar-pax is only supported since 1.9.
configure.ac/configure.in:
AM_INIT_AUTOMAKE([1.9 tar-pax])
Now run `make dist` again and tar won’t bother you anymore (at least with this error
).
Chromium OS using Portage build environment
Feb 22nd
This are good news for the Gentoo community. Portage is being used to build Chromium OS packages. As you may know Portage is the Gentoo Linux default package management system which has its roots on FreeBSD’s ports.
As of February 5, Google developer Ryan Cairns has made this statement on the Chromium OS dev mailing list:
As we’ve been growing and working with more partners, the need to support board specific builds and improve our tools has become more urgent. In order to get there more quickly we’ve been investigating several different build tools. We found that the Portage build tools suit our needs well and we will be transitioning 100% within the next week.
As a Gentoo user and supporter I’m happy to see Portage being picked by major projects like the Chromium OS. Hopefully it will bring more (positive) attention to Gentoo and maybe we will see the Google folks contributing with improvements and bug fixes back to Portage.
For those interested in checking out the Portage-based build environment and build a bootable Chromium OS image take a look at this Chromium OS documentation page.
If you are interested in Portage features and usage check the Gentoo Handbook page about Portage. And if you got curious about Portage history I recommend the this article by Daniel Robbins, the founder of Gentoo.
To know more about the Chromium OS project and Google Chrome OS check this.
Mark all messages as Read in Gmail (in 3 easy steps)
Feb 21st
Want to get rid of all those unread messages in Gmail? Or, just like me, have some unread messages you can’t find and want to reset the unread count to zero? Well, here is the solution:
- Step 1: Type “is:unread” in the search bar.
- Step 2: Then select “Unread” as seen in the picture below.

Type "is:unread" in the search bar and then select "Unread" from the selection bar

In the "More actions" dropdown select "Mark as read"
And that’s it. Your inbox shouldn’t be reporting any unread messages by now.
Check UTF-8 input in PHP: only letters
Feb 18th
This is a simple way to check a UTF-8 string with PHP function preg_match in search for anything that isn’t a letter, which includes all UTF-8 letters and not just ASCII. Preg_match performs a regular match on the given input using a pattern. The pattern used tells preg_match to look for letters (\p{L}) using Unicode (/u).
The function to accomplish this could look like this:
function checkUTF8Input($input)
{
$pattern = '/^[\p{L} ]+$/u';
preg_match($pattern, $string, $matches);
if (count($matches) > 0)
return true; // String is OK (only letters)
else
return false; // String has non-utf8 letters
}
Take a look at preg_match to know more about this function used for regex operations.
How to prevent caching (force image reload) in PHP and/or JavaScript/jQuery
Feb 12th
If you are using images generated on-the-fly by a PHP script (or another server language), like I’m doing on my web application, you surely do not want images to be read from cache as your users will be seeing the same first generated image (saved into cache) and not the new generated versions.
You can play with some header commands and build a function like this…
function cacheKiller()
{
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT\n");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
}
…but this will work for the whole page and not only for images.
So, to make sure the images shown are always up-to-date the simple way is to add a query section with a random number to the image URL in order to make the browser think that this is a different image, while keeping the same name.
In PHP it works like this:
// Generate a number that will never be repeated using the time function
// that "returns the current time measured in the number of seconds since
// the Unix Epoch (January 1 1970 00:00:00 GMT)"
$cachekiller = time();
// Include the generated number in the image URL

If the image URL is built using JavaScript/jQuery the Math function is good choice to generate a random number.
// Generate random number between 1 and 1000.
var cachekiller = Math.floor(Math.random()*1001);
$("#thumbnail").attr("src", "path/to/image.png?"+cachekiller);
How to install Gentoo on a Pentium II in 2010 (Part I)
Oct 16th
So I have a Pentium II box laying around in my student’s house. What a perfect machine to get Gentoo on. C’mon let’s get our hands dirty!
The Pentium II belongs to Intel’s sixth-generation micro-architecture (“Intel P6″) and x86-compatible microprocessors and was launched on May 7, 1997. So what we got here is a 12 years old machine!
Here are the specs of my machine:
[TODO]
As you may imagine compiling on this box is a very tedious task. Fortunately there are alternatives
I’ll be showing these alternatives on the second part of this post…
Howto Gentoo Linux with UTF-8 and Portuguese (Portugal) localization
Mar 31st
Purpose
How to configure a Gentoo Linux system to use UTF-8 character encoding and Portuguese (Portugal) localization (language and keyboard).
Background
UTF-8 is a variable-length character encoding, which in this instance means that it uses 1 to 4 bytes per symbol. So, the first UTF-8 byte is used for encoding ASCII, giving the character set full backwards compatibility with ASCII. UTF-8 means that ASCII and Latin characters are interchangeable with little increase in the size of the data, because only the first bit is used.
UTF-8 allows you to work in a standards-compliant and internationally accepted multilingual environment, with a comparatively low data redundancy. UTF-8 is the preferred way for transmitting non-ASCII characters over the Internet, through Email, IRC or almost any other medium.
A Locale is a set of information that most programs use for determining country and language specific settings. The locales and their data are part of the system library and can be found at /usr/share/locale on most systems. A locale name is generally named ab_CD where ab is your two (or three) letter language code (as specified in ISO-639) and CD is your two letter country code (as specified in ISO-3166). Variants are often appended to locale names, e.g. en_GB.utf8 or de_DE@euro.
Solution
Specify the locales we will need in /etc/locale.gen:
# vi /etc/locale.gen
en_GB ISO-8859-1
en_GB.UTF-8 UTF-8
pt_PT ISO-8859-1
pt_PT@euro ISO-8859-15
pt_PT.UTF-8 UTF-8
pt_PT.UTF-8@euro UTF-8
The next step is to run locale-gen. It will generate all the locales we have specified in the /etc/locale.gen file.
# locale-gen
There is one environment variable that needs to be set in order to use our new UTF-8 locales: LC_CTYPE (or optionally LANG, if you want to change the system language as well). Setting the locale globally should be done using /etc/env.d/02locale.
# vi /etc/env.d/02locale
LANG="pt_PT.UTF-8@euro"
Now update the update the environment after the change
# env-update && source /etc/profile
The keyboard layout used by the console is set in /etc/conf.d/keymaps by the KEYMAP variable. For a Portuguese keyboard use pt-latin1 or pt-latin9. Set also EXTENDED_KEYMAPS attributes like “euro”.
# vi /etc/conf.d/keymaps
KEYMAP="pt-latin9" SET_WINDOWKEYS="yes" EXTENDED_KEYMAPS="backspace keypad euro"
To enable UTF-8 on the console, you need to edit /etc/rc.conf and set UNICODE=”yes”.
# vi /etc/rc.conf
UNICODE="yes"
The keyboard layout to be used by the X server is specified in /etc/X11/xorg.conf by the XkbLayout option.
# vi /etc/X11/xorg.conf
Section "InputDevice"
Identifier "Keyboard0"
Driver     "kbd"
Option     "XkbLayout" "pt"
...
EndSection
There is also additional localisation variable called LINGUAS, which affects to localisation files that get installed in gettext-based programs, and decides used localisation for some specific software packages, such as kde-base/kde-i18n and app-office/openoffice. The variable takes in space-separated list of language codes, and suggested place to set it is /etc/make.conf:
# vi /etc/make.conf
LINGUAS="pt pt_PT en en_GB"
And that’s it! Hopefully your system should now be running in full UTF-8/Portuguese support. Good linuxing
Sources
