Live Fast, Code Hard, Die Young

Archive for the ‘Tips & Tricks’ Category

Finder keeps crashing on Mavericks

Today I had a really annoying problem on my Mac at work. Finder kept crashing every minute…Highly annoying!

It turned out that the problem for me was Google Drive. The crashes went away when I turned off the option “Show file sync status icons and right click menu”. See screenshot below.

Image

Hopefully Google will fix this issue soon.

Advertisement

Changing the Git editor

I am somewhat annoyed by the fact that the command line version of git uses ‘vim’ as the default text editor. Yes, Vim may be cool and all but it is definitely not friendly to new users. It is an advanced tool and it should not be exposed to poor innocent souls who are just getting started with git. I want git to be lovely and cuddly to newbies – not hostile!

So, the best thing to do is to simply change the default editor that git uses when it wants you to fill in some stuff. You can do this with the following command:

$ git config --global core.editor "nano" (Mac)

C:\> git config --global core.editor "notepad" (PC)

You can replace “notepad” or “nano” with your favorite editor of choice.

Of course, you could also use a decent GUI client instead, if you feel intimidated by command line tools. 🙂

How to speed up auto completion in AppCode 2.5

Here is a quick tip if you find the auto complete feature in AppCode to be a bit slow before it appears. I discovered that there is a setting that by default is configured to delay the auto complete popup by one second.

To change this just open up preferences and navigate to Editor->Code completion and adjust the delay as shown in the screenshot below:

Image

Hope this helps!

Improving current line highlighting in VS2010

Are you experiencing that VS2010 is suddenly highlighting the current line in the text editor? Do you want to get rid of it? I’ll show you how – or maybe convince you to keep it!

 

Line highlighting

First of all, let me explain what I’m talking about in case you haven’t figured yet. Current line highlighting is when the entire line that your cursor is on is shown in a different color. In my case it looks like this:

image

This is not part of the default functionality in VS2010 so most users never see this. However, if you happen to install the Productivity Power Tools it will be enabled by default.

The idea is that highlighting the current line will make it easy to see where your cursor is when you have a large monitor and get lost.

Some users probably love this feature. Personally I don’t like it at all when my cursor “taints” the current row like this when I’m editing. I find it plain annoying!

 

Turning it off

The first solution if you don’t like it is obviously to turn it off completely. This is pretty easy to do using the settings which you can find under Tools->Options and then Productivity Power Tools. Just flick the switch to Off:

image

Now if that was all I had to say this wouldn’t be a useful blog post. Let’s see what we can do!

 

Making it work better

Instead of turning it off we can make better use of this feature. I actually think it is a very good idea to show where the cursor is. However, once I have found the place and start typing the highlighting is just in the way for me.

I have come up with a better solution that involves changing the color of the line depending on if the edit window is active or not. This is possible through the settings under Environment->Fonts and Colors. There are two entries for the Current Line color, one for when the line is active and one when it is inactive:

image

I have set the active color to White which means that when I’m in the edit window and typing the highlighting is hidden. When I navigate classes in the Solution Explorer or elsewhere it will light up. This will effectively work very nicely because when I’m working with other panels or windows and returning to the edit window I can find where I was pretty quickly.

Give it a try and see if it works for you! 🙂

 

Conclusion

Line highlighting is a pretty controversial feature. Some swear by it and some curse it. I hope my post shows one interesting hybrid way of using it that does not get in the way as much as the default behavior.

The Productivity Power Tools is a really nice addition to Visual Studio and I highly recommend it. Through the settings you can customize it even more if you don’t like how it works. I suggest you play around with it and see if you can find other useful tips and tricks to share. I’d love to hear about them so feel free to leave a comment on my blog! 🙂

Adjust namespaces with Resharper 5

A really nice feature in Resharper 5 is the ability to adjust namespaces for code files in a directory. When you move files around in your project or between different projects the namespace no longer matches the directory structure. Updating the namespaces in the code files by hand is quite tedious and error prone. This is especially true when you move user controls or web pages that consists of a XAML file or ASP.NET page with a code behind class that needs to match.

You can adjust the namespace for all files in a directory by simply right clicking the folder in Visual Studio and select “Refactor->Adjust Namespaces…”:

image

This will give you the following dialog where you can see the changes that Resharper suggests:

image

Quite handy I think!

Visual Studio debugging tricks

I learned a new Visual Studio trick today. I’m currently working on a hobby project in C++ and since the plan is to make it cross platform I’m using the excellent Juce framework.

Juce has its own string type which is very nice. It handles Unicode, reference counting and so on. Its like the CString type but cross platform. Some people may prefer the standard lib string std::string but personally I think the std lib is a bit awkward.

Anyway, so what’s my problem then? Well, the thing is that when you debug your program in Visual Studio you really want to see the contents of strings easily. By default you get this when using the juce::String type:

image

Visual Studio has no knowledge about the juce::String type so it just takes a guess at what we want to see and shows us some of the private members in the type. Not very helpful…

Autoexp.dat
So what can we do about it? Well I found some info about a little file containing debugger settings for Visual Studio. It’s default location is under C:\Program Files\Microsoft Visual Studio 9.0\Common7\Packages\Debugger and the file is called autoexp.dat. This file controls how VS displays different types during debugging. Interesting!

If you are running Vista/Win7, make sure you edit autoexp.dat as administrator because it’s protected since it’s in your program files. Otherwise you end up writing to a file that gets placed in your VirtualStore and it won’t work (yes, I did this myself..doh!)

Note that you can change the autoexp.dat file anytime. It will be reloaded when the debugger starts, so you don’t have to restart VS.

