Software dev, tech, mind hacks and the occasional personal bit

Month: September 2007

ACS Talk – “Delicious .NET” – 3rd Oct

I’ll be giving a talk at an ACS event after work on Wed next week (3rd October). Here’s the blurb:

A tasty take on WPF, WCF, LINQ and O-R Mapping

An exploration of some of the freshest, tastiest and most powerful features in .NET 3.5 through implementing a useful application.
You’ll take away an understanding of what’s in .NET 3.5 and how to build online and offline applications with the new technology stack supported by Visual Studio 2008 (Orcas Beta 2).

Location
Norman Selfe Room,
Level 3,
280 Pitt St Sydney (Sydney Mechanics School of Arts)

Time
6:15pm, 3rd October 2007

For more info or to register, please visit the ACS site.

Hope you can come 🙂

Reflexil, cute code injection for C#

While catching up on my favourite blogs, I came across Reflexil on Fabrice’s blog. Reflexil is able to do C# code injection into existing assemblies and save the resulting assembly. I haven’t given it a go yet, but it looks like a really neat tool. The legal implications may mean it is only useful for emergency patching or debugging however…

WebJam this Saturday Night

WebJam is usually quite fun. The premise is that a large group of people meet in a pub, have a few drinks (often sponsored by some generous company) and see quite a number of presenters who have 3 minutes each to show off cool, web-related stuff they’ve done recently. The next one is this Saturday. Details as follows:

Place: Bar Broadway (opposite UTS)
Date: 29 Sept 07
Time: 6pm

I’m planning to go, and also to give a 3 minute presentation on my new free wedding registry site.

Hope to see you there!

JRuby on Rails with GoldSpike – Scaling for more users

The default configuration for running JRuby on Rails using GoldSpike only allows 4 instances of the JRuby runtime. This means that if there are more than 4 simultaneous requests from clients, the web server will respond with a server overloaded error. The easiest way to see what’s going on is to take a look at the ‘createObjectPool’ method of RailsServlet.

With a dedicated production server with 1gig of memory, it is possible to allow a lot more JRuby runtimes, and hence allow for more simultaneous users. A little load testing on a fairly small app suggested that 20 instances of JRuby runtime would fit comfortably under the 1gig ceiling and not overload the processor.

An easy way to change the max number of runtimes is to edit ‘web.xml’ in a JRuby application’s WEB-INF directory. Parameter is set as follows:

  <context-param>
    <param-name>jruby.pool.maxActive</param-name>
    <param-value>20</param-value>
  </context-param>

It is also worth checking with the web server configuration to ensure that the web server allows more threads than the number of JRuby runtimes specified in ‘web.xml’.

ScreenCasting

Update: I closed down yourweddingpresents.com in 2013, and let the domain lapse. In 2023, a zombie version was set up by parties unknown at the same domain, using my pages scraped from the wayback machine. This site does not work, and is not run by me despite having my name on it. I am attempting to have it closed down.

After being inspired by the Rails screencast long ago, I thought it would be fun to make a screencast for my free wedding registry site. It takes a bit of work.

I checked out a few different screencast recording packages and ended up going with CamStudio. It is a fairly basic product but free and good enough for my needs. It lets you choose a window to record and also lets you include an audio track. I think the easiest way to use it is by recording to AVI (very quick) and then converting to Flash SWF (slow), when you are happy with the movie. In terms of SWF settings, I found the best combination was 16 bit colour, Playback rate and Keyframe rate at 20 frames / second. It is also a good idea to set the ‘Percent of movie to preload’ to something like 15%, to get things rolling quickly for your viewers.

I’m reasonably happy with the resulting wedding registry screencast, although there is certainly room for improvement. CamStudio unfortunately doesn’t let you set the look and feel of the playback controls, so they feel a bit out of place. When I get time, I might also split the screencast into two – one from the bridal couple’s perspective, and one from a guest’s perspective.

YourWeddingPresents.com (wedding registry site) now live!

Update: I closed down this site in 2013, and let the domain lapse. In 2023, a zombie version was set up by parties unknown at the same domain, using my pages scraped from the wayback machine. This site does not work, and is not run by me despite having my name on it. I am attempting to have it closed down.

I’m really pleased to announce that YourWeddingPresents.com (a free, independent, wedding registry site) is now live!

When my sister was getting married, she had a lot of trouble finding a good free wedding registry that was not tied to any particular shop. I developed the wedding registry site to fill this gap, and also to improve my web programming skills. I’ve tried to design Your Wedding Presents to be really quick to sign up and easy to use. Please tell me if there are any problems with the site, or ways the site could be made better.

On the technical side, I developed Your Wedding Presents using Ruby on Rails. It is running on an Apache load-balanced Mongrel cluster and data is stored in MySQL. It is hosted on Rails Playground.

JRuby, Rails and Statics

