Blogging from TextMate
Shortly after I got rid of my Windows PC in favor of a 20″ iMac at home, I started doing some Rails development. I did quickly realize that I needed something a little more powerful than TextEdit, which is an equivalent of WordPad on Windows. After searching for a while, I ran across TextMate, which seems to be the text editor that everyone is talking about.
So, in addition to being a top-notch text editor, it turns out that TextMate also has a blogging bundle which can be installed. What do you get with this bundle:
- Support for MovableType, WordPress, Drupal and Typo
- Allows pulling content from your blog for editing. Posts are displayed in a menu, allowing you to edit and then republish your updated content.
- You can specify “headers” to control how the post ends up on your server. You can edit the title, date, whether or not to allow trackbacks or comments.
TextMate checks in at 39€ (or roughly $50). You’d spend that much on an OS X application that is an exclusive blogging client. With TextMate you not only get a blogging client, but a premier text editor.
What are you waiting for?
Migrations with Ruby on Rails
I’ve looked through a number of books and websites in the period of time that I’ve been becoming more familiar with the stroke of genius that is Ruby on Rails. I’ve noticed that the majority of the books and websites seem to glance over what I think is probably the single coolest feature of Rails.
Migrations are used as a database agnostic representation of your information schema. You can write your database schema once in Ruby code. Using rake’s migrate task, you can then have the ruby code translated to MySql, PostgreSQL, or SQLite.
The simplest way to help you understand the power of migrations, I think is to just show you.
The first thing we will want to do is run the script that generates the migration. This should look vaguely familiar to those that have done much with RoR.
script/generate migration MigrationName
For example, let’s say I want to add a user. I would go ahead and run
script/generate migration AddUsersTable
This will then generate a ruby file in the folder db/migrate, which takes the format of VERSION_your_migration_name.rb. We’ll talk a little more about VERSION later.
If we look at the generated migration file, we’ll see something like:
class AddUsersTable < ActiveRecord::Migration def self.up end def self.down end end
This new class describes our migration. When we migrate to a new version, the self.up method is used, and when we rollback to a previous version, self.down is used.
Let’s fill this out with some code:
class AddUsersTable < ActionRecord::Migration def self.up create_table :users do |table| table.column :name, :string table.column :login, :string, :null => false table.column :password, :string, :null => false, :limit => 32 end end def self.down drop_table :users end end
What’s happening should be fairly apparent. We’re able to define every database change in an abstract fashion, and leave it up to the connection adapters to generate the SQL necessary for each platform (MySQL, SQL Server, Oracle, etc).
What types of changes can we make with migrations?
- Add a new table
- Remove a table
- Add columns to existing tables
- Remove/rename columns
Once all the migrations are defined, we can then use rake’s migrate task to update the database. rake migrate will migrate your database to the current version. rake migrate VERSION=x will migrate your database to the specified version. You can completely rollback all changes to the database by using rake migrate VERSION=0
I hope I’ve been able to give you a good introduction to migrations with ruby on rails. If you’re not using them yet, you should certainly start. :)
Alternating table row colors with Rails
I was looking for a way to alternate table row colors with Ruby on Rails and stumbled across this gem. All you have to do is use the cycle method on the TextHelper.
< %- for item in @items do -%> <tr class="<%= cycle("even", "odd") %>"> ... use item ... </tr> < %- end -%>
and in the css:
.even { background: #efefef; } .odd { background: #a5a5a5; }
The love affair with Ruby on Rails continues… :)
Vista.Uninstall()
Thanks, but no thanks! After running the Windows Vista RTM on my primary laptop since it was released, I have finally given up and reinstalled Windows XP on the machine.
There has been a lot of comparisons on the web about Vista vs Leopard. Given my experiences with Vista, Leopard has nothing to worry about. I read about the 43 people involved in the design and implementation of the shutdown menu. I gotta say, that that is absolutely ridiculous. 43 people working on that menu for more than a year, and that piece of shit was the best they had??
Vista was a virtually unusable memory hog, and it would have been nice to have some of those 43 people looking at performance issues instead. My base OS without a single application running took ~750MB of RAM. That is completely unacceptable.
Microsoft has a long road ahead of it in the operating systems arena. Mac OSX gets it, and this is why Apple is gaining so much market share.
Remote Management of Terminal Services Sessions
I could have swore that I blogged these tools a while back, but could not find any record of it, so here goes.
Again, I found myself locked out of a terminal server here at work, seems some sesssions had started misbehaving, and would not terminate. To the rescue came two tools, included with Windows XP/2003/Vista, qwinsta.exe and rwinsta.exe.
qwinsta.exe displays information about Terminal Sessions. This information can then be used to feed rwinsta, which will reset a session identified either by name or by session id.
Windows Vista and the screensaver
I had installed Windows Vista RC2 a while back, and just recently (over the weekend) installed the RTM version of Vista on my work laptop (a Dell D820).
One thing that has been driving me bonkers is that the screensaver refuses to kick in. I decided to finally look into what could be causing that, and went to Google. Google brought back a hit to this site that talked about a similar issue, where he realized the mouse was causing the operating system to not turn the screensaver on.
Surely, this couldnt be my problem… After all, Im running a Microsoft cordless mouse (Wireless Notebook Optical Mouse 3000) and surely Microsoft software should work with Microsoft hardware. I yanked mouse and sure enough… the screensaver turned on in 2 minutes.
Fantastic… so where does that leave me now? In the market for a new mouse, I guess. Any recommendations?
Replacing Notepad in Windows Vista
After installing the Vista RTM, I wanted to replace Notepad with Notepad2, as I find this to be a much more powerful editor. It’s much more geared towards programmers, with built-in syntax highlighting. Best of all, it’s free.
It’s been pretty widely documented on how to replace Notepad on Windows XP. However, not much documentation was available for Windows Vista.
Interestingly enough, I found that it was very easy to do. These are the steps I followed, and I have yet to have Vista to replace it with the built-in version.
- Download and extract Notepad2.
- Rename Notepad2.exe to notepad.exe.
- Find c:\windows\notepad.exe and c:\windows\system32\notepad.exe and set the owner to ‘Administrators’, and grant Administrators full control.
- Using Windows Explorer, drag and drop the renamed notepad2.exe to c:\windows and c:\windows\system32.
Doing this allows you to get a much more powerful editor for things like viewing source from Internet Explorer or off of the Edit context menu.
FeedBurner Feeds
I just burned my feeds at FeedBurner. They take care of serving my feeds, while allowing my to look at tons of reports around the stats that they keep for my feed.
Getting this hooked up was very simple. I used Steve Smith’s FeedBurner plugin to redirect 100% of my feeds through FeedBurner. This way, I still get to make sure I get accurate stats and also get all the other benefits of FeedBurner.
The transition should be transparent to you, my readers… Your feed should automatically be updated to http://feeds.feedburner.com/mattberther in your aggregator.
Office 2007 “Save as PDF” plugin
Im sure that by now, everyone has heard of the whole fiasco between Microsoft and Adobe about the “Save as PDF” feature that was supposed to be included in the 2007 version of the Microsoft Office suite.
In a nutshell, Adobe got pissed and Microsoft announced that it would be pulling the PDF support. Microsoft said that Office would still be able to save PDFs, but the functionality would come from a plugin that the user would have to install.
Having just installed Office 2007 RTM, I started to hunt for the plugin. I found a plugin available on the Microsoft downloads site that saves PDF or XPS. There are also plugins available that save only PDF or only XPS.
A generic plugin loader
I dont know how many times I end up writing code that iterates over a set of .dll files and looks for classes that implement a given interface.
I think that just now, I wrote this for the last time… Check this out. I’m kinda proud of it. :)
class PluginLoader { public virtual IList<T> LoadPlugins<T>() where T: class { IList<T> plugins = new List<T>(); string[] assemblies = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, "*.dll"); foreach (string assembly in assemblies) { try { Assembly asm = Assembly.LoadFrom(assembly); foreach (Type type in asm.GetTypes()) { if (typeof (T).IsAssignableFrom(type) && !type.IsAbstract) { T plugin = Activator.CreateInstance(type) as T; if (plugin != null) { plugins.Add(plugin); } } } } catch (Exception) { // A failure to load a plugin should not throw an exception } } return plugins; } }
How do you use this? Pretty simple, actually…
PluginLoader loader = new PluginLoader(); IList<MyPluginType> plugins = loader.LoadPlugins<MyPluginType>();
I love writing code again… It’s been too long. :)


