Author Archive

C# 4.0 specs mentions Ruby in line 4

November 6, 2008

We are currently seeing Microsoft being more and more aware of Ruby and Ruby on Rails world. They’ve launched there own MVC framework and they are working on IronRuby.

Now a whitepaper on the future specs of C# has seen the light of day and I’m proud to say that Ruby is mentioned in line 4 (if you don’t count the introduction). They are implementing more dynamic structures in the language.

The following is a quote from the whitepaper. They are talking about “dynamic” objects:

“Some examples include
a) objects from dynamic programming languages, such as Python and Ruby”

I think this is a funny development of a compiled language. Ruby has excisted for 15 years but suddenly Microsoft finds it the source of great inspiration?!

When that is said the feature I’m currently looking most forward to in C# 4.0 is co- and contravariance. Now we can use generics for more than simple collections πŸ™‚

If you want to read the Microsoft whitepaper, you can get it here

Building a Ruby on Rails application in a week

June 9, 2008

This post will (and perhaps some followups) describe how I did a web application in a week using the web framework Ruby on Rails

My company 41concepts is currently developing a rather large application using Ruby on Rails and during this I had a week where I had to wait for something being delivered by another developer. The application wasn’t really supposed to grow this large, but the feature list just seemed to grow the more we developed.

Because I had this week, I wanted to try to make a small Ruby on Rails application implementing an idea I’ve had for some time now.

I really like my Playstation 3 and if you ask my girlfriend this is also a bit too much sometimes. I generally like adventure and roleplaying games such as the Final Fantasy series and because I hate wasting my time, I usually follow a game walkthrough.

With this application I really wanted to give something back to the game walkthrough community, so I decided to create the site/application “My Walkthroughs“. The main idea is to let users of the site create their game walkthroughs and then share them in different format such as pdf, plain text and html. The idea comes from the fact that almost all walkthroughs are being done in plain ASCII text.

So the application should enable users to build a walkthrough through a web interface and publish it in various formats.

Ok… I had a week for this, so what did I do?

Planning

Well.. I must admit I went straight to implementation. This was a small site and really just a pet project.

Implementation

Design

I’m not really a Photoshop shark (I don’t even have Photoshop), so I found a free template:
http://www.opensourcetemplates.org/templates/preview/1303028527/

For icons I used the FamFamFam silk icon set that is simply astonishing:
http://www.famfamfam.com/

Finally I decided that I wanted some kind of Logo, so I invested in one from Logo Samurai:
http://www.logosamurai.com/

Cool css scalable buttons:
http://monc.se/kitchen/stew/buttons/btn.html

Took the confirmation boxes from:
http://www.templamatic.com/blog.asp?BlogID=18

Got the cool form hints from here
http://www.askthecssguy.com/2007/03/form_field_hints_with_css_and.html

Code

I used a lot of different plug-ins and gems. The fastest code to implement, is code you don’t write :). They are listed below:

Plug-ins

acts_as_bookmarkable
Suddenly I thought it would be a great idea if the user could bookmark other user’s walkthroughs

acts_as_commentable
Of course users should be able to comment each others walkthroughs, it wouldn’t quite get the web 2.0 feel without πŸ™‚

acts_as_list (tutorial)
This is used for lists that should be sortable

acts_as_rated
This was added late, it turned out really nice with this tutorial, adding nice css/ajax support. Also note that all the averages are calculated when the entity is saved and not at render time

attachment_fu (tutorial)
This is used for all uploads and thumbnail generation. It works perfectly together with Amazon S3

auto_complete
Used for completing the game’s name when creating a new walkthrough

restful_authentication (basic use, great screencast)
The standard on authentication

simple_captcha
Used for registrations and other places where spam bots like to date

synch_s3_asset_host
This was used in the Capistrano recipe for synchronizing the public folder with the Amazon S3 asset hosts

Gems

htmldoc (tutorial)
I had to modify it though, when certain PDFs was generated, the gem reported false as return value but left nothing in the error collection. After some investigation I found out there was a bug in how the result from the command-line was parsed and changed line 186 from “case line” to “case line.strip” since there was some \r characters that the code didn’t quite expect. I’m not sure if this is only applicable to me, but now it works

mini_magick
Image manipulation for use with the attachment_fu plugin. This is not as heavy as the full rmagick since it uses the commandline. I wanted to use this with the simple_captcha plugin as well, but it can only modify existing images, not create new ones.

rmagick
Image manipulation for use with the simple_captcha plugin

aws-s3
Provides a nice api for Amazon S3

uuidtools
Used for generating GUIDs. Notice that it couldn’t find the MAC address on my virtual server at Slicehost, so I had to manually give it a MAC address

will_paginate
Great for pagination. If you want to use ajax paging – something we use in another application – this works perfectly

In total the model folder in the application consists of 11 models, 3 observers and 2 mailers. A small and simple app πŸ™‚

The application use REST and search engine optimized urls everywhere which was something I really wanted from the start. Take e.g. the url for a walkthrough:

/walkthroughs/123456-resident_evil_5_ps3/summary

On this page the user gets a summary of the walkthrough and can download the walkthrough in three different formats using the URLs:

/walkthroughs/123456-resident_evil_5_ps3 (no extension => html)
/walkthroughs/123456-resident_evil_5_ps3.txt (plain text – ascii)
/walkthroughs/123456-resident_evil_5_ps3.pdf (well… pdf :))

The code looks at the last edited time of the walkthrough and generates a new one if needed. The output is placed on Amazon S3 and the user is redirected to this. It would be a bit nicer if the application streamed the file from S3 and then directly on to the user, but in order to save server resources, the user is redirected directly to the S3 url (which is currently not that nice).

Deployment

We are currently trying to do deployment on Amazon EC2 for our larger application, but with this one I really wanted to try out the new Passenger (mod_rails) Apache plugin, since it promised real easy rails deployment.

So I bought a slice over at Slicehost and pretty much followed this tutorial to the letter. It worked like a charm.

After this I set up Capistrano according to Slicehost’s own Capistrano documentation.

I also signed up for the Amazon S3 storage service for the walkthrough pdf and txt files, as well as the user avatars (from attachment_fu plugin). Furthermore I used the synch_s3_asset_host to synch the public folders with asset hosts in Amazon S3 during the capistrano deployment.

For tracking I added the site to our Google Analytics account.

Aftermatch

Well, I must admit that not everything was actually done in this one week. The following was added after week one:

  • The domain name (I forgot to start this process in the beginning of the week, and it takes a couple of days to process)
  • The logo from LogoSamurai took some days with revisions and all
  • The bookmarking functionality
  • The asset hosts in the capistrano recipe
  • Forgot password functionality (don’t know why this slipped in the first place)
  • Some minor bugfixes to the pdf and plain text rendering (I will probably keep improving this)
  • Caching (this is something I will need to monitor as the site gets traffic)
  • I normally write alot of tests, I must admit that I could do better with this app πŸ™‚
  • I’ll probably optimize some database indexes along the way
  • A nicer system admin area using Active Scaffold or similiar

Price

So what did all this cost me!?

  • Hosting @ Slicehost $20 a month first bill was $60
  • Logo (LogoSamurai 3 designs unlimited revisions) $147
  • A bunch of great rails plugins – FREE (thanks…)

$207 and one week of work (plus some follow up described above).

Now I only need to get some users on the site (the hard part). I might write a bit about the bootstrapping process later.

So go to http://www.mywalkthroughs.com and give it a spin.

Man I love rails…

Installing Mephisto (multi site) on DreamHost

January 7, 2008

The title might be a bit off, since I’m not providing you with a step by step guide. This post do however sum up my notes during the install.

I started by following excellent guide:
Mephisto and Dreamhost

After looking at several guides, this one was really the easiest to follow.

Now Mephisto was installed and I wanted to add multiple sites support and I followed the guide:
Setting up Mephisto for multiple sites

I did everything but couldn’t figure out why the site still used the site root (/public) as cache location. Well silly me. As it turned out I had to restart the fcgi process (something that I really thought I’ve already done). So… Remember to do a:

touch public/dispatch*

from the application root folder.

Installing RadRails and getting error “Requested operation cannot be performed because it would invalidate the current configuration. See details for more information.”

January 2, 2008

