Archive for the ‘Programming’ Category

Kommand – An AutoHotKey Script that does VIM-Like Text Editing and Window Management

Monday, July 13th, 2009

I’m a huge fan of AutoHotKey. AutoHotKey has the power to make your keyboard do amazing things. I use it on a daily basis to open programs and folders, manage windows, and edit text amongst many, many other things. I use it so extensively that I find it frustrating to use a computer without it. AutoHotKey has the power to transform you into a computer ninja. I highly recommend its use.

Recently I released a part of my AutoHotKey script to the Internets and called it Kommand. Kommand remaps your keyboard and enables VIM-like key bindings that are useful for scooting around a document and making changes. I’ve found it very useful for coding. The nice thing is that since it is an AutoHotKey script, it is application independent and works wherever text input is needed. In addition to text editing, Kommand provides many keyboard shortcuts that help in window management. You can close, restore, maximize, minimize, and move windows around the screen really easily and quickly.

Kommand is very early software and I am only putting it out there to see if anyone is interested. More information about it can be found in the AutoHotKey forums here:

http://www.autohotkey.com/forum/viewtopic.php?p=281279

Kommand can be downloaded from the following link. The source AutoHotKey script is included along with a few files and executables that are useful for integrating it with Windows. If you use it, please let me know what you think!

http://www.kylirhorton.com/kommand.zip

Gentoo “Can’t Pickle” Error

Monday, April 6th, 2009

I’m a Gentoo newbie. Actually, I consider myself a newbie to Linux in general. The other day while putting together my own system using Gentoo, I ran into problems every time I tried to emerge something. While portage was calculating dependencies, it would suddenly stop and spit out a cryptic error trace that ended with:

cPickle.PicklingError: Can't pickle <type 'method-wrapper'>: attribute lookup __builtin__.method-wrapper failed

None of my Gentoo geek buddies knew what was up. After trying a few things, I came up with a good solution: manually reinstall emerge/portage. I found an excellent tutorial on how to do this at gentoo.org:

http://www.gentoo.org/proj/en/portage/doc/manually-fixing-portage.xml

How to Remove an Empty Axialis Toolbar from Visual Studio

Friday, February 20th, 2009

I began having problems with the Axialis icon editing toolbar in Visual Studio a few weeks ago. It would appear as a short, empty, ugly little toolbar within Visual Studio. I would remove it, even delete it out of Visual Studio, and it still hung around and appeared there every time I started up. Fortunately for me, this problem has a simple fix.

If you’re using a x86 machine, edit the following within the registry:
Key: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\9.0\AddIns\IconWorkshopAddin.Connect
Set value CommandPreload to 0×00000000 (0).

If you’re using a x64 machine, edit the following within the registry:
Key: HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\9.0\AddIns\IconWorkshopAddin.Connect
Set value CommandPreload to 0×00000000 (0).

References:

http://www.axialis.com/forum/viewtopic.php?f=4&t=2179

How to read and write settings in App.config with C#

Tuesday, September 9th, 2008

Today I’ve been working on creating a simple WPF application. As a part of this application, I want to store some user-defined preferences. This post briefly details how I went about doing this using C# and Visual Studio 2008.

First, make sure your application has an App.config file. If it is missing, add it by going to Project > Add New Item… and then selecting “Application Configuration File” from the pop up. Visual Studio will then add a blank App.config file to your application. Open it and make it look something like this:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="PreferenceToRemember" value="DefaultValue" />
</appSettings>
</configuration>

In order to write to this App.config file, you will need to add System.Configuration as a project reference. And of course you’ll need to have the appropriate usings statements on the right forms. Once all that is done, you can write to the App.config file with the following:

Configuration oConfig = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
oConfig.AppSettings.Settings["PreferenceToRemember"].Value = "NewValue";
oConfig.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("appSettings");

The last line in the code above refreshes the current in-memory configuration with what is saved inside the App.config file. To read from the App.config file, just use this:

string strPreferenceToRemember = ConfigurationManager.AppSettings["LastProject"];

As a final note, I noticed that nothing seemed to be written to the configuration file while debugging within Visual Studio, but once I published the application it worked as expected. I don’t know why this happens, but I’ll modify this post if I find out.

A Regular Expression that matches CSS lengths

Wednesday, July 2nd, 2008

As a followup to my previous post, here’s a useful regular expression for selecting a valid CSS length.

(more…)

A Regular Expression that matches CSS colors

Thursday, February 28th, 2008

Recently I needed to have a Regular Expression which would match valid CSS colors. I wasn’t able to find any after searching the Internets for a while, so I wrote my own.

(more…)

How to loop through an associative array in JavaScript

Thursday, January 10th, 2008

Looping through an associative array in JavaScript is straight forward, but it does have some catches. You will want to use a for (...in...) loop. This will iterate through every index in the array and even the properties of the array. In order to loop through only the elements within the array, you’ll want to do something similar to this:

for (var name in associativeArray) {
if (name != "length") {
// Code that interacts with associativeArray[name]
// name will contain the index for each property
}
}

The above code snippet can also be useful for iterating through the properties within an object. Firefox supports iterating through an array using the each keyword like so:

for each (var object in associativeArray) {
// object now contains the actual item and can be directly used.
}

In this case, you do not need to worry about picking up the length property.

ASP.NET Application, Page, and Control Life Cycles

Friday, December 14th, 2007

ASP.NET
About every other week I will need to know something about the life cycle of an ASP.NET page and for some reason it takes me a while to find it on the Internets. Below I’ve added an ordered list of the events which fire during the life cycle of an ASP.NET Application, Page, and Control. And then as a bonus I’ve included an image which shows most of it courtesy of Leon Andrianarivony. Enjoy!

(more…)

How to fix broken project references in Visual Studio

Thursday, December 6th, 2007

Visual Studio

The Problem
Lately I’ve been experiencing some frustrating problems with references to DLL files in a Visual Studio solution. Since I’m working with a team of other programmers, we are obviously using a code versioning system—in this case SourceSafe. It seems that nearly every time I “get the latest version” of the solution from SourceSafe and then try to build it, I will get errors with references to missing DLLs. However, the “missing DLLs” actually exist. The problem is that the references to these DLLs within the solution are wrong.

Because each of the other programmers have a different path to their own copies of the same solution, they also have different paths to the DLLs that are included in that solution. One programmer will notice that his stuff isn’t compiling, he’ll fix the reference error, check it in, and then simultaneously break it on all the other programmers’ machines (Or at least all those will a different file structure).

The Fix
To fix it, you’ll want to use “Reference Paths” within Visual Studio:

  1. In Solution Explorer, right-click your project node and click Properties. The Project Designer should appear.
  2. If you are using Visual Basic, select the References page and click the Reference Paths button. In the Reference Paths dialog box, type the path of the folder that contains the DLL that you want to reference in the Folder field, then click the Add Folder button. If you are using C#, select the Reference Paths page. In the Folder field, type the path of the folder that contains the item you want to reference, and then click the Add Folder button.

That’s it! Reference Paths are saved within each user’s own profile, so they will not be propogated to the other SourceSafe users when you check in your files. When you build a solution, Visual Studio will first try to find the DLL with the hardcoded path that is provided within the solution. If it can’t find it, then it will look within the Reference Paths for the file, where you should now have the correct reference to the DLLs.

References:

http://msdn2.microsoft.com/en-us/library/ayds71se(VS.80).aspx