noiselabs.org
yet another lighthouse for Linux geeks and code monkeys
yet another lighthouse for Linux geeks and code monkeys
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.
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);
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…
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
Oct 19th
Recently acquired
Oct 16th
Problem
How to resume a partial file downloaded from wget instead of downloading the same file from the beginning?
Solution
Use the -c/–continue option of wget
From man wget: “Continue getting a partially-downloaded file. This is useful when you want to finish up a download started by a previous instance of Wget, or by another program.”
First fetch:
# wget http://build.chromium.org/buildbot/archives/chromium.tgz
Resume partial file:
# wget -c http://build.chromium.org/buildbot/archives/chromium.tgz
Sep 25th
Problem
I was trying to install dev-util/subversion but emerge failed when java-config was called.
The output:
Traceback (most recent call last):
File “/usr/bin/java-config-2″, line 8, in <module>
from java_config_2 import __version__
ImportError: No module named java_config_2
Possible solution
python-updater was not executed after a python upgrade so run it now:
# python-updater -iv
Sources
Oct 25th
Sábado 27, as zonas ribeirinhas de Porto e Gaia irão receber espectáculos de animação de rua servindo de antecipação ao TRIP Festival Internacional de Rua a realizar pela primeira vez em Setembro de 2008.
A animação começa no sábado à s 22h30 com as actuações dos Per’Curtir, Ramon Kelvink e Transe Express
Oct 25th
Ladytron, Fujiya and Miyagi, sebastiAn, Dj Zebra, Jasson Forrest DJ Dona Summer, são os nomes principais do FESTSOUND2007 – Festival de música que decorre paralelamente ao FEST – Festival de Cinema Jovem de Santa Maria da Feira entre os dias de 28 de Outubro e 4 de Novembro.
Programa do Fest Sound:
29 de Outubro – Recepção – Bar Escadas para o Céu (€2)
22h00 – Território
23h00 – Nimai
00h30 – Mecanismo divino
30 de Outubro – Noite Galega – Bar Escadas para o Céu (€2)
23h00 – Niño y Pistola
00h00 – Cimento
02h00 – Marcos Cruz
31 de Outubro – Halloween – Cine-Teatro António Lamoso (€8)
00h00 – Ouvido Visual – Manuel Halpern e Ricardo Duarte
00h00 – Kid Chocolat (live act)
01h30 – Jason Forrest/Donna Summer
03h00 – Killer Keller
1 de Novembro – Noite Chill Out World – Cine-Teatro António Lamoso (€6)
00h00 – Blablabla DJs Chill Out Session
00h00 – Nova Arcadia
01h00 – Dead Men Talking
02h00 – Babar Luck
2 de Novembro – Party Hard – Cine-Teatro António Lamoso (€12,50)
23h00 – Attic Attack Collective Vs The Vanity Sessions
23h30 – Fujiya & Miyagi
00h45 – DJ Zebra
02h45 – F.E.V.E.R.
3 de Novembro – Festa de Encerramento – Lounge Europarque (entre €10 e €15)
23h00 – Moulinex
00h00 – Elisa do Brasil
01h30 – Ladytron DJs
03h00 – SebastiAn
04h30 – Toxic Avenger
Links: