logo
  • Jobs
  • About Me
  • Contact
  • Home

Archive for November, 2006

« Previous Entries

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?

1 Comment

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. :)

1 Comment

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… :)

No Comments

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.

7 Comments

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.

No Comments

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?

26 Comments

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.

  1. Download and extract Notepad2.
  2. Rename Notepad2.exe to notepad.exe.
  3. Find c:\windows\notepad.exe and c:\windows\system32\notepad.exe and set the owner to ‘Administrators’, and grant Administrators full control.
  4. 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.

46 Comments

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.

No Comments

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.

No Comments

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. :)

3 Comments
« Previous Entries
flag
Favorite Charity
wounded warrior project
Search
Social
  • mattberther on twitter
  • mattberther on linkedin
Syndication
Archives
  • January 2010
  • September 2009
  • July 2009
  • June 2009
  • February 2009
  • January 2009
  • December 2008
  • November 2008
  • September 2008
  • August 2008
  • June 2008
  • May 2008
  • April 2008
  • March 2008
  • February 2008
  • January 2008
  • December 2007
  • November 2007
  • October 2007
  • September 2007
  • August 2007
  • July 2007
  • June 2007
  • May 2007
  • April 2007
  • March 2007
  • February 2007
  • January 2007
  • December 2006
  • November 2006
  • October 2006
  • September 2006
  • August 2006
  • July 2006
  • June 2006
  • May 2006
  • April 2006
  • March 2006
  • February 2006
  • January 2006
  • December 2005
  • November 2005
  • October 2005
  • September 2005
  • August 2005
  • July 2005
  • June 2005
  • May 2005
  • April 2005
  • March 2005
  • February 2005
  • January 2005
  • December 2004
  • November 2004
  • October 2004
  • September 2004
  • August 2004
  • July 2004
  • June 2004
  • May 2004
  • April 2004
  • March 2004
  • February 2004
  • January 2004
  • December 2003
  • November 2003
  • October 2003
  • September 2003
  • August 2003
  • July 2003
  • June 2003
  • May 2003
  • April 2003
  • March 2003
mattberther.com © 2003 - 2010