Say you wanted to store some information across different calls to your JRuby/Rails application on the server side. You could use a database, or memcached. However, what if you just want to do something very simple like a basic cache, and you don’t have a database for your application? Memcached seems like overkill, and would complicate your deployment considerably. So, what about just using statics?

Well, you can’t do it in Ruby, as the Rails integration servlet spawns multiple instances of the JRuby interpreter.

Ruby code in a page view:

<h1>Ruby global number</h1>
<% $i ||= 0 %>
<% $i += 1 %>
<%= $i %>

<h1>Ruby obj id</h1>
<% $o ||= Object.new %>
<%= $o.object_id %>

Results between multiple refreshes of the page:

Ruby global number
1 
Ruby obj id
244 

Ruby global number
1 
Ruby obj id
256 

Ruby global number
2 
Ruby obj id
244 

Ruby global number
2 
Ruby obj id
256 

Our requests seem to be switching between two instances of the Ruby interpreter.

However, we *can* do it in Java. My clever, Java-literate colleagues explained that Java application servers and servlet containers use a single instance of the JVM, but have a class loader for each application. The class loader stores class information and static values. This means that within one application, the static values will be maintained between requests, but a different application on the same server will have its own set of unrelated static values (similar to AppDomains in .NET).

If we add a call to a static method in Java that increments an integer and returns it, our view looks like this:

<h1>Ruby global number</h1>
<% $i ||= 0 %>
<% $i += 1 %>
<%= $i %>

<h1>Ruby obj id</h1>
<% $o ||= Object.new %>
<%= $o.object_id %>

<h1>Java incrementing static integer</h1>
<%= TestClass.incrementAndReturnNumber() %>

Our results now look a lot more useful. The Java static integer is getting incremented each call to the view:

Ruby global number
1 
Ruby obj id
244 
Java number
1 

Ruby global number
1 
Ruby obj id
256 
Java number
2 

Ruby global number
2 
Ruby obj id
244 
Java number
3 

Ruby global number
2 
Ruby obj id
256 
Java number
4 

From this little experiment, Java statics seem like a possible way to go for storing temporary data on the server side (eg, a cache implemented as a singleton) for JRuby / Rails. Another option may be to use the ServletContext from the JRuby Rails integration servlet – probably an area worth investigating.

Web Design and CSS, how hard can it be?

So, audaciously, I decided to do the theme for my pet Rails project. How hard can CSS and Photoshop really be? Having made basic layouts and modified various themes, I thought my CSS skills were adequate, and Photoshop is, after all, just another Windows application.

With the help of my talented fiancee and flatmate, the Photoshop side of things went fairly well for a banner image. Not too hard, find a good image and apply some layers, effects and text.

When time came to hit the CSS, I felt confident. Based on my vague trial and error understanding of floats etc, I managed to spend a fair bit of time messing around, painfully, slowly getting a good layout in Firefox, only to be frustrated by an awful rendition in Internet Explorer. Then trying to make a compromise layout between the two that looked reasonable in both, only to have a slight change throw everything into disarray. Repeat ad nauseum.

Clearly, I my confidence was misplaced, and my CSS skills sucked. Time to actually learn something. I turned to my yet un-opened copy of “Beginning CSS Web Development – From Novice to Professional” by Simon Collison, recommended by a ThoughtWorks buddy, Warren. I read it pretty much cover to cover on Saturday. It was quite a good read, practical with useful examples and a light tone. Lots of good stuff within:

  • Clear explanation of the basics
  • Coverage of different browsers
  • Some insight into a web designer’s mind
  • A number of useful page layouts
  • Different options for form layouts
  • Some advanced CSS tricks
  • A nice worked example of cutting up a Photoshop mock-up and turning it into image slices, CSS and HTML.

Overall, the book was pretty much exactly what I needed to get back on track and bring my misbehaving CSS under control.

Here’s a few things I learnt that solved some of the most pressing woes I was having with CSS:

  • Margins collapse into each other. Ie, if you have two elements next to each other and each has a 10px margin, the total distance between the two will only be 10px. Adding 1px of padding will mean the borders of the two elements don’t touch and hence won’t collapse
  • Generally avoid padding on fixed width elements. Instead, wrap them in another element such as a div, and put the padding on it. That way, you avoid needing to do any hacks for the broken box model in older versions of IE.
  • You can put an ID on each pages’ BODY, and that way, you can easily target elements on individual pages using their body’s ID.
  • Often a good way of doing layout with floats is to keep the document as much using the normal flow layout, and then put in appropriate margins or padding to make space for floats, rather than floating the whole document.
  • The order of values in short declarations like ‘margin: 1px 2px 3px 4px;’ is top, right, bottom, left.
  • It is a good idea to stick to the limited set of web-safe fonts, and also use a number of fallbacks for font family to cover all viewers.

My app’s theme is not finished yet, but CSS has now become more a pleasure than a frustration.

Powered by WordPress & Theme by Anders Norén