Published by Pui-chor on 08 Feb 2012

CSS DIV box horizontally centered

My cantonese tableinput version came across the problem of centering the DIV box for the output. I would like to have a button when clicked will move the output DIV from the very bottome to the middle of the screen when the table is shown with the top part. I tried several ways, setting the position to absolute, relative with various top and left setting and did not work. As the screen size varies for different monitor, it is a tough one. I managed to find one here, idea is from one of the site in internet:

function ContentDown(d)
{
var obj = document.getElementById(d);
if(stateup==’up’){
obj.style.position = “absolute”;
obj.style.top = ‘200px’;
obj.style.left=’50%’;
obj.style.marginLeft=’-370px’;
stateup=’down’;
}
else{
obj.style.position = “relative”;
obj.style.top = ‘10px’;
obj.style.left = ‘0px’;
obj.style.marginLeft=’0px’;
stateup=’down’;
}
}
So when the event happens to move the Content, the position is changed to absolute and setting the top and left with the marginLeft, the DIV will be centered and the value is calculated for the left 50% and the marginLeft is half of the DIV size which is 740px and setting it to -370px will make the DIV horizonally centered.

You can check it out at: http://pcwong.org/cantonese/input/tableinput.html

Published by Pui-chor on 23 Jan 2012

Perl Program to auto-downloading from site

Just save this for my future reference. I have a bunch of file I like to use a program to download it rather than accessing the site and click download or right-click and then choose save and then enter the file name. This is the one:

#! /usr/bin/perl
use CGI qw(:standard);
use strict;
use LWP::UserAgent;

my $ua = new LWP::UserAgent;
$ua->timeout(120);
my $url=’http://en.wiktionary.org/wiki/File:人-order.gif’;

my $request = new HTTP::Request(’GET’, $url);
my $response = $ua->request($request);
my $content = $response->content();

print header(-type => ‘image/gif’);
print $content;

exit;

1;
This program outputs the download but the download can be saved. Mulitple download can be done using a loop as long as there is a pattern for the name of the download.

Published by Pui-chor on 23 Jan 2012

Joining All MP3’s

I did not expect making one mp3 file from a bunch of mp3’s file is so easy. Just to save what is to be done with the perl code that I created in my cantonese site:

my $temp=$sounddir.”/temp”;
my $FROM_IP=$ENV{”REMOTE_ADDR”};
my $all=$FROM_IP.”_”.int(rand(100));
my $tempfile=$temp.”/$all.mp3″;
my $sounds=join(’ ‘,@sndlist);
system(”cat $sounds > $tempfile”);
$text.=”<a id=’whole’ style=’display:none;’_href=’http://pcwong.org/audio/temp/$all.mp3′>.</a>\n”;

I am using just a system cat command which appends one mp3’s content to another untile all file are put together in one single file. Same is for the text using cat command. If anyone does not know cat command will do in unix, you can search for it.

- Next »