php5-imagick error in Ubuntu 8.04
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.
Pasting text in terminal VIM
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.
Repairing corrupted FAT32 drive
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.
Strings and equality in Java
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.
Create a new MySQL-user with all privileges
GRANT ALL PRIVILEGES ON thedatabase.* TO 'theusername'@'localhost' IDENTIFIED BY 'thepassword' WITH GRANT OPTION;
UPDATE 20080916: Skip the last line if the user exists.
Root partition free space
du -xh --max-depth=1 /
On using find
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
Backup a MySQL database with mysqldump
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
Some useful Vim-commands
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 = |
Prettify print_r output
By putting print_r() statements enclosed by html pre-tag, the output is quite a lot more readable.