blog.eliotsykes.com

Icon

Recommended random plugin for Rails (find_random)

find_random is a decent rails plugin that I’ve been using for a while now on Missed Connections that is very handy for finding random active records.

The plugin author is Ben Tucker of Green River .  I’ve just emailed him in the hope he’ll add a couple of changes I submitted.

find_random subversion repository: http://pub.svn.greenriver.org/find_random/

Update: Heard back from Ben and he’s kindly merged in my changes – thanks Ben!

GMail has built-in Multiple Signatures (its called Canned Responses)

Gmail

When looking to find a way to have multiple signatures in gmail, I found a lot of older blog posts talking about Firefox plugins, which aren’t great if you use multiple computers or a different browser.

So anyway, there’s a better solution, works on all platforms and its built in to gmail.

  • Go to the Google Labs features in Gmail and enable “canned responses”.
  • Add your signatures to canned responses.  To add a canned response, “Compose” a new email, enter the signature you want, then just above the message text area use the “canned responses” drop down to save the signature.
  • Repeat above steps for every signature you want

Photo: Thanks to Mario

Finding original free photos for your blog

Polar Bear

Update 21/Dec/2009: I’m now using an easier method than this, Sprixi – see blog post or go to Sprixi

A week-long feature of New York Missed Connections has begun over on the Missed Connections blog.

For each post I’ll be using a photo with a Creative Commons license found on Flickr, although not all Flickr photos have the Creative Commons license.  To find the ones that do:

  1. Go to Flickr Advanced Search
  2. Enter the search terms and any other criteria you want
  3. To find Creative Commons licensed content: scroll down the page and be sure to check the box labelled “ “.  There are some sub-checkboxes here you may also want to check depending on the intended use of the photo.
  4. Click the search button

Once you’ve got the results back, consider sorting by “Most interesting” so you see some of the best photos matching your search first.

Then, when you’ve clicked through to the photo you want, look towards the bottom of the right-hand column of the photo’s page for the “Additional Information” heading.  Underneath the heading there’ll be a “Some rights reserved” link, which you should click on to find the specific terms of the Creative Commons license the photographer has chosen for the photo.  If the photo’s license doesn’t jar with your intended use then you can use the photo, and bear in mind  you’ll normally need to attribute the photographer in the article you publish the photo – I suggest a link to the photo’s page on Flickr and a link to the photographer’s Flickr profile.

Finally, you might like to drop the photographer an e-mail or Flickr-mail as they’ll probably be interested in hearing how their photo is being used.

More about Creative Commons licensed photos on Flickr.

Photo: Thanks to Valerie for making this amazing photo of a Polar Bear available to the World

MovieStinger.com and RunPee.com improve your cinema experience

Note to self: check these web sites before stepping into a movie

“Post credits scene database” MovieStinger.com

“Helping your bladder enjoy going to the movies as much as you do” RunPee.com

Thanks to George Norman for this post

How to move subversion subdirectory to its own repository

Thanks to Walter Reiner for his guide on moving a svn directory to a different repository, it helped me out this morning.

Update: I couldn’t get this to work for me (svnadmin broken pipe on cygwin), I think its a problem with my setup rather than the instructions. As it is just a local filesystem repository with only my work in it, and life is short, I’ve decided to just do an svn export and import it into a new repository. I’ll keep the old repository subdirectory kicking around for a while just in case I need the history.

100 Most Inspiring Movies

To kill a Mockingbird movie poster

Tonight I’m watching To Kill a Mockingbird, and so I wikipedia’d it and found out that it is 2nd in a list of America’s 100 most inspiring movies, as judged by the AFI in 2008.  The list is good reading for movie lovers. Here’s some interesting stats (copied from wikipedia) about the 300 movies from the original ballot that the final 100 were selected from:

Quoted from: AFI’s 100 Years… 100 Cheers

UserVoice vs. Get Satisfaction

UserVoice logo
Get Satisfaction Logo

Just been deciding what feedback doowhacky to use with Missed Connections.

Clearly it came down to two of the main players, UserVoice and Get Satisfaction, with UserVoice taking the top spot, as it just has a better feel to it (although Get Satisfaction is very good) and according to the comments on this post by Doriano Carta (aka @paisano whos tweets I’m a fan of, worth a follow) it generates more feedback and that’s the measure that sold me.

Green Lantern movie gets green lit

Not really, I just got a kick out of writing green twice in a headline, but there is this fan-made trailer

This give anyone else geekbumps?

Originally seen at Nerdist

Intention revealing naming – a real world example

For anyone looking for a realistic example of intention revealing naming, I hope this requirement I encountered will help you out.  Here you’ll see 3 versions of the requirement in code, each one an improvement on the previous.

Background

I do some work for an online pharmacy.  Most of the products the pharmacy sells online are available to be bought by anyone, however, there is a small set of prescription products for sale that are only available to certain customers.

A product can belong to any number of categories.  A category may be designated as a “prescription category”.  If a product belongs to a prescription category then the product is a prescription product.

For every product we track the quantity in stock.  If a product sells out then an “out of stock” message is shown to the customer and the “add to cart” link is removed.

Here’s an idea of the view code I started with:

if (product.getQuantity() < 1) {
  "Sorry this product is out of stock"
} else {
  "<a href=...>Add to cart</a>"
}

New business requirement
If a prescription product sells out, then it can still be ordered by the customer.  The customer does not need to know that the product is out of stock as the pharmacy can now get it shipped to them in time.

1st attempt at introducing requirement
We use the existing Product method “belongsToPrescriptionCategory()” to determine if this is a prescription product.

if (product.getQuantity() < 1
  && !product.belongsToPrescriptionCategory()) {
  "Sorry this product is out of stock"
} else {
  "<a href=...>Add to cart</a>"
}

belongsToPrescriptionCategory() loops through each category the product belongs to and if it finds a prescription category then it returns true. If none of its categories are prescription ones then false is returned.

1st attempt summary:  Its kind of clear what is going on here, but it could be clearer.  Worse is the potential for duplication.  If you need to perform this check elsewhere in the view then your code will become ugly.  You’re aiming for clear and elegant, hence your code ought to read like a story.

2nd attempt
So we want the code to read like a story, how about this?

if (product.isOutOfStock()
  && !product.requiresPrescription()) {
  "Sorry this product is out of stock"
} else {
  "<a href=...>Add to cart</a>"
}

2 new methods have been introduced to Product:

isOutOfStock() {
  return getQuantity() < 1;
}

requiresPrescription() {
  return belongsToPrescriptionCategory();
}

This last method demonstrates a useful technique that I rely upon: wrapping an existing method call with an intention revealing name (‘requiresPrescription’ is the intention revealing name). Anyone reading the code for the first time will understand what is going on quicker than if I hadn’t done this. Its also a help to me when I come back to read this code for the first time in a few months and have completely forgotten the purpose and reasons behind it.

2nd attempt summary: The code is no fairytale but it is an easier to read story. We still have potential for needless duplication by having those 2 method calls in the if expression.

Final attempt

if (product.showInShopAsOutOfStock()) {
  "Sorry this product is out of stock"
} else {
  "<a href=...>Add to cart</a>"
}

Product’s new methods:

showInShopAsOutOfStock() {
  return isOutOfStock() && showableInShopAsOutOfStock();
}

showableInShopAsOutOfStock() {
  return !neverShowInShopAsOutOfStock();
}

neverShowInShopAsOutOfStock() {
  return requiresPrescription();
}

3rd attempt summary: We’ve removed the excessive code from the view layer and have ended up with code who’s intention you know immediately the first time you read it.

That method name “showInShopAsOutOfStock()” tells you exactly what the purpose of that view code is. If you need to know the business reasons behind why we show something as out of stock in the shop then you go and take a look at the new methods in the Product class. Business reasons do not need to be explicit everywhere you want to test whether to show a product as out of stock in the shop.

Summary
Intention revealing names make your code clear, they remove duplication, and make it quicker to add new requirements. For example, suppose another new requirement came in that said I had to make it so all products that cost over £1000 should never be shown in the shop as out of stock, my first attempt would have me add to the neverShowInShopAsOutOfStock() method:

neverShowInShopAsOutOfStock() {
  return requiresPrescription() || getPriceInPounds() > 1000;
}

Simple right? Remember long descriptive method names are a widely accepted practice and you may find it more fun than writing lots of comments to explain your code. Paragraphs of comments can go stale quickly, descriptive method names tend to not.

Looking for a colour multifunction laser printer?

I was, and I’ve just ordered one.

This is it

Samsung CLX-3175FN All-in-One Colour Laser Printer, Copier, Scanner and Fax

Samsung 3175-FN. I hope it fits in my flat

As far as I can tell by comparing specs the Dell 1235cn printer is this model rebadged (specifically the 3175-FN model, Samsung also do FW, F, and plain 3175 models, where the F stands for Fax, N for Networkable, and W for wireless).

Dell 1235cn Multifunction Laser Printer

Dell 1235cn. Look familiar?

Although I ordered from Amazon, a slightly better price was available from Acer Direct .

The Dell is only slightly pricier but available with 2 years on site warranty from Printerland, which seems like a very good deal.

If you want the plain Samsung 3175 model, the best price I could find was on Pixmania and it came in under £200 including VAT.

Remember all of this is only correct in my often wrong opinion and at time of writing.

Sites I used for price comparison were Froogle and Kelkoo.  Google ads also threw up some pretty good prices.

Who’s Blog?



Hello, I’m Eliot Sykes and this is my blog. Thank you for visiting. I'm the Founder of Missed Connections


Read about my current projects, contact me or find me on github