How To Fix “Metadata file does not match checksum” YUM error

December 30th, 2009 Masao No comments
# 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!
Categories: YUM Tags:

Perl Version of PHP’s “ucwords” Function

December 15th, 2009 Masao 1 comment
my $string = 'this is a string of text';
$string =~ s/\b(\w+)\b/ucfirst($1)/ge;
print "$string\n";
Categories: PHP, Perl Tags:

How To Merge PHP Objects

December 12th, 2009 Masao No comments
foreach($objectA as $k => $v) $objectB->$k = $v;
Categories: PHP Tags:

How To Change Your CPAN urllist

September 17th, 2009 Masao No comments

# cpan
cpan> o conf init

Connecting to ftp.perl.org|64.27.65.115|:21… connected.
Logging in as anonymous … Logged in!
==> SYST … done. ==> PWD … done.
==> TYPE I … done. ==> CWD /pub/CPAN … done.
==> SIZE MIRRORED.BY … 140951
==> PASV … done. ==> RETR MIRRORED.BY … done.
Length: 140951 (138K)

100%[===========================================================>] 140,951 374K/s in 0.4s

17:21:36 (374 KB/s) – `-’ saved [140951]

Now we need to know where your favorite CPAN sites are located. Push
a few sites onto the array (just in case the first on the array won’t
work). If you are mirroring CPAN to your local workstation, specify a
file: URL.

First, pick a nearby continent and country (you can pick several of
each, separated by spaces, or none if you just want to keep your
existing selections). Then, you will be presented with a list of URLs
of CPAN mirrors in the countries you selected, along with previously
selected URLs. Select some of those URLs, or just keep the old list.
Finally, you will be prompted for any extra URLs — file:, ftp:, or
http: — that host a CPAN mirror.

(1) Africa
(2) Asia
(3) Australasia
(4) Central America
(5) Europe
(6) North America
(7) Oceania
(8) South America
Select your continent (or several nearby continents) []

Categories: Everything Else Tags:

How to Install Flash Firefox Plugin for 64-bit Fedora Linux

September 13th, 2009 Masao No comments
  1. Download the plugin here.
  2. Tar -zxvf the tar.gz file.
  3. Copy that file to: /usr/lib64/mozilla/plugins
  4. Restart firefox.
  5. 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

Categories: Firefox, Flash, Linux Tags:

No recognized SSL/TLS toolkit detected

September 5th, 2009 Masao No comments

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

Categories: Errors Tags:

How To Add a MySQL Column with Index

September 5th, 2009 Masao No comments

ALTER TABLE mytable
ADD mycolumn INT UNSIGNED NOT NULL AFTER othercolumn ,
ADD INDEX ( mycolumn );

Categories: MySQL Tags:

How To Fix a Perl Memory Leak

September 3rd, 2009 Masao No comments

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

Categories: Perl Tags:

How To Determine Directory of Sourced Bash Script

September 2nd, 2009 Masao No comments

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]%/*}

Categories: Bash, Linux Tags:

Hotel Room Problem

August 28th, 2009 Masao 1 comment

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?

Categories: Cool Problems Tags:

How To Redirect STDERR to STDOUT in Perl

August 28th, 2009 Masao No comments

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.
Categories: Perl Tags:

Failure: The Secret to Success

August 23rd, 2009 Masao No comments

Categories: Everything Else Tags:

How to Fix an Empty Bash Shell Prompt

August 21st, 2009 Masao No comments

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
Categories: Bash, Linux Tags:

Burning Rope Problem

August 13th, 2009 Masao 1 comment

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?

Categories: Cool Problems Tags:

8 Bricks Problem

August 13th, 2009 Masao 1 comment

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?

Categories: Cool Problems Tags:

Monty Hall Problem

August 13th, 2009 Masao 1 comment

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?

Categories: Cool Problems Tags:

How To Know If You Have a 64-bit Processor

August 5th, 2009 Masao No comments

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).

Categories: Hardware, Linux Tags:

How to Fix Ugly Sidebar in Wordpress iNove Theme

August 5th, 2009 Masao No comments

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!

Categories: Wordpress Tags:

MySQL Slow Query Optimization Tips

July 26th, 2009 Masao No comments

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.

Categories: MySQL Tags:

How to Convert Seconds to Minutes in BASH

July 22nd, 2009 Masao No comments

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

Categories: Bash Tags: