Canvas & QR-Code

Filed under: Main, Javascript Tips — vincent @ 23:57

I played a little with HTML 5 Canvas and QR-Code.

Using the excellent javascript library from Kazuhiko Arasé, I made an extension to draw a QR-Code in an HTML5 Canvas.

Playing with Google Charts and jQuery

Filed under: Main, Javascript Tips — vincent @ 14:00

Extracting information from table inside the page, and inserting into the very same page a Google Pie Chart? Easily done with jQuery!

List PIDs of child processes

Filed under: Perl tips, Technical — vincent @ 18:31

The next script can be usefull to list all PIDs of a given process and its childs (i.e.: threads also under Linux)

It’s quite brute-force, using /proc extensively. Most probably very Linux specific…

#!/usr/bin/perl -w

use strict;

my $pid=shift @ARGV;

# We'll first make a hash %h where:
# each key is the PID of a process
# each value is a list of the PIDs of the sub-process (direct descendant (ie: children) only, no grand child,...)

# we'll loop on all files under /proc, and take only those whose filename is a number
opendir(DIR,"/proc/") or die ("Can't list proc");
my $file;
my %h=(); # key=pid, value=list of children
while($file=readdir(DIR)) {
        next unless $file =~ m/^d+$/;  # only numbers
        open(STAT,"/proc/$file/stat") or next; # open the stat file for this process
        my $s=<STAT>;
        my @f=split(/s+/,$s);
        # pid: $f[0]   parent PID: $f[3]
        push @{ $h{$f[3]} },$f[0];

my @pids=();

# recursive function to add a pid and the PIDs of children, grand-children,...
sub add($) {
        push @pids,$_[0];
        map { add($_) } @{ $h{$_[0]} } if (defined($h{$_[0]}));
# print join("n", map { $_ . ':' . join(',',sort @{ $h{$_}  } )} sort keys %h);


# output results
print join(' ',@pids)."n";

Code valid in both PHP and SSI

Filed under: Php tips — vincent @ 00:04

In a project that I’m working on, web pages are generated, and sent by FTP to a remote server. Some of those pages are simple HTML pages, others SHTML (i.e.: use server side include, or SSI, to include some blocks of information), and some others are PHP pages.

I’ve been in a case where a given block of code would have to be used both by SHTML and by PHP page. I can generated any code that I’d like, but the same code must be used for the PHP and SHTML blocks. In addition, it would be nice if this block, when seen directly as HTML (no PHP neither SSI parsing), would display correctly.

MySQL data corruption… useServerPrepStmts=false

Filed under: Java Tips — vincent @ 22:38

I’ve undertaken a new project, which uses Hibernate, MySQL, Spring, Maven2 and a few other technologies. During this, I’ve stumbled on a bug, which I first though came from Hibernate, but later discovered to be a MySQL issue.

Encoding problems between Perl and MySql V4.0

Filed under: Perl tips — vincent @ 22:01

MySQL v4.0 doesn’t handle encoding very well. Basically, its considering everything you send it as simple binary data. At least, it doesn’t corrupt it, but no conversion is made. I had to interact, from Perl, with a database which was populated by PHP (v4 also), and which had ISO-8859-1 data in it.

The power of the Perl ‘map’ function

Filed under: Perl tips — vincent @ 23:55

I’ve spent a few years writing Perl without ever looking carefully at the map function, but since I’ve discovered it, I use it often. I propose here some sample usage that I’ve found usefull. I’ll also show how to use the grep function, which is quite similar in usage.

Exporting X authorization to another user

Filed under: Linux — vincent @ 17:44

On my machine, I have a special user account for when I want to make tests. Sometimes, I’d like to run a command under this account while I’m working in my X desktop, without switching desktop.

Please note that this article is not oriented toward people unfamiliar with Unix.

CSS post-processing in PHP

Filed under: Php tips — vincent @ 13:08

While implementing the layout of this site in PHP, I found the tutorial on A List Apart, and wished to implement it here. However, I wanted to be able to change the column widths without having to recalculate manually the different dimensions.

XMLRPC and Lyceum

Filed under: Php tips — vincent @ 14:42

Lyceum is a blog farm written in PHP and based on Word Press. I’ve had to interat with it from Java. I won’t copy here the workarounds needed to Lyceum to be usable through XML RPC, since I’ve already added some at the Lyceum Wiki page. Thanks to the other contributors of that page, they helped me a lot.

Next Page »