Archive for July, 2007

tar and hidden files

tar doesn’t want to include hidden files in your archive? Probably you are using command tar cf archive.tar * or something similar. Try to use tar cf archive.tar ./ instead of * interpolation.

Friday, July 27th, 2007

XML serialization for Dictionary generic

For some reasons Microsoft made their generic Dictionary<TKey, TValue> class not XML-serializable. But making your own Dictionary that supports XML serialization is very simple. All you have to do is to write an implementation of IXmlSerializable interface.
(more…)

Tuesday, July 24th, 2007

Generic Pair .NET class

If you ever worked with C++ STL library you might remember pair template, which sometimes was very useful. .NET Framework has similar generic KeyValuePair<TKey, TValue>. But as it is designed to work with Dictionary class KeyValuePair has one sufficient constraint: it does not have public setters for Key and Value properties.

So I wrote my own generic Pair class and extended it with some useful static routines.
(more…)

Monday, July 16th, 2007

Trimming two sides of an image

I had a task to trim two sides of an image in script using Imagemagick. If you were working with command-line Imagemagick, then you surely know perfect examples of its use. There is an instruction how to trim one side of the image. Expanding this example we can create the following command to trim bottom and right borders:

convert image.png -background white -splice 0x1 -background black -splice 0x1 -trim +repage -chop 0x1 -background white -splice 1x0 -background black -splice 1x0 -trim +repage -chop 1x0 trim.png

It works nicely, but if you know background color of your image, you can simplify command. Let’s assume that we want to trim white background. Just add one black dot in top left corner, trim the image and chop image by one pixel from left and top:

convert -background white xc:black -size 1x1 -page +1+1 image.png -mosaic -trim +repage -chop 1x1 trim.png

Saturday, July 14th, 2007

Firefox word selection without trailing space

I hated long time that when I double click word in Firefox, it’s being selected together with a space. I hated it so much, that one day I entered into Firefox configuration editor (about:config) and found configuration value that is responsible for this behavior. Here it is – layout.word_select.eat_space_to_next_word, just change it to false and enjoy.

Friday, July 13th, 2007

Parsing large mysql dumps

Recently I faced a problem – I had large mysql dump on remote machine and I needed just some tables from it. Dump file was about 900 Mb, bzip’ed – around 60 Mb. I didn’t want to download it just for about 1 Mb of required data. First idea that came into my head – load this dump to the database on remote machine and then dump again only required tables. The problem that I had no possibility to do that – I had just ftp/ssh access. So, I opened this ~1Gb sql file with vi. It opened it even with syntax highlighting! But when I tried to remove 2 millions of unnecessary lines it hanged forever… Emacs wasn’t better.
(more…)

Saturday, July 7th, 2007