December 30th, 2009
Masao
# yum install -y ImageMagick-perl
Loaded plugins: fastestmirror
Setting up Install Process
Parsing package install arguments
Resolving Dependencies
--> Running transaction check
---> Package ImageMagick-perl.i386 0:6.2.8.0-4.el5_1.1 set to be updated
filelists.xml.gz | 3.9 MB 00:09
http://apt.sw.be/redhat/el5/en/i386/rpmforge/repodata/filelists.xml.gz: [Errno -1] Metadata file does not match checksum
Trying other mirror.
filelists.xml.gz | 3.9 MB 00:29
http://ftp-stud.fht-esslingen.de/dag/redhat/el5/en/i386/rpmforge/repodata/filelists.xml.gz: [Errno -1] Metadata file does not match checksum
Trying other mirror.
filelists.xml.gz | 3.9 MB 00:12
http://fr2.rpmfind.net/linux/dag/redhat/el5/en/i386/rpmforge/repodata/filelists.xml.gz: [Errno -1] Metadata file does not match checksum
Trying other mirror.
Error: failure: repodata/filelists.xml.gz from rpmforge: [Errno 256] No more mirrors to try.
Run the following commands:
yum clean all
yum makecache
yum update
Then, it should work:
# yum install -y ImageMagick-perl
Loaded plugins: fastestmirror
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package ImageMagick-perl.i386 0:6.2.8.0-4.el5_1.1 set to be updated
--> Finished Dependency Resolution
Dependencies Resolved
====================================================================================================
Package Arch Version Repository Size
====================================================================================================
Installing:
ImageMagick-perl i386 6.2.8.0-4.el5_1.1 base 145 k
Transaction Summary
====================================================================================================
Install 1 Package(s)
Update 0 Package(s)
Remove 0 Package(s)
Total download size: 145 k
Downloading Packages:
ImageMagick-perl-6.2.8.0-4.el5_1.1.i386.rpm | 145 kB 00:00
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : ImageMagick-perl 1/1
Installed:
ImageMagick-perl.i386 0:6.2.8.0-4.el5_1.1
Complete!
December 15th, 2009
Masao
my $string = 'this is a string of text';
$string =~ s/\b(\w+)\b/ucfirst($1)/ge;
print "$string\n";
December 12th, 2009
Masao
foreach($objectA as $k => $v) $objectB->$k = $v;
September 13th, 2009
Masao
- Download the plugin here.
- Tar -zxvf the tar.gz file.
- Copy that file to: /usr/lib64/mozilla/plugins
- Restart firefox.
- Check “about:plugins” in your address bar to see the Flash plugin installed
Plugin file should look like this:
/usr/lib64/mozilla/plugins/libflashplayer.so
about:plugins should look like this:
Shockwave Flash
File name: nswrapper_64_64.libflashplayer.so
Shockwave Flash 10.0 r32
September 5th, 2009
Masao
While running Apache configure, if you get this error:
No recognized SSL/TLS toolkit detected
…do this:
yum install -y openssl-devel # Required for Apache configure
September 3rd, 2009
Masao
If you’re using HTML::TreeBuilder, you might find a memory leak when creating lots of trees. You must explicitly delete the trees because HTML::Tree does not use weak refs. Here’s how to delete the ref:
use HMTL::TreeBuilder;
my $formatter = HTML::FormatText->new();
my $html_tree = HTML::TreeBuilder->new_from_content($line);
my $plain_text = $formatter->format($html_tree);
$html_tree->delete();
Or if you use HTML::Parse:
my $html_tree = parse_html($line);
$html_tree->eof();
my $plain_text = HTML::FormatText->new()->format($html_tree);
$html_tree->delete();
Or using Object::Destroyer
use Object::Destroyer;
my $html_tree = parse_html($line);
$html_tree = Object::Destroyer->new($html_tree, ‘delete’);
$html_tree->eof();
my $plain_text = HTML::FormatText->new->format($html_tree);
Source: perlmonks.org
September 2nd, 2009
Masao
Sourcing a script can be useful for exporting variables in the current shell.
However, you can’t use “dirname $0″ to get the directory of the script.
Here’s how to get the same effect of dirname, but still allowing you to export variables.
Relative path:
DIRNAME=${BASH_ARGV[0]%/*}
Full path:
ABSDIR=$PWD/${BASH_ARGV[0]%/*}
Three men decided to split the cost of a hotel room. The hotel manager gave them a price of $30.
The men split the bill evenly, each paying $10, and went to their room. However, the hotel manager realized that it was a Wednesday night, which meant the hotel had a special: rooms were only $25. He had overcharged them $5!
He called the bellboy, gave him five one-dollar bills and told him to return it to the men.
When the bellboy explained the situation to the men, they were so pleased at the honesty of the establishment that they promptly tipped the bellboy $2 of the $5 he had returned and each kept $1 for himself.
So each of the three men ended up paying $9 (their original $10, minus $1 back) totaling $27, plus $2 for the bellboy which makes $29. So where is the missing dollar?
Redirecting STDERR to STDOUT in Perl:
open STDERR, '>&STDOUT';
Reassign raw file handles:
*STDERR = *STDOUT;
Redirect all output to a logfile:
open(LOG,">/tmp/foo.log");
*STDERR = *LOG;
*STDOUT = *LOG;
Example:
#!/usr/bin/perl
use strict;
use warnings;
warn "regular error";
open STDERR, '>&STDOUT';
warn "redirected error";
Output:
[kitamura@web3 perl]$ ./stderr.pl 2>/dev/null
redirected error at ./stderr.pl 6.
If you bash shell prompt is empty when logging in, here’s how to fix it.
Create a ~/.bashrc file:
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
Create a ~/.bash_profile file:
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
You have two ropes that each burn for 1 hour end to end, but at varying rates.
You have a lighter. You cannot cut the ropes (and doing so wouldn’t help, since they burn at unknown rates and you only know total burn time).
How do you measure 45 minutes?
You have 8 bricks, but one of them is lighter than the rest.
You have a balance you can only use twice.
How do you find the lighter brick?
Of three options, you have a 1/3 chance of picking the “right” option.
If you pick one at random, then a single “wrong” option is eliminated, should you switch and why?
If you have asked yourself, “Do I have a 64-bit processor?”, then here are several ways to find out:
uname
# uname -p
x86_64
cpuinfo
# cat /proc/cpuinfo
flags : fpu vme de pse tsc msr pae mce cx8 apic mtrr
pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm
pbe syscall lm constant_tsc arch_perfmon pebs bts rep_good pni
dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm lahf_lm tpr_shadow
bogomips : 4255.87
clflush size : 64
cache_alignment : 64
address sizes : 36 bits physical, 48 bits virtual
The “lm” flag stands for Long Mode.
You can read more in this file:
/usr/src/kernels/#.#.#-#.#.fc11.x86_64/arch/x86/include/asm/cpufeature.h
#define X86_FEATURE_LM (1*32+29) /* Long Mode (x86-64) */
lshw
# lshw
*-cpu
description: CPU
product: Intel(R) Core(TM)2 CPU 6420 @ 2.13GHz
width: 64 bits
From the lshw manpage:
lshw is a small tool to extract detailed information on the hardware configuration of the machine. It can report exact memory configuration, firmware version, mainboard configuration, CPU version and speed, cache configuration, bus speed, etc. on DMI-capable x86 or IA-64 systems and on some PowerPC machines (PowerMac G4 is known to work).
The iNove theme gives your wordpress blog a Mac-ish look and feel. However, the sidebar has some ugly built-in widgets. Here’s how to remove them.
In themes/inove/sidebar.php, remove everything between these lines:
<!-- sidebar north END -->
...
delete everything here
...
<!-- sidebar south END -->
Done!
Slow Query Example
SELECT
widget_id
, widget_name
, COUNT(DISTINCT type) AS num_types
FROM widget
GROUP BY type
ORDER BY num_types DESC
With lots (>100K) of rows, this query will get slow because it orders on an aggregate COUNT DISTINCT function. Remove the ORDER BY to make this fast again.
This is how to convert seconds into HH:MM:SS in bash:
$ date -d '1970-01-01 100 sec' +'%H:%M:%S'
00:01:40
Recent Comments