/kb

personal knowledgebase

php5-imagick error in Ubuntu 8.04

without comments

I got the following error message, caused by a bug in Ubuntu.:

PHP Warning:  PHP Startup: Unable to load dynamic library
'/usr/lib/php5/20060613+lfs/imagick.so' -
libWand.so.9: cannot open shared object file:
No such file or directory in Unknown on line 0 finished.

Here’s the solution.

Written by hgrimelid

July 17th, 2008 at 1:42 pm

Posted in Server

Tagged with , , , ,

Pasting text in terminal VIM

without comments

Pasting code into a VIM running in terminal has never worked properly for me. It occured to me that Google might have some information on the topic. It turned out to be ridiculously easy:

:set nopaste

Paste your code, and then:

:set paste

Ref.: vim.org.

Written by hgrimelid

July 16th, 2008 at 5:42 pm

Posted in Editors

Tagged with

Repairing corrupted FAT32 drive

without comments

By using fsck as described below I managed to restore one of my hard drives.

$ fsck.msdos -r -v -V /dev/hda2

According to the man file, the options have the following effects:

-r Interactively repair the file system. The user is asked for advice whenever there is more than one approach to fix an inconsistency.
-v Verbose mode. Generates slightly more output.
-V Perform a verification pass. The file system check is repeated after the first run. The second pass should never report any fixable errors. It may take considerably longer than the first pass, because the first pass may have generated long list of modifications that have to be scanned for each disk read.

Reference: Fedora Mailing List.

Written by hgrimelid

June 28th, 2008 at 1:30 pm

Posted in General

Tagged with , ,

Strings and equality in Java

without comments

In order to compare objects in Java we are taught to use the equals()-method, except when the goal is to check for object reference, explicitly, then the == operator must be used. However, String objects does not behave entirely as expected, as seen from the following example.

  String s1 = "Fish";
  String s2 = "Fish";
 
  String s3 = new String("Fish");
  String s4 = new String("Fish");
 
  System.out.println(s1 == s2);       // true
  System.out.println(s1.equals(s2));  // true
 
  System.out.println(s3 == s4);       // false
  System.out.println(s3.equals(s4));  // true

The reason for this behaviour is that strings s3 and s4 are created outside of the string pool. In the string pool, String objects with the same value are set to the same object internally in order to save space.

Written by hgrimelid

June 4th, 2008 at 1:32 pm

Posted in Programming

Tagged with ,

Create a new MySQL-user with all privileges

without comments

GRANT ALL PRIVILEGES ON thedatabase.* TO 'theusername'@'localhost'
	IDENTIFIED BY 'thepassword' WITH GRANT OPTION;

UPDATE 20080916: Skip the last line if the user exists.

Written by hgrimelid

May 17th, 2008 at 7:26 pm

Posted in Server

Tagged with

Root partition free space

without comments

du -xh --max-depth=1  /

Written by hgrimelid

May 17th, 2008 at 7:21 pm

Posted in Shell

Tagged with ,

On using find

without comments

find is an extremely powerful command. In order to leave the directory matching *DIRECTORY* out from your search for .txt-files:

find . -path '*DIRECTORY*' -prune -o -iname '*.txt' -print

If you’re using xargs together with find and xargs complains about file names with spaces, use:

find . YOURFINDOPTIONSHERE -print0 | xargs -0 rm -rf

Finding files larger than a certain limit:

find . -size +200M -print0 | xargs -0 ls -lh

Deleting the complementary files:

find . ! -name "*.mp3" -delete

Courtesy of HÃ¥kon.

Please note that these commands pertains to the BSD find as on Mac OS 10.5.

UPDATE 20080517: Looking for file size
UPDATE 20080602: Added deleting complement

Written by hgrimelid

May 15th, 2008 at 12:49 pm

Posted in Shell

Tagged with , , , ,

Backup a MySQL database with mysqldump

without comments

It’s very easy, but I always have to look it up.

mysqldump --opt -u USERNAME -p -h HOST.HOST.COM DATABASE_TABLE > DUMPFILE.sql

Written by hgrimelid

May 14th, 2008 at 6:29 pm

Posted in Server

Tagged with , , ,

Some useful Vim-commands

without comments

There are numerous pages and blog posts about Vi and Vim out there so here’s my small contribution. Here are some less frequently used commands that tends to be useful from time to time:

Delete lines patching pattern
:g/pattern/d
Go to position previously modified
g;
Go to next modified position in change list
g,
Create bookmark in file
mLETTER
Go to bookmark
'LETTER
Change highlighted text to upper case
gU
Open file under cursor
gf
Coopy text mathich pattern to register a
:/pattern/yank A
Paste text from register a
"ap
Reduce split window size
C-w -
Increase split window size
C-w +
Make split windows equally big
C-w =

Written by hgrimelid

May 14th, 2008 at 12:36 pm

Posted in Editors

Tagged with , , ,

Prettify print_r output

without comments

By putting print_r() statements enclosed by html pre-tag, the output is quite a lot more readable.

Written by hgrimelid

May 7th, 2008 at 6:21 pm

Posted in Programming

Tagged with ,