Archive for category Tools
MacVim, NerdTree, Janus Annoyances
I’ve decided to use Vim for a few weeks at least and am enjoying it. There are plenty of posts on using Vim as a Ruby IDE and switching from your IDE of choice. Most of the TextMate to Vim posts seem to recommend Janus and for good reason.
Janus adds a number of plugins and settings to Macvim including NerdTree. NerdTree displays a project drawer in a window which is in a vertical split, normally alomgside your working buffer. The first problem is that if you close your working buffer with :bd or :bw, the NerdTree window will fill the MacVim tab, to cycle to the next or previous buffer then entails resizing splits which is not what I want.
Janus solves this with a function in .vimrc:
This function closes the MacVim tab (i.e. Cmd + W) if there is only one tab and it contains 2 windows, one of them with the NerdTree buffer. Unfortunately this doesn’t consider buffers that are not currently displayed. If I want to close MacVim or the MacVim current tab, I’ll use Cmd + Q or W, when I delete a buffer I want the window to display the next buffer.
To disable the Janus function add an override to .vimrc.local:
It’s better to make changes in .vimrc.local and .gvimrc.local as Janus can be updated to the latest version without losing your customisations.
Luckily there is a script on the vim wiki that keeps the window open when deleting a buffer. It can be amended to ignore the NerdTree buffer, if I want to close NerdTree I will use the key mapped to toggle it:
I would like to map :bd to :Kwbd but it seems it can’t be done (I’d be happy to be proved wrong here) so have mapped Ctrl + Shift + B in .vimrc.local:
SQL Databases and Version Control–Part 2
I originally wrote this as a code walkthrough but the code is fairly self explanatory and there is not much of it so I gave posted it on CodePlex http://sdbvc.codeplex.com/ under the MIT license (which basically allows anyone to do anything with it except sue me for it not working).
DBManager
DbManager has one public method with two overloads. It upgrades a database either from an array of scripts or from a folder of scripts. The actual running of the scripts is done by an implementation of IScriptRunner.
IScriptRunner
The ScriptRunner only has one public method which executes a single script against a target database. Before it runs the script, it checks the script version against the database version using properties of an implementation of IVersionedDatabase.
IVersionedDatabase
The VersionedDatabase exposes properties for version numbers which it retrieves from the schemachangelog table and is the class that finally executes the scripts against the target database.
SQL Databases and Version Control–Part 1
Requirements
I imagine most developers keep their code under source control and I doubt many would argue about keeping their databases under source control, but it seems it is not as common as it should be.
There are a number of commercial offerings to support this, but they are generally overkill for my requirements.
My requirements are:
- To be able to recreate the database to any previous version.
- The database should record schema changes and versions.
- To be able to do this to SQL Server and SQL CE databases.
- To commit change / create database scripts to source control.
This does ignore a possible requirement that may be important to other developers:
- The ability to revert a database to a previous version.
The solution I am planning could possibly be extended to cover that requirement, but if that is a requirement, you may be better off looking at one of the commercial offerings.
To be able to recreate the database to any previous version
To do this, I need an initial database create script followed by any number of change scripts, all of which need to be run sequentially. The easiest way to do this (preferring convention over configuration) is to have the script file name indicate the sequence by naming it:
MajorReleaseNumber.MinorReleaseNumber.PointReleaseNumber.*.sql
The store all scripts for a given database in one folder.
The database should record schema changes and versions
This simply requires a table to store the versioning information in and a tool to run the scripts and record the changes. Additionally this allows the tool to check the current version of a database before running change scripts.
The table should contain the following columns:
| Column | Data Type | Length | Primary Key |
| Id | int | Yes | |
| MajorReleaseNumber | smallint | ||
| MinorReleaseNumber | smallint | ||
| PointReleaseNumber | smallint | ||
| ScriptName | nvarchar | 255 | |
| DateApplied | datetime |
Lastly, the table should be created in the first script run after database creation.
To be able to do this to SQL Server and SQL CE databases
This will be reflected in the tool but also affects the scripts as SQL CE is limited to a subset of the functionality of SQL Server.
To commit change / create database scripts to source control
As the database creation / changes will be done by a number of scripts this can easily be managed by the same source control system used for the code base.
Azure Development Fabric and Visual Studio 2010
Just installed Visual Studio 2010. The first thing I tried was creating an new Cloud project.
The whole process was surprisingly painless. After creating the solution, I was prompted to download and install the Azure tools. Once they were installed, I deleted and recreated the solution and was prompted for which Roles I wanted:
After creating the solution just hit F5 to see the project running in the Azure Development Fabric.
The debugger is already connected and all works just as you would expect.
Installing Subversion on Windows
My requirements are to host the repository on a windows machine, mostly for access from the LAN but also to be accessible over the Internet. The server is running Vista but the install and set up process should be similar on other versions of windows.
Currently there are two relevant builds of Subversion, one based on apache 2.0 and one based on 2.2. I am going to install Apache 2.2 and the corresponding Subversion build.
Install the Apache HTTP server.
Download and run the latest subversion build (currently svn-1.4.6-setup.exe) from http://subversion.tigris.org/servlets/ProjectDocumentList?folderID=8100&expandFolder=8100&folderID=91
Copy the file mod_dav_svn.so from C:\Program Files\Subversion\bin to C:\Program Files\Apache Software Foundation\Apache2.2\modules.
Open the Apache configuration file (‘Start > All Programs > Apache HTTP Server 2.2 > Configure Apache Server > Edit the Apache httpd.conf Configuration File’) and find the line ‘#LoadModule dav_module modules/mod_dav.so’.
Remove the ‘#’ from the front of that line then add the line ‘LoadModule dav_svn_module modules/mod_dav_svn.so’ below it. Save the file and restart the service to confirm everything is working as it should.
Create the directory where you want to store the repositories (e.g. D:\Svn).
Go back to the Apache configuration file and at the end of the file add:
<Location /Svn>
DAV svn
SVNListParentPath on
SVNParentPath D:\Svn
</Location>
Save the changes then restart the Apache service for them to take effect.
You should now be able to browse to http://localhost:81/Svn/ and see a page with zero repositories.
Installing Apache HTTP Server on Windows
I am setting up a machine to host Subversion. My preference is to use Apache as the HTTP server. The server is running Vista but the install and set up process should be similar on other versions of windows.
Download
The latest Apache build (currently apache_2.2.9-win32-x86-no_ssl-r2.msi) from http://httpd.apache.org/download.cgi
Install Apache
Run the installer and follow the instructions. Enter the server name under ‘Network Domain’ and ‘Server Name’, enter an email address and leave ‘for All Users’ selected.
Navigate to http://localhost/ and you should see the text ‘It works!’.
I prefer to run IIS on port 80 and Apache on 81. If you already have IIS installed and running you may not have got the ‘It works!’ page but rather an IIS page when running the test above.
Change to Port 81
‘Start > All Programs > Apache HTTP Server 2.2 > Configure Apache Server > Edit the Apache httpd.conf Configuration File’
Search for ‘Listen 80′ and replace with ‘Listen 81′
Save the conf file and restart the service from the services console then browse to http://localhost:81/ to confirm it works.
Create a Password File
Open a command prompt at C:\Program Files\Apache Software Foundation\Apache2.2.
Create a password file by entering ‘bin\htpasswd -c passwd username‘ and enter and confirm the password when prompted.
Add any further users with ‘bin\htpasswd passwd username‘.
Edit the Apache httpd.conf configuration file and change:
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
</Directory>
To:
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
AuthType Basic
AuthName “Subversion Repositories”
AuthUserFile passwd
Require valid-user
</Directory>
Restart the Apache 2.2 service and confirm you are asked for a username and password when you navigate to http://localhost:81/.
You may need to amend your firewall to allow connections from port 81.
Macro to Set Outlook’s Master Category List
I upgrade, move, or reinstall the OS on my PCs fairly often so setting a master category list with a macro is useful:
Public Sub ResetCategories()
DeleteAllCategories
CreateCategory “! goals”, 1, 0
CreateCategory “! objectives”, 2, 0
CreateCategory “! projects”, 3, 0
CreateCategory “@ anywhere”, 4, 0
CreateCategory “@ computer”, 5, 0
CreateCategory “@ email”, 6, 0
CreateCategory “@ errands”, 7, 0
CreateCategory “@ home”, 8, 0
CreateCategory “@ office”, 9, 0
CreateCategory “@ phone”, 10, 0
CreateCategory “1:1″, 11, 0
CreateCategory “2 inbox”, 23, 1
CreateCategory “2 someday maybe”, 24, 0
CreateCategory “2 waiting for”, 19, 0
CreateCategory “meeting”, 22, 0
CreateCategory “holiday”, 17, 0
CreateCategory “social”, 18, 0
CreateCategory “STS”, 20, 0
CreateCategory “travelling”, 21, 0
CreateCategory “cards”, 25, 0
End Sub
Private Sub DeleteAllCategories()
Dim objNameSpace As NameSpace
Dim objCategory As Category
Set objNameSpace = Application.GetNamespace(“MAPI”)
If objNameSpace.Categories.Count > 0 Then
For Each objCategory In objNameSpace.Categories
objNameSpace.Categories.Remove (objCategory.CategoryID)
Next
End If
Set objCategory = Nothing
Set objNameSpace = Nothing
End Sub
Private Sub CreateCategory(strCategoryName As String, intColor As Integer, intKey As Integer)
Dim objNameSpace As NameSpace
Dim objCategory As Category
Set objNameSpace = Application.GetNamespace(“MAPI”)
If intColor > 25 Then intColor = -1
objNameSpace.Categories.Add strCategoryName, intColor, intKey
Set objCategory = Nothing
Set objNameSpace = Nothing
End Sub
Outlook Item to Task Macro
The following macros convert outlook items to tasks with different categories. Based on this blog post which in turn is based on this one.
- The item body is copied to the task body and the item itself is added as an attachment.
- If multiple items are selected, multiple tasks will be created.
- Created tasks are left open for editing.
- I am in two minds about deleting the item after the task is created and have decided against it at the moment.
- It appears that OL 2007 does not allow shortcut keys to be assigned to macros
.
Public Sub CreateInboxTaskFromItem()
CreateCatagorisedTaskFromItem (“2 inbox”)
End Sub
Public Sub CreateWaitingTaskFromItem()
CreateCatagorisedTaskFromItem (“2 waiting for”)
End Sub
Public Sub CreateSomedayTaskFromItem()
CreateCatagorisedTaskFromItem (“2 someday maybe”)
End Sub
Public Sub CreateTaskFromItem()
CreateCatagorisedTaskFromItem (“”)
End Sub
Private Sub CreateCatagorisedTaskFromItem(catagory As String)
Dim olTask As Outlook.TaskItem
Dim olItem As Object
Dim olExp As Outlook.Explorer
Dim fldCurrent As Outlook.MAPIFolder
Dim olApp As Outlook.Application
Set olApp = Outlook.CreateObject(“Outlook.Application”)
Set olExp = olApp.ActiveExplorer
Set fldCurrent = olExp.CurrentFolder
Dim cntSelection As Integer
cntSelection = olExp.Selection.Count
For i = 1 To cntSelection
Set olTask = olApp.CreateItem(olTaskItem)
Set olItem = olExp.Selection.Item(i)
olTask.Attachments.Add olItem
olTask.Body = olTask.Body + olItem.Body
If catagory = “2 waiting for” Then
olTask.Subject = olItem.SenderName & “: ” & olItem.Subject
Else
olTask.Subject = olItem.Subject
End If
olTask.Categories = catagory
‘olItem.Delete
olTask.Display
olTask.Save
Next
End Sub
User Commands in Xplorer2
When I am doing anything more complicated than simple file browsing I use Xplorer2 rather than the windows file browser.
One of the features of Xplorer2 is the ability to run commands on files you have selected.
These are the commands I currently have set up:
- VS Cmd
$”C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\sdkvars.bat”
Sets the console to act like a Visual Studio command prompt - Get Public Key
$sn -Tp “$F”
Gets an assemblies public key (requires vs Cmd to be run first). - DiffMerge Files
>”C:\Program Files\SourceGear\DiffMerge\DiffMerge.exe” “$F” “$G”
Uses Source Gear’s DiffMerge to diff files from each pane. - DiffMerge Folders
>”C:\Program Files\SourceGear\DiffMerge\DiffMerge.exe” “$P” “$I”
Uses Source Gear’s DiffMerge to diff folders from each pane (although Xplorer2 does this well enough itself).