noiselabs.org

yet another lighthouse for Linux geeks and code monkeys

Follow me on TwitterRSS Feeds

  • Home
  • Linux
    • Gentoo
  • Programming
    • PHP
    • Python
  • Software Tips & Tricks
    • Linux
    • Web
  • Web Development

Check UTF-8 input in PHP: only letters

Feb 18th

Posted by noisebleed in Web Development

2 comments

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.

php, regex, unicode, utf-8

How to prevent caching (force image reload) in PHP and/or JavaScript/jQuery

Feb 12th

Posted by noisebleed in Web Development

No comments

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);
javascript, jquery, php

How to install Gentoo on a Pentium II in 2010 (Part I)

Oct 16th

Posted by noisebleed in [...]

2 comments

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…

binhost, gentoo, pentium ii

Howto Gentoo Linux with UTF-8 and Portuguese (Portugal) localization

Mar 31st

Posted by noisebleed in [...]

No comments

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

  • http://www.gentoo.org/doc/en/utf-8.xml
  • http://www.gentoo.org/doc/en/guide-localization.xml
gentoo

To-buy list

Oct 19th

Posted by noisebleed in Music

No comments


And here it is my to-buy list of CDs. As soon as I get some money… (which seems to be not so soon… :( )

  • Test Icicles – For Screening Purposes Only
  • Digitalism – Idealism
  • Porcupine Tree - Fear Of A Blank Planet
  • Opeth – Blackwater Park

Recently acquired ;)

  • Thee Orakle – Secret
  • Thee Orakle – Metaphortime

Music

[gentoo] Resume wget broken downloads

Oct 16th

Posted by noisebleed in [...]

No comments

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

gentoo, Linux, wget

[gentoo] Emerge of subversion fails on java-config

Sep 25th

Posted by noisebleed in [...]

1 comment

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

  • Gentoo Bug 236131 – Stabilize dev-util/subversion-1.5.1
gentoo, java-config, python, subversion

TRIP – Festival Internacional de rua no Porto

Oct 25th

Posted by noisebleed in Agenda

No comments

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

Agenda

Ladytron, Fujiya e Miyagi e DJ Zebra no FestSound2007 de Santa Maria da Feira

Oct 25th

Posted by noisebleed in Agenda

No comments

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:

  • Fest Sound (com links para o MySpace das bandas)
  • Blitz
Agenda, Music

i like: Progressive Rock/Metal bands

Oct 23rd

Posted by noisebleed in Music

No comments

  • Porcupine Tree
  • Too
  • Riverside
  • Opeth
  • Pure Reason Revolution
Music
«123»
    • Recent comments
    • Popular posts
    • Archives
    • Tags
    • Categories
    • Entertainment (5)
      • Agenda (2)
      • Music (3)
    • Linux (3)
      • Gentoo (1)
    • Programming (3)
      • PHP (3)
    • Software Tips & Tricks (3)
      • Web (3)
    • Web Development (5)
    Agenda assetic automake autotools binhost bundle chillispot chromium os coova-chilli datatables email gentoo github gmail google java-config javascript jquery layman Linux Music openwrt overlay pdf pentium ii php portage programming python radius regex smarty subversion sunrise symfony tabletools tar tips unicode utf-8 wget
    • March 2012 (1)
    • December 2011 (1)
    • April 2011 (2)
    • May 2010 (1)
    • March 2010 (2)
    • February 2010 (5)
    • October 2009 (1)
    • March 2009 (1)
    • October 2008 (2)
    • September 2008 (1)
    • October 2007 (4)
    • How to install Gentoo on a Pentium II in 2010 (Part I) (2)
    • Check UTF-8 input in PHP: only letters (2)
    • Don't let updatedb take your Linux down (2)
    • Introducing SmartyBundle, a Smarty3 bundle for Symfony2 (2)
    • i like: Hardcore/Mathcore/Post-hardcore bands (1)
    • [gentoo] Emerge of subversion fails on java-config (1)
    • tar: file name is too long (max 99) (1)
    • Meme Miner: the translation tool I've been looking for (1)
    • Sanitize filenames with PHP (0)
    • i like: Progressive Rock/Metal bands (0)
    • Erik Søe Sørensen: Thanks a bundle!
    • : Hi. Thanks! Hope you enjoy both SmartyBundle and Symfony2. Take care.
    • 生 李: incredible work!  I'll learn from your bundle to master the service container (dependency ...
    • Steve: I am calling this function with the following and it is consistently returning 'String is OK (only...
    • Victor: Awesome! I did not know about "/u." I have been trying (unsuccessfully) to get ctype_alpha to work...
    • Tweets that mention Don't let updatedb take your Linux down | noisebleed -- Topsy.com: [...] This post was mentioned on Twitter by domaci-tutoriali.com. domaci-tutoriali.com said:...
    • Links 2/5/2010: Screenshot Of GNU/Linux Steam Client; PlayOnLinux 3.7.5 and KDevelop 4.0 Are Out | Techrights: [...] Don’t let updatedb take your Linux down [...]
    • Fred Rocha: No, thank you, Vitor! The tool is intended to make people's life easier. I'll be happy if it shows...
  • Recent Posts

    • Assetic in SmartyBundle
    • Introducing SmartyBundle, a Smarty3 bundle for Symfony2
    • Failed to submit batch buffer (Xorg)
    • Sanitize filenames with PHP
    • Don't let updatedb take your Linux down
  • Latest tweets

    Loading tweets...
    Follow me on Twitter!
  • Blogroll

    • Gentoo Linux
Mystique theme by digitalnature | Powered by WordPress | Background image from Light Graffiti theme
RSS Feeds XHTML 1.1 Top