Up until now, I’ve been using TextMate to create my Ruby on Rails code, but I’ve been missing stuff like autocompletion (I know, a bit more difficult when using dynamic languages, but I really miss it because I also do alot of C# development in Visual Studio).

So.. I decided to try out RadRails that is now named Aptana Studio and the Rails development package installed as a plugin.

After the download and the installation I then tried to install the Rails plugin, but got this strange error:

“Requested operation cannot be performed because it would invalidate the current configuration. See details for more information.” and “ Subclipse Mylar Integration (1.0.1) requires plug-in org.eclipse.mylar.tasks.core (0.9.2)”, or later version.”

After some searching I found the answer here. All you have to do is to un-select the Mylar integration. Although this might be a simple operation for experienced users of Aptana Studio, I was a bit puzzled about this. As someone who just wanted to try out the Rails environment (and I guess I’m not the only one), this seemed like an unnecessary complex installation (at the time I didn’t even now what Mylar was – now Mylyn)

Ruby on Rails’ footprint on Microsoft

December 21, 2007

This post could also be called how David (DHH) inspired Goliath (MS).

Lately Microsoft has release a number of products and new technologies on the .NET platform. Of course this could just be seen as the way of .NET framework. I mean.. 3.0 and 3.5 are just what comes after 2.0, right?!

Anyway… We’ve had this WebForms framework for doing websites for years now, and MS never really strafed from this strategy even though the Model View Controller pattern has had alot of followers and proven itself on the Java platform. Why should we have an MVC stack when working with .NET?!? Well.. I for one find it really easy to understand. No more advanced event cycles and s… viewstate. No more postback and advanced control design… Well that’s just me. When that is said, I’ve worked almost exclusivly with WebForms since the .NET 1.0 beta was out… Of course there has been some alternatives. In the last post I linked to the MonoRails project. On the frontpage it even says that it is inspired by Ruby on Rails (just see the .rails file extension for the httphandler in all their examples).

As I wrote in the last post, Microsoft are now launching their own MVC stack… Hmmm… Why the sudden change? As with everything Microsoft goes into, they pretty much market it as something completely new and innovative. Just look at the MVC frenzy going on over at: ScottGu and Haacked.com (ok.. also alot of great examples… ).

So is this another MS MVC post… Well not really, I just wanted to sum up some recent stuff out of MS and then leave it up to you to decide if they are not (heavily) inspired by RoR:

MVC

As already discussed, the heart of RoR and a sudden shift from MS.

REST

While not invented by DHH, he spoke (and) … and the world listened. This completely suprised MS. “Does people actually need this silly rest thingy?!”. Well apparently MS is now REST’ing a but with the Astoria Project.

NRuby?

We currently have JRuby and MS recently launched their first dynamic language (IronPython) on the .NET platform. Furthermore there are job ads like this. There is also this open source project however.

O/R Mapping

While RoR uses Martin Fowler’s Active Record pattern for its o/r mapper, Microsoft finally has something they almost can call an o/r mapper. While MS has brought the dynamic expression i c# to the table with the LINQ technology, LINQ for Entities (and SQL) is really too little too late.. I’ve been using NHibernate for years now and with the LINQ for NHibernate I might just stay there :). And also remember that this is not the first o/r mapper MS tries to bring to the market. Who doesn’t remember ObjectSpaces.

While I don’t claim that MS has picked up on o/r mappers after RoR, they certainly comes in handy with their brand new lightweight MVC package.

So…

What do you think?! Is MS inspired by RoR?! I believe they are at least keeping a very big eye on it (Sauron style) but that’s just my to cents?

Asp.net MVC framework

October 12, 2007

And so it happened… Microsoft acknowledged that not all developers like the whole event driven/viewstate model.

Other web frameworks like the MVC model has been used for years on other platforms, alternatives like MonoRails have existed on the .net platform with a small loyal crowd of developers.

But now…. (my guess is because the whole buzz about Ruby on Rails and its MVC model) Microsoft launches their own MVC framework:

http://codebetter.com/blogs/jeffr…mvc-framework-at-alt-net-conf.aspx

At last… I can’t wait to try it out and to see how adoption goes.

Don’t rename the title field in sharepoint lists and doing caml lookup by id

August 8, 2007

I guess alot of you that if you rename the Title field in a SharePoint list, the internal name is still “Title” (only the viewable name is actually changed). I had such a scenario where another developer had renamed the Title field to E-mail because there was really no need for having a title field in the list.

By itself this posed no problem, but when you work intensive with CAML problems quickly add up. When writing CAML queries in SharePoint you query on the internal name of the field. This didn’t pose as a problem for me, I just made a comment in the code so my fellow developers could see why I’d written “Title” in my query when the “E-mail” was what I needed. After I then ran my code nothing happend. SharePoint just returns “0 found posts” if anything is wrong with the CAML query making it hard to really see where the error is.

Somewhat confused by this, I downloaded the Stramit SharePoint Caml Viewer. Great application. When looking at the data for the entire list, I could see another field called “LinkTitle”. When I used this in my query it magically worked.

While I found a solution, I was really too far out in the internal fields of SharePoint, so I deleted the list and created a new one WITH THE TITLE FIELD :). I’m not sure if this oddity was caused by all the renaming but the lesson learned (at least for me) was: Don’t mess with the title field…

If you’re still reading, a quick tip for working with lookup fields in CAML. A normal caml query with lookup looks like:

<Where><Eq><FieldRef Name=”Category” /><Value Type=”Lookup”>My category</Value></Eq></Where>

Nothing fancy here, but something that I’ve only found on a few blogs out there is how to do the lookup with the item id. Here’s how:

<Where><Eq><FieldRef Name=”Category” LookupId=”TRUE” /><Value Type=”Lookup”>234</Value></Eq></Where>

Happy SharePointing πŸ™‚

VM-ware Fusion and remote desktop fun

August 7, 2007

While I’ve been using apple computers for years now, I’m new to virtualization.

Because we develop web applications using Ruby on Rails, we decided to work with apple MacBooks. This is really nice because we then look cool while writing cool code, but a challenge when we do consultancy work on other platforms. Currently I’m doing Sharepoint (MOSS 2007) development for a customer and for this MacOS just won’t cut it. For this we’ve bought VMware Fusion. I cannot praise this magnificent piece of software enough. It just works (and I’m still running with the beta version).

So a couple of days ago I had to connect via remote desktop to my MOSS development environment and change my default password. To change my password on the Windows 2003 server I had to do a “ctrl-alt-delete“, and then it hit me… How the heck do I do this with my MacBook keyboard?! I’ve started a Windows XP in VMware Fusion and connected to a (virtual) Windows 2003 Server through Remote Desktop (talk about virtualization :)). I search the net but could not really find anything about this cocktail, so I wanted to share my findings on this tricky key combination (or at least store it somewhere for when I need it again in six months):

fn-M + numeric enter (the funny up arrow next to the right apple key) + <– (the top right delete key)

I used like an hour to figure this one out πŸ™‚


Design a site like this with WordPress.com
Get started