Friday, December 12, 2008

[Tips] List of protocols supported by Konqueror

I always use Konqueror as an alternative web browser to Firefox and to access my mobile phone via Bluetooth.
I just find out that Konqueror supports lots of other protocols.
See http://en.opensuse.org/Konqueror_Tips_and_Tricks

Monday, December 8, 2008

Webcast of OpenSolaris

Here is a little webcast from a OpenSolaris evangelist that shows the cool features of OpenSolaris 8.11, in particular ZFS in action
http://webcast-west.sun.com/interactive/09A12416/index.html

Monday, November 10, 2008

[perl] Few tips

*To Jump to a variable/function declaration, type:
gd
Found at http://www.moolenaar.net/habits.html

*To check if a user has an account on a host, you can use getpwnam
Found at http://www.perl.com/doc/manual/html/pod/perlfunc/getpwnam.html
See also getgrnam and other variants get*


*Some perl variables:
$<, $>
Description of those special perl variables at http://affy.blogspot.com/p5be/ch12.htm
Those threads may help you understand
http://www.linuxforums.org/forum/redhat-fedora-linux-help/106602-difference-between-uid-effective-uid.html
http://stackoverflow.com/questions/205070/whats-the-deal-with-all-the-different-uids-a-process-can-have

Monday, August 4, 2008

[bash]Which file takes the most of the space

