Dark theme for Mac Terminal with cool prompt
OSX now have fairly decent terminal app - but with one problem - default dark themes is horrible (and Terminal must be dark!).
So now I have the following:
How to do it?
Here is instructions - http://blog.toddwerth.com/entries/show/6, but if you have 64-bit Snow Leopard (like mine MacBook Air) you must use this SIMBL plugin - http://github.com/timmfin/terminalcolours/raw/master/TerminalColours-SL-64bit.zip (thanks for http://www.nightlion.net/themes/2010/osx-terminal-theme/)
Another cool thing from http://www.nightlion.net/themes/2010/osx-terminal-theme/ - is it’s multiline prompt, but this prompt has bug - if you try to enter command that longer than terminal width - it’s not go to the newline but overwrite current line. Here is correct one (from my config, also commented another cool looking prompts):
export TERM="xterm-color" alias ls="ls -G" export PS1="\[\e[1;30m\]\[[\e[\e[1;30m\]\e[1;33m\] \u@\H \[\e[1;32m\]\w\[\e[0m\] \[\e[1;30m\]\[]\]\n\[[\[ \[\e[1;31m\]\T\[\e[0m\] \[\e[1;30m\] \[]\] \[$\] \[\e[37m\]" #export PS1='\n\[\033[1;34m\]\342\226\210\342\226\210 \u @ \w\n\[\033[0;36m\] \342\226\210\342\226\210 \t $ \[\033[0;39m\]' #export PS1='\[\033[01;36m\]\w\[\033[00m\]\n\[\033[01;32m\]\u@\h\[\033[00m\]\$ ' export CLICOLOR=1 export LSCOLORS=ExFxCxDxBxegedabagacad
more info about configuring bash prompt - http://wiki.linuxquestions.org/wiki/Bash_prompt#Multi-line_prompts
Install Mercurial on OSX
You must use homebrew (http://mxcl.github.com/homebrew/) as package manager - install it.
then
brew install python
brew install pip
pip install mercurial
sudo ln -s /usr/local/Cellar/python/2.7.1/bin/hg /usr/bin/hg
Debug Windows Mobile applications on real device
Highly recommend this article - rare type of article about migrating real-world application from one platform – iPhone - to another - windows mobile, great in comparing and adopt different approaches to development.
So one of things that I realized only when reading this article - is that we can debug Windows Mobile applications on real device, connected to desktop, not in emulator, and it’s very helpful.
It’s easy – between various emulators in default devices setting for project we have “Windows Mobile 6 Professional Device” – and it works fine.
Nested (inner) object initializers
Object initializers are probably most usable feature from C# 3 in my daily work. It was adopted by me since the beginning but only today I found that its support nesting, look:
var edit = new TextEdit(); edit.Name = "passwordEdit"; edit.Properties.PasswordChar = '*';
It’s simple but real code, without initializers, how we can improve it? Before today’s knowledge only like this:
var edit = new TextEdit{
Name = "passwordEdit"
}
edit.Properties.PasswordChar = '*';Because we can’t write:
var edit = new TextEdit{
Name = "passwordEdit",
Properties.PasswordChar = '*'
}And now, proper syntax:
var edit = new TextEdit{
Name = "passwordEdit",
Properties = {
PasswordChar = '*'
}
}
Awesome. I hope some day we can attach event handlers with object initializers like Miguel de Icaza proposed.
GAC GUI/.Net 2.0 Configuration
It appears that if we go to Control Panel\Administrative Tools – we found tool called Microsoft .NET Framework 2.0 Configuration.
And with this tool has GUI for work with GAC – list, register, unregister - without need to use gacutil. I think sometimes (and for some people :)) it may be very helpful – while console utils is right way, of course.
Real world refactoring
I often find code like this in some projects:
public bool ShowDialog(object view, string title)
{
//some code
var window = GetWindow(control,title);
//some code
using (container)
return (bool) window.ShowDialog();
}
/////////////////////////////////////////
// a lot code between
/////////////////////////////////////////
public void Show(Control view, string title)
{
//some code
var window = GetWindow(view, window);
//some code
window.Show();
}
/////////////////////////////////////////
// a lot code between
/////////////////////////////////////////
private Window GetWindow(Control control, string title)
{
var window = new Container(control);
//doings something else with container, like:
window.Text = title;
return window;
} I this case Show and ShowDialog have really different logic and not well suitable for functional-style as I think, that’s not the case.
The case is method GetWindow itself – it is like situation when solving one problem you creates another.
As I think developer has following code:
public bool ShowDialog(object view, string title)
{
//some code
var window = new Container(control);
//doings something else with container, like:
window.Text = title;
//some code
using (container)
return (bool) window.ShowDialog();
}
/////////////////////////////////////////
// a lot code between
/////////////////////////////////////////
public void Show(Control view, string title)
{
//some code
var window = new Container(control);
//doings something else with container, like:
window.Text = title;
//some code
window.Show();
}
His intention was to remove code duplication and it’s right, but… But He prefer to “Extract method” GetWindow, which give us code that we have. Yes, this is one way to do, but it’s not best, because in this case when somebody wants to read or edit this code it’s a very annoying. You need to switch your view between such “Top-level” public method and that “Extracted” private methods, it’s in such big class, especially bad when you have several methods like GetWindow. You just violates SRP.
You can avoid it really easy – you have 2 alternatives:
First
Just overload constructor of Window and implement all you need there:
public bool ShowDialog(object view, string title)
{
//some code
var window = new Container(control,title);
//some code
using (container)
return (bool) window.ShowDialog();
}
/////////////////////////////////////////
// a lot code between
/////////////////////////////////////////
public void Show(Control view, string title)
{
//some code
var window = new Container(view, window);
//some code
window.Show();
}
//Container.cs:
public class Container
{
public class Container(Control control, string title, /*any other params you need to set it properly */)
{
//doings something you need
window.Text = title;
//doings something you need
}
} Second
The bad thing of first way is that 1) You can have no access to/can’t inherit from class Container 2) You can hides some logic in Container which not natural to class Container. If one of these, or both – create Factory:
IContainerFactory containerFactory;
public bool ShowDialog(object view, string title)
{
//some code
var window = containerFactory.Get(control,title);
//some code
using (container)
return (bool) window.ShowDialog();
}
/////////////////////////////////////////
// a lot code between
/////////////////////////////////////////
public void Show(Control view, string title)
{
//some code
var window = containerFactory.Get(view, window);
//some code
window.Show();
}
// ContainerFactory.cs:
public class ContainerFactory
{
public Get(Control control, string title, /*any other params you need to set it properly */)
{
//doings something you need
window.Text = title;
//doings something you need
}
} Little gem and back to school
Do you know how Double.IsNan() implemented?
public static bool IsNaN(double d)
{
return (d != d);
}From stackoverflow. The same for java.
It’s really funny when you find something like this. You find it when you not really need it, just try quick way to remove noise data – starts with zeros, then found you need to remove NaNs – and catch this. Firstly it’s impressive – a few moments later you understand that it’s proper, it’s just from school’s math and logic, nothing more but you enjoy this moments…
Visual Studio for Internationalization and Localization
Every new platform, every not mature platform has common set of problems and one of this problems are probably will be Internationalization (I18N) and Localization support. For big part of development world it’s not problem - if you are write solely for your country or you speak in English - and so you may be never think about it. But if you speak in different language and think of broader market for your product - or just want to create UI in the same terms as domain model - I18N is your headache.
So if you think that Visual Studio is mature product - you are wrong - every mature development product must know of Localization problems and give you full set of tools to do it.
Localize Forms
Ok, Visual Studio Forms Designer give your ability to localize forms - it’s good enough.
Just
- Set Form’s (or Control) Localizable property to True
- Choose your language in Language property
- And in the form’s design view translate all that your need.
And that’s all - good.
But designed controls are not all strings in UI interactions. When you show messages to user or create control dynamic you also need localize UI.
How? By extract strings to resource (the same as Form Designer do for forms).
For instance - all major java IDE has ability for this:
IntelliJ IDEA: http://www.jetbrains.com/idea/features/i18n_support.html
But not Visual Studio!
With visual studio you don’t have way to externalize your string to resources without many manual work… to present day.
Now we have two very good add-ins for it.
Resource Refactoring Tool
Resource Refactoring Tool is a free add-in for Visual Studio that gives your ability to extract hard-coded strings to resource.
Select text, from context menu select Refactor->Extract to Resource (or use Ctrl-R, Ctrl-X shortcut):
Than select resource file where you want to extract and refactor parameters:
So then you must copy your resource file to resource file for localization - for instance if you have Resources.resx you need to make copy with name Resources.ru.resx (where ru - is your language postfix - de, pl n etc.).
And then in Resources.ru.resx translate parameters to needed parameters.
Good enough.
One problem is that when you extract string to resource and you already have localized version of that resource - you must manually create new variable in localized file. For example with IDEA you don’t need to do this:
safedevelop’s RGreatEx
Another tool for that is Commercial plugin for other great development tool - Resharper (plugin for VS) - RGreatEx (30 Euros per license).
Why You need to buy commercial tool (and moreover - plugin for plugin) instead using free? I can’t answer clearly - if you use Resharper or something like IDEA and understand how it sometimes differs (in a good sense) from other tools - you must try it. The bad thing about that for today it don’t support latest Resharper and Visual Studio 2008 - I expect to update this post when it will be released.