andre's blog

Tradegy in Oslo

We are all devastated by the terrible events in Oslo, Norway, where almost 100 people were killed in two closely linked incidents of terrorism. Browsing the news about these events, I couldn't help but notice facial similarity between the alleged executor of the terrible acts, a certain Anders Behring Breivik, and the notoriously famous manager of Wikileaks, Julian Assange.


Vim line wrapping and word boundary

Vim (vi) is a very powerful and customizable text editor. There are many parameters you can fine-tune to adjust the way your data is displayed. For example, vim can visually wrap lines, which are too long to fit the width of the screen. This is "virtual" wrapping - no new line characters are actually added to the text. By default, vim wraps the text at the last character, which fits in the visible area. However, especially when editing long runs of text, it is much more convenient to see lines wrap at word boundaries. To achieve this simply use the following command:

Editing Markdown or txt files in OpenOffice

I have been introduced to Markdown format some time ago and today I find it extremely convenient for most of the writing I need to do. Markdown is essentially "markup without markup" - it requires you to do very little in order to format your text and it can be easily converted in a number of other formats, such as PDF, Word, ODT, LaTeX, HTML, Docbook etc. From experience I found that the most convenient environment to edit Markdown files is OpenOffice (or LibreOffice). Not only is it free and open source, it is actually quite convenient.

Right-align help menu in a WPF application

If you want to right-align the "Help" (or any other) menu entry in your menu bar in a WPF application, you can use the following example:

  1. <Menu>
  2.     <Menu.ItemsPanel>
  3.         <ItemsPanelTemplate>
  4.             <DockPanel HorizontalAlignment="Stretch"/>
  5.         </ItemsPanelTemplate>
  6.     </Menu.ItemsPanel>
  7.     <MenuItem Header="File">
  8.         <MenuItem Header="Exit"/>

How to change shell prompt in Midnight Commander

Bash allows users to do very advanced things when defining shell prompt, including colours and propagation of information into xterm title. Unfortunately, when you want to use mc (Midnight Commander) in conjunction with bash prompts, you may find, that not all advanced escape sequences are handled by mc properly. To overcome this issue you can have a special prompt just for mc. To achieve that, consider the following shell snippet:

Sample .vimrc file for software developers

Vim is a very powerful and convenient text editor for Unix environments. I certainly don't wish to start any disputes along the lines of the old vim/emacs frontier, especially since I used both of them for long periods of time and find unique features in each. However in recent years I tend to use vim most of the time, mainly because it is quite lightweight. In order to benefit the most from the editor it needs to be configured to suit my specific requirements.

Opening new e-mail form of the default mail client in a WPF / WinForms application

Sometimes, while writing a WPF or WinForms GUI application, you might need to allow the user to send a pre-populated e-mail from her machine. A typical example would be sending an e-mail to your technical support from the application. A naive approach to implement this functionality is to use the following code sniplet:


Use system icons in WPF

Sometimes you would like to use a standard Windows system icon, such as error, warning, question etc. in your WPF program. The main reason is usually consistent look with the rest of the system. While you could have extracted the desired icon from one of the system resource files, there is a much better technique for doing it. First, add a reference to System.Drawing to your project. Then you can use this sample code to get the desired icon quickly:


Side by side editing of .resx files for localization

WPF allows you to create localized applications with relatively little effort. The localized strings are put into resource files (.resx), one per target language, and maintained as needed. The editing facilities of Visual Studio, however, are not designed to help the localization efforts, however. The GUI can only show one resource file at a time.