Now lets see what we can do… Open up the file autoexp.dat and scroll down a bit to a section called [Visualizer]. This section controls the VS visualizers for STL, ATL and other stuff. This part has a large DO NOT MODIFY text so we won’t touch that part (make a backup if you’re scared…)

Just below the part with the STL and ATL container stuff add the following:

juce::String{
    preview     ([$e.text->text,su])
    stringview  ([$e.text->text,sub])
}

This will tell VS about the Juce string type and explain how we want to view it. The ‘preview’ bit controls what to show in the watch window and the ‘stringview’ bit controls the popup string viewer that allows you to view the string as text, XML or HTML. Very handy feature!

The expression refers to the variable being viewed as $e and then you simply access its members as you would in normal code watch expressions. The ‘su’ part means that the value should be treated as a null terminated string in Unicode format. The ‘sub’ means that the string should be shown using “bare representation”. In this case it will display the string without the surrounding quotes (I only use this in the string viewer, as this seems to be the common practice).

Here is a screenshot of how it looks now:

image

Neato! Now we see the strings easily while debugging. We can also click the magnifying glass to examine the string in a popup window, even show it as formatted XML. Now the Juce type is even more juicy! Great isn’t it?

These debugger expressions can do a lot more. You can read more it here: http://www.virtualdub.org/blog/pivot/entry.php?id=120

Happy coding!

Fixing the missing icons in TortoiseSVN

image

I’m using TortoiseSVN for source control both at work and at home. Lately I’ve been having some problems with it though because the icon overlays that show the status of files are not displayed. That kind of takes away one of the great features of the program so it quickly drove me nuts.

It turned out that it was not hard to fix. After some searching I found out that the problem is that Windows only supports a maximum of 15 registered overlay icons. Of those it uses 4 itself so that leaves us with 11 icons to play with. What happens if more icons are registered? Well, those extra icons are simply not shown. According to the TortoiseSVN FAQ this is taken into consideration when Tortoise is deciding which icons to use and I’ve never had any problems with it until now. Maybe it is not working as intended when running in Windows 7 (64-bit)?

So how does Windows decide which icons to use? Well there is a special key in the registry where everything can be found. It’s under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\ShellIconOverlayIdentifiers.

This is how my registry looks:

image

Windows reads this list in alphabetical order which is kind of lame. I have some icons from Dropbox, some from Tortoise and some other that I suspect belong to Windows or Office. It seems that this list of 15 icons should work but it doesn’t. It’s more likely that only 11 of these icons are used because I’m missing the most common Tortoise icons (Modified and Normal) which happen to fall just outside the range.

The great part here is that each of these keys only contains a GUID which tells Windows where to lookup the actual icon information. In fact, we can change the names of the keys without breaking anything which gives us an easy way of rearranging the list!

This is a simple way of fixing it and making sure that the Tortoise icons gets a higher priority:

image

As you can see I renamed the icon identifiers and prefixed them using numbers which will ensure they are sorted before the other icons. I skipped the “TortoiseUnversioned” icon because it’s usually not of interest to me. Maybe I could skip some of the other icons too but I wanted to make sure it worked first.

After doing this little rename operation you have to restart your computer (yea, it’s Windows isn’t it?) and then the icons should show up nicely again. Quite sweet isn’t it…

image

It’s working! 🙂

Quickly inserting a new line in Excel

I don’t use Microsoft Excel very often but when I do I always find myself looking for the keyboard shortcut for inserting a new line. To me it seems impossible to find this information in Excel itself easily so I always have to resort to Google searching. And when I do that I have to wade through at least 5-6 pages talking about irrelevant shortcuts that don’t do what I need, which is simply to insert rows quickly. Now I figured that if I blog about it I can at least have a tiny chance of remembering the shortcut next time!

Anyway, the easiest way I have found to add a new line in Excel is to first hit SHIFT-SPACE. This marks the entire line that the cursor is on. After that you can just hit CTRL and + as many times you like to get new lines. Similarly CTRL and – will delete a line.

(As a side note I sometimes use Microsoft Project which uses the INSERT key as a shortcut for inserting new rows. Perhaps Microsoft could someday standardize the keyboard shortcuts in the Office applications please?)

Getting the base domain URL from the Uri class

If you’ve used the System.Uri class in .NET you may have stumbled upon the need to extract the base part of the URL and found no obvious solution. You know, you have a URL that looks like this:

http://www.mydomain.com/somepath/somepage.aspx?param=x

And you want to get only this part:

http://www.mydomain.com

If you put the long URL in a Uri object you would expect to be able to get the domain name part via a simple property but as you look through the class you won’t find it. There is a property called Authority for getting “www.mydomain.com” but then you need to concatenate that with the Scheme property which contains “http” and add “://” in between them to get a valid URL. Looks quite cumbersome to me.

I seem to hit this problem every once in a while and I keep forgetting how to do it properly. To me this indicates that the class is missing something obvious. Actually it has a method for getting what I want, and it is called GetLeftPart().

The GetLeftPart() method takes a UriPartial enum that describes how much of the URL to return. If we pass “Authority” to it we get what we want!

Interesting solution
Now I wouldn’t have blogged about this if the GetLeftPart() method was the end of it all. What I really wanted was an easy way to access the base URL and ideally that would be via a property. To achieve this we can create our own class that derives from Uri and add the property there.

Another interesting solution that I found is to add an extension method to the Uri class. Unfortunately there are no extension properties (yet) so we will have to settle for a method called GetBaseUrl(). Here is some code to do it:

namespace System
{
    public static class Extensions {
        public static string GetBaseUrl(this Uri uri)
        {
            return uri.GetLeftPart(UriPartial.Authority);
        }
    }
}