I was just asked to investigate on a problem.
None of the user could not log in to our application that uses OpenLDAP.
We restarted the slapd daemon, had a look at /var/log/apache2/error.log but nothing showed up. Weird
A sample df -h showed me that the available amount of space was 0% :(.
So to find out which file takes most of the space, run the command:

find / -type f -size +20000k -exec ls -lh {} \; | awk '{ print $8 ": " $5 }'

and it will return the name of the file and its size.
Tip found here

Friday, July 25, 2008

[Bash] Include a shell script within another one

I just found out today how to include a shell script into another one.
It doesnt use the keyword 'include' like in javascript or php.
A simple dot '.' will just do the trick.

===== bash1.sh =======
#!/bin/bash

export MESSAGE="Hello World"
export MESSAGE2="Hello World 2"
echo $MESSAGE
echo $MESSAGE2

===== bash2.sh =======

#!/bin/bash

. bash1.sh
echo $MESSAGE
echo $MESSAGE2

When running bash2.sh, you will see:

Hello World
Hello World 2
Hello World
Hello World 2

Explanation:
You may think that running the bash1.sh script with :
./bash1.sh
would work but no. Why?
When running ./bash1.sh (or a call to the bash1.sh script with an absolute path), the current shell will create a child process and run the bash1.sh script within it.
When the child process finished, bash2.sh carries on but doesnt display anything for the

echo $MESSAGE
echo $MESSAGE2

lines
For this you will have to run the bash1.sh script within the current shell instead of creating a child process. And you are doing this by using the '.' or you can use the 'source' command.

'.' or 'source' will run the bash1.sh in the current shell, so when bash1.sh will finish to run , the environment variables $MESSAGE and $MESSAGE2 set from bash1.sh will persist wihtin the current shell and you' ll be able to use them from bash2.sh

Friday, July 4, 2008

[Bash] Populate command line with occurrences

Little tip for bash users:

Let's say you want to delete all files in a directory that starts by 'exam' except one. I would use 'rm' and put all the file names I want to delete manually as there is just one I want to keep.
By typing:

rm exam[ESC + *]

the command [ESC + *] will populate the argument line with all occurrences of 'exam'.

And now, you can remove the file you want to keep from the list.

If you're lucky and the file you want to keep is the last one, a simple [Ctrl + W] will remove the last argument passed in the command line.

The tip was found here(in french)

Friday, May 30, 2008

[perl] Regular expressions

* Oneliner to remove spaces at the beginning and at the end of a string (trim)
$string =~ s|^(\s*)(.*?)(\s*)$|$2|s;

* Replacing "::" by "/" . This can be useful when you want to see if you can load a module at run time

$module =~ s|::|/|g;
eval "require $module.pm";

Tuesday, May 27, 2008

[mysql] - Dropping tables without caring about relationships

On Mysql, to avoid having a
"Cannot delete or update a parent row: a foreign key constraint fails"
message when dropping tables with relationships between them, you can set the flag
SET FOREIGN_KEY_CHECKS=0;
at the very beginning of your sql script.

Monday, May 19, 2008

[Tip] How to concatenate pdf files

Sometimes, I received some few documents in pdf format and I would rather read them as a whole document than to close one page and open the next one.

The tool "pdftk" can be used to concatenate the different pdf files to create 1 file containing the whole

See this tutorial on how to use it

Friday, May 2, 2008

Which Linux version am I running?

I can't never remember which version of GNU/Linux I'm running on. I know I use Ubuntu but is it Gutsy Gibbon? Hoary Hedgehog? Feisty Fawn?

I just found out about a tool called lsb_release.

lsb_release is a tool created by the LSB (Linux Standard Base) that returns information about the distribution name, version, codename... So this tool should be available on most of the GNU/Linux distribution.

The output will look like this:

cyril@merlin:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 7.10
Release: 7.10
Codename: gutsy


Time to upgrade to Hardy Heron

Tuesday, April 29, 2008

Perl - How to merge 2 simple hashes ?

How to merge 2 hashes ? with the use of hash slice:

my %hash1 = ( hello1 => 'world1' , foo1 => 'bar1', hello2 => 'foobar' );
my %hash2 = ( hello2 => 'world2' , foo2 => 'bar2' );
my %hash = %hash1; # %hash contains the same keys/values as hash1
@hash{keys %hash2} = values %hash2; # We merge the content of hash2 with hash


This uses hash slices in order to merge the content of hashes. Slices can also be used to remove duplicates entries in an array:

my @array = qw/hello world foo bar hello/;
my %hash;
@hash{@array} = undef;
my @array = keys(%hash);

Friday, April 11, 2008

Transforming Unicode

I used to work in the localisation industry (terrible world).
Once, a former colleague asked me if it would be possible to retrieve the japanese characters from the unicode string. With Perl, the answer is "YES"
Just make sure you have the module Unicode::Escape installed, save your unicode string in a text file (i.e. unicodetext.txt) and run the oneliner:

perl -MUnicode::Escape -ne 'print Unicode::Escape::unescape($_);'/path/to/unicodetext.txt

Example with some strings in russian:
With a unicode string:

\u041f\u0440\u0435\u0434\u0438\u0441\u043b\u043e\u0432\u0438\u0435


the result would be:

Предисловие

Your favorite Linux command

I am subscribed on a french Linux mailing list, lea-linux.org and one of the moderator, Emmanuel F., sent this nice command to find out what your favorite command is:

history|awk '{a[$2]++ }END{for(i in a){print a[i] " " i}}'|sort -rn|head

Tuesday, April 8, 2008

modperl - PerlAuthenHandler

Let's say you are working on tenth of web services. All of them work perfectly.
And one day, your boss comes to you and says: "I need you to implement an Authorization mechanism for every web services".
How do you think you can do that?
You can create a class and edit every single handlers (web services) to handle authentication at the application level.
or
You can use the power of modperl and do this at the server level.

Apache runs several phases (some depends on your configuration) before running the actual code you want to serve (called the response handler).
Those phases can be found here

The interesting phase (or HTTP handler) for authentication is PerlAuthenHandler.

A basic configuration would be :

<Location /mywebservice/>
##############
# The below directives are mandatory in order
# to step in the PerlAuthenHandler phase
AuthType Basic
AuthName Test
Require valid-user
##############
SetHandler perl-script
PerlAuthenHandler MyAuthenticationModule
PerlResponseHandler MyWebService
</Location>


Only the "Basic" type of authentication is supported (at the moment?)
When running this phase, your favorite web browser would pop up a login window.
You would then have to implement your authentication mechanism in the handler set at PerlAuthenHandler (in our case MyAuthenticationModule).

The description of the PerlAuthenHandler is quite straight forward.

This type of Authentication is called "Basic HTTP Authentication". After successful authentication, for every requests your browser will send, the HTTP request header will contain a "Authorization" field containing your credentials (username/password) encrypted with an base-64 algorithm.
To reset the credentials, the server will have to call $r->note_basic_auth_failure and return a status code Apache2::Const::HTTP_UNAUTHORIZED.

If you want a fancy web interface to deal with Basic HTTP authentication, my advise is to forget about it as there is no way to reset credentials (if you want to simulate a timeout session) except with the method above, but you will always get the login window ...

So all you have to do is to edit the Apache configuration file and include the above directives without touching any code of your web services.

modpython also has access to HTTP handlers. It uses the same name as modperl for configuration directives (smart move). I m not sure if php has this feature of using Apache HTTP handlers, to investigate...

Monday, April 7, 2008

What is poti marara?

What is a "poti marara"?
"Poti marara" is a polynesian speed boat used for fishing.
The boat is drivable by a stick. Like this, the fisherman can drive the boat with one hand and hold in the other hand his harpoon or net.

A photo and a more-detailed description can be found here

Why did I choose this name?
Because I like it.

Introduction

No, "New Kids On The Blog" is not a blog about a boy band from the 80s-90s.
It's my (Cyril Cheneson) blog. Here, I' ll talk mainly about stuff I am working on (Apache, modperl, LDAP...), but also about anything.

See a short biography:
I am Cyril. I was borned in a tiny island lost in the middle of the Pacific Ocean called Tahiti which is part of the French Polynesia. No, we are not savage, we do have clothes and we do speak french.

I grew up there and moved to France at around 15-16 years old.
After getting my leaving certificate (baccalaureat) with a speciality in electronics, I continue my studies in M.I.T.(Montpellier Institut of Technology) in GEII (Electronic Engineering and Industrial Computing). After those 2 years study and the diploma, I moved to Dublin,Ireland where I work as a QA engineer and Test Automation Engineer for 6 years.

Today, I live in Prague (+2.5 years), Czech Republic where I work first as a perl developper for MonsterTRAK (a division of Monster.com) and now,I work as a perl developper for a company specialized in 3 differents businesses: Video streaming for mobile phones, J2me games and web development.

I like:
  • hiking
  • inline/ice skating
  • snowboarding
  • biking (but dont have a bike at the moment)
  • travelling
  • meeting new people
  • music
  • computers
  • sports (squash, basketball ...)
I don't like
  • doing nothing at work for weeks
  • Dublin Bus
I hope I will find the time to update this blog as often as possible but most of the time, lazyness takes over motivation but stay tune.