<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule" version="2.0"><channel><title>David Jones - Home</title><link>http://www.d-jones.com/</link><language>en-US</language><lastBuildDate>Wed, 17 Jun 2009 20:42:37 PDT</lastBuildDate><generator>Mephisto Noh-Varr http://mephistoblog.com</generator><description></description><geo:lat>-43.534767</geo:lat><geo:long>172.64034</geo:long><creativeCommons:license>http://creativecommons.org/licenses/by/2.0/</creativeCommons:license><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/djones_blog" type="application/rss+xml" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><item><title>How to display recent posts from a WordPress blog on your Rails site</title><link>http://www.d-jones.com/2009/6/18/how-to-display-recent-posts-from-a-wordpress-blog-on-your-rails-site</link><category>How To's</category><category>Ruby on Rails</category><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">djones</dc:creator><pubDate>Wed, 17 Jun 2009 20:42:37 PDT</pubDate><guid isPermaLink="false">tag:www.d-jones.com,2009-06-18:21281</guid><description>We've had quite a flurry of clients at &lt;a href="http://www.resolvedigital.co.nz"&gt;Resolve Digital&lt;/a&gt; (and even ourselves) wanting to integrate their Rails site with a Wordpress blog. We generally recommend our clients use Wordpress if they want a blog but that leads to one problem, Rails is written in Ruby and Wordpress is written in PHP.

And of course the client wants the latest blog post or last few recent posts up on their home page. But that very home page is running off their Rails site, so somehow the Wordpress blog needs to integrate with the Rails site.

!/assets/2009/6/18/resolve-digital.png!

How's how you do it.

h2. Step 1 - Fetch the RSS feed from the Wordpress Blog

Copy this file (rss_parser.rb) into RAILS_ROOT/lib/

&amp;lt;script src="http://gist.github.com/131656.js"&gt;&amp;lt;/script&gt;

This will do the hard work for you. It simply downloads a RSS feed and parses for you.

If that doesn't float your boat, checkout &lt;a href="http://simple-rss.rubyforge.org/"&gt;SimpleRSS&lt;/a&gt; as an alternative.

In this example we have PagesController with a home method. Add line 5 to get the latest posts from your blog. Obviously change the RSS feed URL to the one on your Wordpress blog.

&amp;lt;script src="http://gist.github.com/131658.js"&gt;&amp;lt;/script&gt;

h2. Step 2 - Display the post in a view

And finally show the post in the home page view.

&amp;lt;script src="http://gist.github.com/131660.js"&gt;&amp;lt;/script&gt;

I'm sure many of you will prefer to show the latest 3 posts instead, here's how:

&amp;lt;script src="http://gist.github.com/131661.js"&gt;&amp;lt;/script&gt;

Note you have to run strip_tags() because if you truncate HTML a tag might be open but never close because you snipped the HTML too soon. So we take out all tags first so we just have plain text and then truncate.

h2. Performance

At first I was a little worried that downloading the RSS feed from the blog each time the page is requested would cause performance issues, but for those of us who have sites that don't have a huge flow of traffic this will do just fine.

If you're still concerned about it, here's two ideas:

* Setup a CRON job to download the RSS feed nightly
* Use time based fragment caching to expire that part of the view daily so only the first person to request the page that day triggers the RSS feed to download.&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/djones_blog?a=JDGz_Gm8hcU:4afIdozFClU:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/djones_blog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/djones_blog?a=JDGz_Gm8hcU:4afIdozFClU:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/djones_blog?i=JDGz_Gm8hcU:4afIdozFClU:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/djones_blog?a=JDGz_Gm8hcU:4afIdozFClU:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/djones_blog?i=JDGz_Gm8hcU:4afIdozFClU:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/djones_blog?a=JDGz_Gm8hcU:4afIdozFClU:KwTdNBX3Jqk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/djones_blog?i=JDGz_Gm8hcU:4afIdozFClU:KwTdNBX3Jqk" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description></item><item><title>What's the temperature in Christchurch? Ruby to the rescue.</title><link>http://www.d-jones.com/2009/6/9/what-s-the-temperature-in-christchurch-ruby-to-the-rescue</link><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">djones</dc:creator><pubDate>Thu, 11 Jun 2009 15:38:22 PDT</pubDate><guid isPermaLink="false">tag:www.d-jones.com,2009-06-09:21279</guid><description>&lt;p&gt;If you're on a Mac, here's a fun wee bit of code to have your computer tell you what temperature it is in Christchurch down to the minute. The Christchurch City Council has a pretty kick arse weather station &lt;a href="http://www.ccc.govt.nz/weatherdata/waterweb.htm"&gt;running over here&lt;/a&gt; that we'll leverage to get the info.&lt;/p&gt;
&amp;lt;script src="http://gist.github.com/126885.js"&gt;&amp;lt;/script&gt;

&lt;p&gt;Downloading and running it. Open up terminal and follow these steps:&lt;p&gt;
&lt;pre&gt;&lt;code&gt;
~$ cd ~
~$ curl -o weather.rb -s http://gist.github.com/raw/126885/cc4567aa7e7d6412d6a7dfff646f3c22ac2fa149/weather.rb
~$ chmod +x weather.rb 
~$ ./weather.rb 
It is 11.7 degrees outside in Christchurch with a windchill of -0.2 degrees
~$ 
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;a href="/assets/2009/6/10/weather.aiff"&gt;Click to hear what that sounds like&lt;/a&gt;
&lt;p&gt;Since I'm a little crazy and like to have these things available without having to remember where the file to run is, I then setup an alias so I can type "weather" wherever I am in terminal and it will read to me what it's like outside.&lt;/p&gt;

&lt;code&gt;&lt;pre&gt;
nano ~/.bash_login
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
Add this line at the top:

&lt;pre&gt;&lt;code&gt;
alias weather="~/weather.rb"
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
and then hit ctrl + o then enter to save and then ctrl + x to exit.
&lt;/p&gt;
&lt;code&gt;&lt;pre&gt;
source ~/.bash_login
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now it will load in that alias when you next login to your computer. But since we haven't logged in again yet we just need to reload the file so we can use the command right now without having to login again.&lt;/p&gt;
&lt;p&gt;
&lt;p&gt;Finally now I can just type weather and it runs from anywhere in terminal&lt;/p&gt;
&lt;code&gt;&lt;pre&gt;
~$ weather
It is 11.7 degrees outside in Christchurch with a windchill of -0.2 degrees
~$ 
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
Now to automate that so it tells me at 11:50am before I go out to lunch ;-)
&lt;/p&gt;

&lt;h2&gt;Update&lt;/h2&gt;
&lt;p&gt;&lt;a href="http://www.flickr.com/photos/t0nyburton/"&gt;Tony's&lt;/a&gt; version&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
echo "It is "`curl http://www.ccc.govt.nz/weatherdata/waterweb.htm 2&gt;/dev/null | head -n 1 | cut -d' ' -f2`" degrees outside in Christchurch with a windchill of "`curl http://www.ccc.govt.nz/weatherdata/waterweb.htm 2&gt;/dev/null | head -n 1 | cut -d' ' -f3`" degrees."
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;a href="http://kennedytechnology.com/"&gt;Nathan's&lt;/a&gt; version&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
#!/bin/bash
W=(`curl -s http://www.ccc.govt.nz/weatherdata/waterweb.htm`)
echo It is ${W[1]} degrees outside in Christchurch with a windchill of ${W[2]} degrees
&lt;/pre&gt;&lt;/code&gt;
&lt;p&gt;Nice one guys!&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/djones_blog?a=4FqDd0zu6Vw:dQ26-RXyjN4:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/djones_blog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/djones_blog?a=4FqDd0zu6Vw:dQ26-RXyjN4:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/djones_blog?i=4FqDd0zu6Vw:dQ26-RXyjN4:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/djones_blog?a=4FqDd0zu6Vw:dQ26-RXyjN4:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/djones_blog?i=4FqDd0zu6Vw:dQ26-RXyjN4:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/djones_blog?a=4FqDd0zu6Vw:dQ26-RXyjN4:KwTdNBX3Jqk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/djones_blog?i=4FqDd0zu6Vw:dQ26-RXyjN4:KwTdNBX3Jqk" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description></item><item><title>Create UML diagrams online for free</title><link>http://www.d-jones.com/2009/6/9/create-uml-diagrams-online-for-free</link><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">djones</dc:creator><pubDate>Tue, 09 Jun 2009 14:04:14 PDT</pubDate><guid isPermaLink="false">tag:www.d-jones.com,2009-06-09:21277</guid><description>&lt;p&gt;Way back when I was studying towards the degree I hold today, a lot of the lessons I was taught I was already doing in "the real world". But there was one tool I did take away and still use regularly. That's UML diagrams. They help visualise the structure of usually something I can't hold in my head at one time.&lt;/p&gt;

&lt;p&gt;I used to have Visio when I was a PC user but I've recently cut back on the number of programs I have installed in favour of web applications that can do the same thing for me online (like Google Apps).&lt;/p&gt;
&lt;p&gt;To create UML diagrams you really don't need anything too complex, you just want to be able to show different items and the relationship or flow between them.&lt;/p&gt;

&lt;h2&gt;Meet yUML (beta)&lt;/h2&gt;

&lt;p&gt;&lt;a href="http://www.yuml.me/"&gt;yUML&lt;/a&gt; is a seriously kick arse idea. It turns out it's made by a Rails consulting company too so naturally I liked them a little more.&lt;/p&gt;

&lt;p&gt;You can create online with ease your own UML diagrams for free. Here's an example:&lt;br /&gt;

&lt;img src="http://d-jones.com/assets/2009/6/9/89c9be6e8644324030dd7a35e8c5cbad.png" alt="UML Diagram" /&gt;
&lt;br /&gt;



How do you do it? Instead of using an unreliable GUI to create these diagrams, you just use a wee little language they have invented which is strangely natural and easy to pick up. And it does make a lot of sense to not use a GUI and use a language in this case since we're dealing with a predominantly programmer market using this product.
&lt;/p&gt;
&lt;p&gt;
So go &lt;a href="http://www.yuml.me/diagram/scruffy/class/samples"&gt;checkout the examples&lt;/a&gt; and definitely give &lt;a href="http://www.yuml.me/diagram/scruffy/class/draw"&gt;making one a try&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
Nice one &lt;a href="http://engineroomapps.com/"&gt;Engine Room&lt;/a&gt;. 
&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/djones_blog?a=sG2UyYflsiI:SsiQBClIk8M:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/djones_blog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/djones_blog?a=sG2UyYflsiI:SsiQBClIk8M:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/djones_blog?i=sG2UyYflsiI:SsiQBClIk8M:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/djones_blog?a=sG2UyYflsiI:SsiQBClIk8M:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/djones_blog?i=sG2UyYflsiI:SsiQBClIk8M:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/djones_blog?a=sG2UyYflsiI:SsiQBClIk8M:KwTdNBX3Jqk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/djones_blog?i=sG2UyYflsiI:SsiQBClIk8M:KwTdNBX3Jqk" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description></item><item><title>Refinery CMS from Private to Public</title><link>http://www.d-jones.com/2009/5/30/refinery-cms-from-private-to-public</link><category>Ruby on Rails</category><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">djones</dc:creator><pubDate>Mon, 01 Jun 2009 13:51:47 PDT</pubDate><guid isPermaLink="false">tag:www.d-jones.com,2009-05-30:21275</guid><description>About 5 years ago I joined "Resolve Digital":http://www.resolvedigital.com . A lot has happened since then, we now even have a "Resolve Digital NZ":http://www.resolvedigital.co.nz our local New Zealand branch, but one of the items which has really been there from the beginning is our content manager. When I started at Resolve, they were using a PHP based content management system. At the time I had just learnt Rails and started to build our own content manager using it. Each site we completed we shaped it a little more into something we originally called M-Tools.

M-Tools was pretty cool, it was very simple and only had what we knew our clients wanted in it. As time went on we continued to modify it and finally came to the conclusion that we have something quite special here.

Patrick, our creative director at Resolve, did a bit of fiddling with the UI and we came up with a few nice features we'd like to have in it ourselves. And we hired Phil, who was a driving factor behind it's nice new modular architecture. It's from that point we renamed it to Refinery.

!/assets/2009/5/30/refinery-cms.png!

Refinery is now the starting point for almost all our projects and we decided hey if this is useful for us, we might as well share the love around. Anyone starting a new Rails site for a small business is going to be interested to at least check it out.

So yesterday I turned nearly 5 years of work, which has been tested and used by well over 50 of our clients into something freely available for anyone to download and start using for free themselves. We've made it completely open source.

So if you're interested checkout "RefineryCMS.com":http://www.refinerycms.com and if you're a developer then "here's our GitHub repository.":http://github.com/resolve/Refinery/

There's also an online demo that you can try out.
The public site is here: "http://demo.refinerycms.com/":http://demo.refinerycms.com/
And you log in using "demo" as the username and password here: "http://demo.refinerycms.com/admin":http://demo.refinerycms.com/admin&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/djones_blog?a=QkWJ1b0oBRc:6IEhh9OabLk:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/djones_blog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/djones_blog?a=QkWJ1b0oBRc:6IEhh9OabLk:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/djones_blog?i=QkWJ1b0oBRc:6IEhh9OabLk:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/djones_blog?a=QkWJ1b0oBRc:6IEhh9OabLk:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/djones_blog?i=QkWJ1b0oBRc:6IEhh9OabLk:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/djones_blog?a=QkWJ1b0oBRc:6IEhh9OabLk:KwTdNBX3Jqk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/djones_blog?i=QkWJ1b0oBRc:6IEhh9OabLk:KwTdNBX3Jqk" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description></item><item><title>Capistrano: Over engineering for small sites? Absolutely.</title><link>http://www.d-jones.com/2009/5/29/capistrano-over-engineering-for-small-sites-absolutely</link><category>Ruby on Rails</category><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">djones</dc:creator><pubDate>Fri, 29 May 2009 16:08:49 PDT</pubDate><guid isPermaLink="false">tag:www.d-jones.com,2009-05-29:21274</guid><description>I've just finished some work for a client who had a Ruby on Rails website setup on Mongrel. The interesting part is the developer has "gone" and that's when someone like myself gets called in.

The client was very confused as to how their website works and ultimately they just want to be able to log in and put some files on their site like many older PHP sites. They were asking for a "FTP log in".

The problem Mongrel servers like this are setup just for Rails sites, there often is no FTP. So I have to explain to the client what SFTP is. And that's fine but here's the catch, the developer used "Capistrano":http://www.capify.org/

So now it's like oh you can only put files over here in this system directory so everything you upload will be www.theirdomain.com/system/yourfiles. That's anything but ideal. It's also damn confusing to the client. Trying to explain their website code is in one place, but your "shared" files are in another folder is just odd to them.

And that's where I begin to wonder, this is a small low traffic website we're dealing with here. Capistrano is great for web apps that have developers behind it in the long run, which ultimately is saying that you have a large site where it's worth the money to hire people to look after it. But at the end of the day a small business, low traffic site doesn't need the extra complexities Capistrano brings.

I get the sense that in the Rails community there are certain ways of doing things which are seen as the "proper" way to do things when building a Rails site. The thing is the proper way is good when you're building a full on Rails web application used by thousands of people, but the proper way is such overkill for the majority of the sites which are small, low traffic websites.

Keep it simple stupid!&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/djones_blog?a=W3Rkb1NZJJk:jXdWdIiwXWc:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/djones_blog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/djones_blog?a=W3Rkb1NZJJk:jXdWdIiwXWc:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/djones_blog?i=W3Rkb1NZJJk:jXdWdIiwXWc:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/djones_blog?a=W3Rkb1NZJJk:jXdWdIiwXWc:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/djones_blog?i=W3Rkb1NZJJk:jXdWdIiwXWc:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/djones_blog?a=W3Rkb1NZJJk:jXdWdIiwXWc:KwTdNBX3Jqk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/djones_blog?i=W3Rkb1NZJJk:jXdWdIiwXWc:KwTdNBX3Jqk" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description></item><item><title>Gong - An iPhone App</title><link>http://www.d-jones.com/2008/8/19/gong-an-iphone-app</link><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">djones</dc:creator><pubDate>Tue, 19 Aug 2008 13:46:36 PDT</pubDate><guid isPermaLink="false">tag:www.d-jones.com,2008-08-19:58</guid><description>&lt;p&gt;
&lt;img src="/assets/2008/8/19/gong.jpg" /&gt;
As part of an effort to learn Objective-C, I've released my first iPhone app. Admittedly it is very simple, but I'm sure a few of you will have a bit of fun with it.&lt;/p&gt;
&lt;p&gt;I've had to learn a range of different things to get this to work including how to use the iPhone SDK, some basic QuartzCore framework stuff to animate the Gong and AudioToolbox framework to play the audio.
&lt;/p&gt;
&lt;p&gt;
The process of distributing the app to your own phone and on the iTunes AppStore is a challenge in itself.
&lt;/p&gt;
&lt;p&gt;
Hopefully my next app will be a little more sophisticated but for now you'll have to settle for the almighty Gong.
&lt;/p&gt;
&lt;p&gt;Here is a quick summary of what it can do:
&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;
We love the gong as much as you do and this is why we bring you this brilliant virtual gong.
&lt;/p&gt;
&lt;p&gt;
YOUR MISSION: To use this Gong to wake up anyone who is sleeping when you think they should not be.
&lt;/p&gt;
&lt;p&gt;
Features:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Plays realistic gong sound when you hit the gong&lt;/li&gt;
&lt;li&gt;Vibrates device when gong is hit&lt;/li&gt;
&lt;li&gt;The Gong shakes like a real one when you hit it&lt;/li&gt;
&lt;li&gt;Heaps of fun, perfect for you pranksters out there!&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;p&gt;
&lt;img src="/assets/2008/8/19/Picture_13.png" /&gt; It isn't live in the iTunes Store yet, but I'll post an update when it is. It's going for US$0.99 (NZ$1.29).
&lt;/p&gt;
&lt;p&gt;I've heard many people reporting it takes about 3 days to get approved the first time around and some waiting up to 14 days just to release an update to their application!&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/djones_blog?a=k65jTXF8yQg:PkGE7z0gHno:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/djones_blog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/djones_blog?a=k65jTXF8yQg:PkGE7z0gHno:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/djones_blog?i=k65jTXF8yQg:PkGE7z0gHno:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/djones_blog?a=k65jTXF8yQg:PkGE7z0gHno:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/djones_blog?i=k65jTXF8yQg:PkGE7z0gHno:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/djones_blog?a=k65jTXF8yQg:PkGE7z0gHno:KwTdNBX3Jqk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/djones_blog?i=k65jTXF8yQg:PkGE7z0gHno:KwTdNBX3Jqk" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description></item><item><title>iPhone in New Zealand: Vodafone's Greed</title><link>http://www.d-jones.com/2008/7/7/apple-iphone-new-zealand-vodafone</link><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">djones</dc:creator><pubDate>Mon, 07 Jul 2008 20:59:48 PDT</pubDate><guid isPermaLink="false">tag:www.d-jones.com,2008-07-07:53</guid><description>&lt;p&gt;
Vodafone just released their &lt;a href="http://www.vodafone.co.nz/iphone/plans.jsp"&gt;iPhone plans in New Zealand&lt;/a&gt; and oh boy did Vodafone screw us all!&lt;/p&gt;
&lt;p&gt;Sure it's a desired item, but NZ$1129 for a 16GB model is insane. You could almost &lt;a href="http://www.dse.co.nz/cgi-bin/dse.storefront/4872a03c07bbdabc273fc0a87f3b0727/Product/View/G2145"&gt;buy a 37" LCD TV&lt;/a&gt; for that price!
&lt;/p&gt;
&lt;p&gt;What's really insane is the prices of the plans. Their highest plan is $250/month and they still want you to pay $199 for the phone! You're going to pay them $6,000 over a period of 2 years and they want you to pay for the handset, I'm sorry, but that is about as greedy as it gets.
&lt;/p&gt;
&lt;p&gt;
In contrast, Telstra in Australia is offering the iPhone for free with a A$100 a month plan on a two-year contract. Which seems a little more reasonable!
&lt;p&gt;
I'm predicting there is now going to be somewhat of a blackmarket of iPhone's as people attempt to import them from elsewhere, jailbroken, to avoid any lame Vodafone plans that literally cost you an arm and leg.
&lt;/p&gt;
&lt;p&gt;
Next time Vodafone, sort your stuff out!
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Update:&lt;/strong&gt; Several others share the same thoughts &lt;a href="http://mothership.co.nz/blog/index.php/2008/07/08/iphone-rate-plans/"&gt;here&lt;/a&gt;, &lt;a href="http://blogs.nzherald.co.nz/blog/your-views/2008/7/8/what-do-you-think-vodafones-iphone-pricing-plan/?c_id=1501154"&gt;here&lt;/a&gt; and &lt;a href="http://www.geekzone.co.nz/iphone/5335"&gt;here&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;Unfortunately Stuff.co.nz &lt;a href="http://www.stuff.co.nz/4610626a28.html"&gt;reported it as being in-expensive&lt;/a&gt;. And then updated to say it was expensive - get it right the first time guys!
&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/djones_blog?a=WxUZti-3_PA:e_p8VLTvou4:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/djones_blog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/djones_blog?a=WxUZti-3_PA:e_p8VLTvou4:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/djones_blog?i=WxUZti-3_PA:e_p8VLTvou4:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/djones_blog?a=WxUZti-3_PA:e_p8VLTvou4:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/djones_blog?i=WxUZti-3_PA:e_p8VLTvou4:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/djones_blog?a=WxUZti-3_PA:e_p8VLTvou4:KwTdNBX3Jqk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/djones_blog?i=WxUZti-3_PA:e_p8VLTvou4:KwTdNBX3Jqk" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description></item><item><title>Ruby on Rails: From Hackers to the Enterprise</title><link>http://www.d-jones.com/2008/6/27/ruby-on-rails-from-hackers-to-the-enterprise</link><category>Ruby on Rails</category><category>White Papers</category><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">djones</dc:creator><pubDate>Wed, 09 Jul 2008 20:42:30 PDT</pubDate><guid isPermaLink="false">tag:www.d-jones.com,2008-06-27:52</guid><description>I was there in mid 2004. I was using Ruby on Rails when its version number was a small decimal. It wasn’t my fault, a few years of PHP is enough to make anyone take the plunge. I set aside a couple of weeks until I got confident and in week three I had my first commercial Rails application built and live. Now four years later, I have never looked back.

At the time, the Rails community was nothing more than 100 hackers hanging around online trying to help each other out with a common goal of writing beautiful code for their applications. Now Rails has become somewhat of a hot topic online.  But how did creator David Heinemeier Hansson pull this off? How could one man make such a huge dent in the development of web applications?

At first there was resistance. Rails has always been very firm on how you do things, there is little choice, you do it the Rails way or you’re doing it wrong. And it’s this very controversial approach that has been key to beating the resistance of uptake. It’s amplified the gap. Instead of having a few people who think Rails is alright, you get a mere two types of people, lovers and haters. There is no fence sitting here. These dedicated programmers spoke to their friends and with a strong opinion managed to pull in more Rails recruits.

Then there was denial. Now with a healthy backing of strong opinioned Rails hackers, Rails was starting to show up on respected industry sites like SlashDot in early 2005. The word was starting to spread. Along with outrageous claims like “Rails will make you 10 times as productive”. If anyone told me that, damn straight I’d deny it too.

Then there were copycats. Slowly but surely programmers in other languages started to work out that Rails was exactly what they were looking for. So what did they do? They took the architecture of the Rails framework and wrote it in the language of their choice. CakePHP for PHP cropped up in 2005, then Pylons for Python and even Microsoft is starting to show some similarities with their latest ASP.NET MVC framework. They always have said imitation is the sincerest form of flattery.

Then came the large start-ups. Start-ups took the risk and capitalised on the ability to start from the beginning in Rails. And boy did they ever! Sites like twitter.com, 43things.com and odeo.com were bang on the money. But the enterprise still resisted. No one ever got fired for choosing Microsoft right?

And here comes the enterprise. In 2006 and 2007, Rails got really bagged for not being able to scale. Now sites like twitter.com, which was recorded in 2008 to handle over 3 million twitter messages a day, you can’t doubt that Rails can and does truly scale.

But the hosting environment Rails needed has always been a good excuse not to use Rails. If your web framework doesn’t run on a standard open source enterprise web server like Apache, the enterprise isn’t going to even notice you.

But that issue is now solved too. Recently mod_rails was released, a module that allows you to run Rails properly on Apache, and is what I believe is going to see a frenzy of growth in the uptake of Rails in the enterprise. David HH said himself “This could become very popular, very fast!” and he’s absolutely right.

Rails is now, in 2008, being used by some seriously big names, Amazon.com, The BBC, IBM, Apple Computer, yellowpages.com and NASA to name a few. And it’s grown around the world with Rails development companies setting up shop just about everywhere.

It’s been a long hard push uphill to bring Rails to the enterprise and there is a long way to go yet, but both feet are well in the door.

&amp;lt;script src="http://w.sharethis.com/widget/?tabs=web%2Cpost%2Cemail&amp;amp;charset=utf-8&amp;amp;style=default&amp;amp;publisher=6063ab5f-1944-4013-be77-be03fc4e1eb2&amp;amp;popup=true" type="text/javascript"&gt;&amp;lt;/script&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/djones_blog?a=w8NoT3TEUqs:e_a_hACo9HQ:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/djones_blog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/djones_blog?a=w8NoT3TEUqs:e_a_hACo9HQ:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/djones_blog?i=w8NoT3TEUqs:e_a_hACo9HQ:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/djones_blog?a=w8NoT3TEUqs:e_a_hACo9HQ:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/djones_blog?i=w8NoT3TEUqs:e_a_hACo9HQ:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/djones_blog?a=w8NoT3TEUqs:e_a_hACo9HQ:KwTdNBX3Jqk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/djones_blog?i=w8NoT3TEUqs:e_a_hACo9HQ:KwTdNBX3Jqk" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description></item><item><title>Simulating Different Connection Speeds in OS X</title><link>http://www.d-jones.com/2008/6/16/simulating-different-connection-speeds-in-os-x</link><category>How To's</category><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">djones</dc:creator><pubDate>Sun, 15 Jun 2008 19:49:14 PDT</pubDate><guid isPermaLink="false">tag:www.d-jones.com,2008-06-16:49</guid><description>&lt;p&gt;
When developing a website or app it's useful to see what things feel like at different speeds.
&lt;/p&gt;
&lt;p&gt;
I just wanted to share the commands I've been using to acheive this. You could use this for limiting your traffic if you're downloading something but don't want to hog your connection if it's shared.
&lt;/p&gt;
&lt;p&gt;
So pop open Terminal.app and try the following:&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Limiting port 80 to dialup speed:&lt;/strong&gt;&lt;br /&gt;
&lt;code&gt;
sudo ipfw pipe 1 config bw 7KByte/s;sudo ipfw add 1 pipe 1 src-port 80;echo '\''Limiting port 80 to 7kbps'\'
&lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Removing the limit and restoring port 80 back to full speed:&lt;/strong&gt;&lt;br /&gt;
&lt;code&gt;
sudo ipfw delete 1;echo '\''Traffic resuming at full speed!'\'
&lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;And of course you can alter the speed and port to whatever you like.
&lt;/p&gt;
&lt;p&gt;
So there you have it, an easy little tip. Comes in handy at times, trust me.
&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/djones_blog?a=CrYJ6692hRE:ZpM5ggYRst4:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/djones_blog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/djones_blog?a=CrYJ6692hRE:ZpM5ggYRst4:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/djones_blog?i=CrYJ6692hRE:ZpM5ggYRst4:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/djones_blog?a=CrYJ6692hRE:ZpM5ggYRst4:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/djones_blog?i=CrYJ6692hRE:ZpM5ggYRst4:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/djones_blog?a=CrYJ6692hRE:ZpM5ggYRst4:KwTdNBX3Jqk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/djones_blog?i=CrYJ6692hRE:ZpM5ggYRst4:KwTdNBX3Jqk" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description></item><item><title>How To Fix Textile Paragraphs in Rails</title><link>http://www.d-jones.com/2008/6/5/fixing-textile-paragraphs-in-rails</link><category>How To's</category><category>Ruby on Rails</category><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">djones</dc:creator><pubDate>Wed, 04 Jun 2008 17:11:34 PDT</pubDate><guid isPermaLink="false">tag:www.d-jones.com,2008-06-05:48</guid><description>&lt;p&gt;
Rails has a &lt;a href="http://api.rubyonrails.org/classes/ActionView/Helpers/TextHelper.html#M001054"&gt;built in textilize() method&lt;/a&gt; but it by default treats a new line as a BR tag. Which is really lame and annoying.
&lt;/p&gt;
&lt;p&gt;
The code the Rails textilize() method uses is:&lt;br /&gt;
&lt;code&gt;textilized = RedCloth.new(text, [ :hard_breaks ])&lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
What this does is causes some textile text like this
&lt;pre&gt;
h1. Birds

I know all about birds. They have wings.

Birds eat worms.
&lt;/pre&gt;
&lt;p&gt;
into this HTML
&lt;/p&gt;
&lt;p&gt;
&lt;pre&gt;
&lt;h1&gt;Birds&lt;/h1&gt;
&lt;br /&gt;
I know all about birds. They have wings.
&lt;br /&gt;
Birds eat worms.
&lt;/pre&gt;
&lt;p&gt;Not good code at all!&lt;/p&gt;
&lt;h2&gt;The Solution&lt;/h2&gt;
&lt;p&gt;Rails by default isn't behaving how we need it so we have to override the method Rails uses. We do this by creating our own textilize() method in our application helper that doesn't include the &lt;code&gt;[:hard_breaks]&lt;/code&gt; option Rails does.&lt;/p&gt;
&lt;code&gt;&lt;pre&gt;
module ApplicationHelper
  
  def textilize(text) # overriding Rails method to remove hardbreaks
    if text.blank?
     ""
    else
     textilized = RedCloth.new(text).to_html
    end
  end
  
end
&lt;/pre&gt;&lt;/code&gt;
&lt;p&gt;So there you have it. Call the Textilize method now and you're Textile will be nicely formatted with paragraphs.&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/djones_blog?a=YpqtnfbzNTs:BHnjJ5Pg0SU:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/djones_blog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/djones_blog?a=YpqtnfbzNTs:BHnjJ5Pg0SU:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/djones_blog?i=YpqtnfbzNTs:BHnjJ5Pg0SU:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/djones_blog?a=YpqtnfbzNTs:BHnjJ5Pg0SU:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/djones_blog?i=YpqtnfbzNTs:BHnjJ5Pg0SU:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/djones_blog?a=YpqtnfbzNTs:BHnjJ5Pg0SU:KwTdNBX3Jqk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/djones_blog?i=YpqtnfbzNTs:BHnjJ5Pg0SU:KwTdNBX3Jqk" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description></item><item><title>Out with Photoshop and in with Pixelmator</title><link>http://www.d-jones.com/2008/3/25/image-editing-mac-osx-photoshop-pixelmator</link><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">djones</dc:creator><pubDate>Mon, 24 Mar 2008 19:39:17 PDT</pubDate><guid isPermaLink="false">tag:www.d-jones.com,2008-03-25:47</guid><description>&lt;p&gt;Abobe Photoshop is the industry standard image editing software, but today I've made the switch to &lt;a href="http://www.pixelmator.com/"&gt;Pixelmator&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;
Photoshop isn't that fast on a Mac nor is it very "Mac-like". And this is where I find Pixelmator really good. It's simple, insanely fast to startup and takes about 2 seconds to learn if you know Photoshop. Everything is pretty much in the same place as Photoshop which I imagine is why &lt;a href="http://www.gimpshop.com/"&gt;Gimpshop&lt;/a&gt; has become so successful. And I really love the black interface they've slapped onto it.&lt;/p&gt;

&lt;p&gt;For US$59 ($NZ78.74) it's a steal in comparison to Photoshop so consider making the switch if you're on a Mac!&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/djones_blog?a=kp3Ji_8IjCs:NL6GI6jbflU:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/djones_blog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/djones_blog?a=kp3Ji_8IjCs:NL6GI6jbflU:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/djones_blog?i=kp3Ji_8IjCs:NL6GI6jbflU:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/djones_blog?a=kp3Ji_8IjCs:NL6GI6jbflU:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/djones_blog?i=kp3Ji_8IjCs:NL6GI6jbflU:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/djones_blog?a=kp3Ji_8IjCs:NL6GI6jbflU:KwTdNBX3Jqk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/djones_blog?i=kp3Ji_8IjCs:NL6GI6jbflU:KwTdNBX3Jqk" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description></item><item><title>How to Fix Validation Alignment Issues in Rails</title><link>http://www.d-jones.com/2007/12/26/how-to-fix-validation-alignment-issues-in-rails</link><category>How To's</category><category>Ruby on Rails</category><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">djones</dc:creator><pubDate>Tue, 25 Dec 2007 19:02:50 PST</pubDate><guid isPermaLink="false">tag:www.d-jones.com,2007-12-26:46</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[
            <p>Here's a real quick tip which fixes a problem I've come across time and time again.</p>
<p>Consider the form below:</p>

<img src="/assets/2007/normal-form.png" alt="Wine Form" />
<p>Here's a real quick tip which fixes a problem I've come across time and time again.</p>
<p>Consider the form below:</p>

<img src="/assets/2007/normal-form.png" alt="Wine Form" />

<p>Here's a snippet of what the code looks like to create 3 of those fields:</p>
<code><pre>
<div class="field">
	&lt;%= f.label(:vintage) %>
	&lt;%= f.text_field :vintage, :size => 5 %> <small>Optional - e.g. 1990</small>
</div>
<div class="field">
	&lt;%= f.label(:alcohol) %>
	&lt;%= f.text_field :alcohol, :size => 5 %>% <small>e.g. 5.6 or 10.25 </small>
</div>
<div class="field">
	&lt;%= f.label(:residual_sugar) %>
	&lt;%= f.text_field :residual_sugar, :size => 5 %> g/L <small>e.g. 45 </small>
</div>
</pre>
</code>
<p>You can see I've added a few little side notes next to each field using the small tag. The problem with adding a note inline next to a field in Rails is when the form is submitted and the data isn't valid. The form returned looks like this:</p>

<img src="/assets/2007/form-with-errors.png" alt="Form with Errors" />

<p>As you can see, the little notes get pushed over onto the next line. That's because Rails puts a div around the fields that are invalid. These divs are assigned a "fieldWithErrors" class. Now this can be useful for highlighting fields that have errors. For example, I like to highlight the label for the field with an error in red text. So I add this to my CSS:
</p>

<code><pre>
div.fieldWithErrors label {
	color: #933; /* mid to dark red */
}
</pre>
</code>
<p>And that works great, but we still have this problem with the field notes jumping down. The reason for that is because the element Rails uses to put around the invalid field is a div and by default a div is displayed as a block element. We can fix this problem by forcing the browser to render it as an inline element by using the following CSS:</p>
<code><pre>
div.fieldWithErrors {
	display: inline;
}
</pre>
</code>
<p>Now it looks like this:</p>
<img src="/assets/2007/form-with-errors-fixed.png" alt="Form with Errors - Fixed" />

<p>So there you have it. A simple little tip some of you out there might find useful.</p>
          <div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/djones_blog?a=vRkTok4DwrQ:m0jQLqbWgrY:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/djones_blog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/djones_blog?a=vRkTok4DwrQ:m0jQLqbWgrY:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/djones_blog?i=vRkTok4DwrQ:m0jQLqbWgrY:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/djones_blog?a=vRkTok4DwrQ:m0jQLqbWgrY:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/djones_blog?i=vRkTok4DwrQ:m0jQLqbWgrY:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/djones_blog?a=vRkTok4DwrQ:m0jQLqbWgrY:KwTdNBX3Jqk"><img src="http://feeds.feedburner.com/~ff/djones_blog?i=vRkTok4DwrQ:m0jQLqbWgrY:KwTdNBX3Jqk" border="0"></img></a>
</div>]]></content:encoded><description>&lt;p&gt;Here's a real quick tip which fixes a problem I've come across time and time again.&lt;/p&gt;
&lt;p&gt;Consider the form below:&lt;/p&gt;

&lt;img src="/assets/2007/normal-form.png" alt="Wine Form" /&gt;</description></item><item><title>How to add Cropping Support to Acts_As_Attachment</title><link>http://www.d-jones.com/2007/10/11/cropping-support-for-acts_as_attachment</link><category>How To's</category><category>Ruby on Rails</category><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">djones</dc:creator><pubDate>Thu, 11 Oct 2007 16:17:11 PDT</pubDate><guid isPermaLink="false">tag:www.d-jones.com,2007-10-11:42</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[
            <p>
<a href="http://technoweenie.stikipad.com/plugins/show/Acts+as+Attachment">Acts_as_attachment</a> really kicks arse when it comes to handling files and images in your Rails application but one thing the <a href="http://www.kanthak.net/opensource/file_column/">file_column plugin</a> has over acts_as_attachment is cropping support. Time and time again <a href="http://www.resolvedigital.com">at work</a> we have a space in the design for an image which has to be a certain size. By that I mean it must have a set width and height. But the client needs to be able to put any image they want into that space. But what if they upload a bigger image? Or, what if it's different aspect ratio?
</p>


<p>
<a href="http://technoweenie.stikipad.com/plugins/show/Acts+as+Attachment">Acts_as_attachment</a> really kicks arse when it comes to handling files and images in your Rails application but one thing the <a href="http://www.kanthak.net/opensource/file_column/">file_column plugin</a> has over acts_as_attachment is cropping support. Time and time again <a href="http://www.resolvedigital.com">at work</a> we have a space in the design for an image which has to be a certain size. By that I mean it must have a set width and height. But the client needs to be able to put any image they want into that space. But what if they upload a bigger image? Or, what if it's different aspect ratio?
</p>
<h2>Example</h2>
<p>Imagine you've got a client that trains dogs. They're revising their home page and the designer has come up with a design that has space for 3 images that are exactly the same size. The designer thinks this looks great, but now you're stuck with the problem of how can you let the client upload any image of any size or aspect ratio and have them perfectly fit into those 3 boxes.</p>
<img src="/assets/2007/10/11/step1.jpg" alt="Step one" />
<p>
Acts_as_attachment allows you to resize images which is useful when you can have a fixed width or height, but the other is variable. But in this case the designer wants 3 images which are all the same size, both in height and width. This is what would happen if we used acts_as_attachment to resize the images using a fixed width, but variable height.
</p>
<img src="/assets/2007/10/11/step2.jpg" alt="Step two: Resizing only" />

<p>Out of the box, this is actually your best option. But I've taken acts_as_attachment one step further and added cropping support. This will allow us to resize, then crop the image so that it's scaled down, and then the left over bits are cropped off so that we can fit any image in these 3 boxes of fixed height and width. This is the results of using resizing and cropping:</p>
<img src="/assets/2007/10/11/step3.jpg" alt="Step Three: Resizing and Cropping" />
<p>Now the client can be confident they can upload any image they like and it's going to look nice on the site.</p>
<h2>Patching Acts_as_Attachment to Support Cropping</h2>
<p>
Once you've installed the acts_as_attachment plugin, find the <code>thumbnail_for_image</code> method which is in /vendor/plugins/acts_as_attachment/lib/technoweenie/acts_as_attachment.rb
</p>
<p>
For me the <code>thumbnail_for_image</code> method begins on line 242. This might be different for you. The method should look like this:
<code><pre>
def thumbnail_for_image(img, size)
  size = size.first if size.is_a?(Array) && size.length == 1 && !size.first.is_a?(Fixnum)
  if size.is_a?(Fixnum) || (size.is_a?(Array) && size.first.is_a?(Fixnum))
    size = [size, size] if size.is_a?(Fixnum)
    img.thumbnail(size.first, size[1])
  else
    img.change_geometry(size.to_s) { |cols, rows, image| image.resize(cols, rows) }
  end
end
</pre></code>
To add cropping support, change it to this:
<code><pre>
def thumbnail_for_image(img, size)
  size = size.first if size.is_a?(Array) && size.length == 1 && !size.first.is_a?(Fixnum)
  if size.is_a?(Fixnum) || (size.is_a?(Array) && size.first.is_a?(Fixnum))
    size = [size, size] if size.is_a?(Fixnum)
    img.thumbnail(size.first, size[1])
  elsif size.is_a?(String) && size =~ /^c.*$/ # Patch to enable cropping
    dimensions = size[1..size.size].split("x")
    img.crop_resized!(dimensions[0].to_i, dimensions[1].to_i)
  else
    img.change_geometry(size.to_s) { |cols, rows, image| image.resize(cols, rows) }
  end
end
</pre></code>
<p>Save and restart your web app and you should be up and running with cropping support!
<h2>How to Indicate you Want Cropping</h2>
<p>
In your model all you need to do is put a "c" infront of the dimensions on the thumbnail you want to resize and crop. The "c" indicates to acts_as_attachment that cropping should occur.
<code><pre>
acts_as_attachment :storage => :file_system,
                   :file_system_path => 'public/system', # Using Capistrano conventions
                   :max_size => 4.megabytes,
                   :content_type => :image, # only allow png, gif and jpg
                   :resize_to => "1000x1000",
                   :thumbnails => {:home => "c100x80",
                                            :something_else => "500>"}
</pre></code>
For the example above you might make a new thumbnail called "home". We've put a c infront of it to make sure the cropping occurs. The result should be an image fixed at 100x80 regardless of what size or aspect ratio the client uploads.
</p>
<h2>Extending this Idea Further</h2>
<p>If you take a look at the modifcations to acts_as_attachment to support cropping, you could easily modify it to support anything you like. Perhaps on a certain thumbnail you want a drop shadow to appear. You could make acts_as_attachment recognise "s" (for 'shadow') infront of the deminsions.</p>
<p>If you do anything cool like that please comment below and let us know!</p>

<p><small>Images used in example taken from <a href="http://www.dogbitelaw.com/graphics/dogs-running.jpg">here</a>, <a href="http://web.media.mit.edu/~nicholas/dog-1.JPG">here</a> and <a href="http://dogtownsend.com/images/dog28.jpg">here</a>.</small></p>
          <div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/djones_blog?a=Z8UhiBQMYYY:F4zhnjBc6rk:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/djones_blog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/djones_blog?a=Z8UhiBQMYYY:F4zhnjBc6rk:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/djones_blog?i=Z8UhiBQMYYY:F4zhnjBc6rk:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/djones_blog?a=Z8UhiBQMYYY:F4zhnjBc6rk:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/djones_blog?i=Z8UhiBQMYYY:F4zhnjBc6rk:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/djones_blog?a=Z8UhiBQMYYY:F4zhnjBc6rk:KwTdNBX3Jqk"><img src="http://feeds.feedburner.com/~ff/djones_blog?i=Z8UhiBQMYYY:F4zhnjBc6rk:KwTdNBX3Jqk" border="0"></img></a>
</div>]]></content:encoded><description>&lt;p&gt;
&lt;a href="http://technoweenie.stikipad.com/plugins/show/Acts+as+Attachment"&gt;Acts_as_attachment&lt;/a&gt; really kicks arse when it comes to handling files and images in your Rails application but one thing the &lt;a href="http://www.kanthak.net/opensource/file_column/"&gt;file_column plugin&lt;/a&gt; has over acts_as_attachment is cropping support. Time and time again &lt;a href="http://www.resolvedigital.com"&gt;at work&lt;/a&gt; we have a space in the design for an image which has to be a certain size. By that I mean it must have a set width and height. But the client needs to be able to put any image they want into that space. But what if they upload a bigger image? Or, what if it's different aspect ratio?
&lt;/p&gt;</description></item><item><title>How to Test Change with assert_difference() in Rails</title><link>http://www.d-jones.com/2007/8/28/test-change-assert_difference-method-rails</link><category>How To's</category><category>Ruby on Rails</category><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">djones</dc:creator><pubDate>Tue, 28 Aug 2007 15:10:26 PDT</pubDate><guid isPermaLink="false">tag:www.d-jones.com,2007-08-28:37</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[
            <p>
The Rails core team have really been kicking out some cool stuff recently. One addition I've been taking full advantage of is the <code>assert_differnce()</code> method (<a href="http://dev.rubyonrails.org/browser/trunk/activesupport/lib/active_support/core_ext/test/difference.rb?rev=6647">changeset here</a>). This method is only available to those of you who are using Edge Rails.
</p>
<p>
If you need to test something that changes, then <code>assert_differnce()</code> is perfect. Below is a typical example of something changing. We have a user class and we want to test the destroy method to make sure the user really does get destroyed.
</p>
<p>
The Rails core team have really been kicking out some cool stuff recently. One addition I've been taking full advantage of is the <code>assert_differnce()</code> method (<a href="http://dev.rubyonrails.org/browser/trunk/activesupport/lib/active_support/core_ext/test/difference.rb?rev=6647">changeset here</a>). This method is only available to those of you who are using Edge Rails.
</p>
<p>
If you need to test something that changes, then <code>assert_differnce()</code> is perfect. Below is a typical example of something changing. We have a user class and we want to test the destroy method to make sure the user really does get destroyed.
</p>
<p>
Let's take a step back for a moment. What changes when this user is deleted? User.count does, because there is now one less user to count. So we need to ensure that there is a difference in the count of users after deleting a user.
</p>
<h2>Before</h2>
<pre><code>
class UserTest &lt; Test::Unit::TestCase

  fixtures :users

  def test_should_delete_first_user
    # Record current user count
    old_count = User.count  

    # Delete the first user we find
    User.find(:first).destroy

    # Make sure the count is now 1 less than it was before
    assert_equal old_count -1, User.count  
  end

end
</code></pre>
<h2>After (using assert_difference)</h2>
<pre><code>
class UserTest &lt; Test::Unit::TestCase

  fixtures :users

  def test_should_delete_first_user
    assert_difference('User.count', -1) do
      User.find(:first).destroy
    end
  end

end
</code></pre>
<p>Ah yes, much nicer.</p>
          <div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/djones_blog?a=YuReAX46kRM:dItB3O_FZ0o:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/djones_blog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/djones_blog?a=YuReAX46kRM:dItB3O_FZ0o:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/djones_blog?i=YuReAX46kRM:dItB3O_FZ0o:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/djones_blog?a=YuReAX46kRM:dItB3O_FZ0o:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/djones_blog?i=YuReAX46kRM:dItB3O_FZ0o:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/djones_blog?a=YuReAX46kRM:dItB3O_FZ0o:KwTdNBX3Jqk"><img src="http://feeds.feedburner.com/~ff/djones_blog?i=YuReAX46kRM:dItB3O_FZ0o:KwTdNBX3Jqk" border="0"></img></a>
</div>]]></content:encoded><description>&lt;p&gt;
The Rails core team have really been kicking out some cool stuff recently. One addition I've been taking full advantage of is the &lt;code&gt;assert_differnce()&lt;/code&gt; method (&lt;a href="http://dev.rubyonrails.org/browser/trunk/activesupport/lib/active_support/core_ext/test/difference.rb?rev=6647"&gt;changeset here&lt;/a&gt;). This method is only available to those of you who are using Edge Rails.
&lt;/p&gt;
&lt;p&gt;
If you need to test something that changes, then &lt;code&gt;assert_differnce()&lt;/code&gt; is perfect. Below is a typical example of something changing. We have a user class and we want to test the destroy method to make sure the user really does get destroyed.
&lt;/p&gt;</description></item><item><title>6 Style Guidelines for CSS</title><link>http://www.d-jones.com/2007/7/16/style-guidelines-for-css</link><category>How To's</category><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">djones</dc:creator><pubDate>Tue, 09 Jun 2009 15:58:00 PDT</pubDate><guid isPermaLink="false">tag:www.d-jones.com,2007-07-16:36</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[
            <p>It's important to keep a consistant style when writing CSS. When you have a team of developers you might want to consider writing a guideline that everyone follows and agrees to.</p>

<p>Here are some guidelines I follow...</p>
<p>It's important to keep a consistant style when writing CSS. When you have a team of developers you might want to consider writing a guideline that everyone follows.</p>

<p>Here are some guidelines I follow...</p>

<ol>
<li>Always combine statements that can be combined. One line is shorter and sweeter. It groups all statements of the same type together which is useful and easier to access. For example:
<code>
<pre>
/* Better */
background: url(background.png) #00FF00 no-repeat;

/* Bad */
background-image: url(background.png);
background-color: #00FF00;
background-repeat: no-repeat;
</pre>
</code>
</li>
<li>
	Always use words for colours where possible. If you're dealing with a basic developer they're far more likely to recognise the word of the colour than the hex value. 
<code>
<pre>
/* Better */
color: white;

/* Bad */
color: #FFFFFF;
</pre>
</code>
</li>
<li>
Shorten hex colours where possible. Short and sweet.
<code>
<pre>
/* Better */
color: #F0F;

/* Bad */
color: #FF00FF;
</pre>
</code>
</li>
<li>
Hex values are easier to spot and read when in capitals.
<code>
<pre>
/* Better */
color: #F0F;

/* Bad */
color: #f0f;
</pre>
</code>
</li>

<li>
All hacks should be linked to documentation in a comment. Hacks can be pretty confusing looking to many CSS developers, so why not do them a favour and link them to some relevant documentation so they can go read up about it!
<code>
<pre>
/* Clearfix hack, see http://www.positioniseverything.net/easyclearing.html */
.clearfix:after {
    content: "."; 
    display: block; 
    height: 0; 
    clear: both; 
    visibility: hidden;
}
/* ... snip ... */
</pre>
</code>
</li>
<li>
Be careful not to duplicate CSS or forget to remove redudant CSS. We've all done this, written some CSS and then removed the HTML it was styling but never removed the CSS. <a href="http://code.google.com/p/css-redundancy-checker/">CSS redundancy checker</a> to the rescue! This Ruby script will run through your CSS and find and remove redundant CSS for you.
</li>
</ol>
<p>These are just 6 guidlines I follow. <strong>Comment if you have one of your own to add...</strong></p>
          <div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/djones_blog?a=z-7frekdcGk:3uSETSGgNa4:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/djones_blog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/djones_blog?a=z-7frekdcGk:3uSETSGgNa4:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/djones_blog?i=z-7frekdcGk:3uSETSGgNa4:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/djones_blog?a=z-7frekdcGk:3uSETSGgNa4:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/djones_blog?i=z-7frekdcGk:3uSETSGgNa4:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/djones_blog?a=z-7frekdcGk:3uSETSGgNa4:KwTdNBX3Jqk"><img src="http://feeds.feedburner.com/~ff/djones_blog?i=z-7frekdcGk:3uSETSGgNa4:KwTdNBX3Jqk" border="0"></img></a>
</div>]]></content:encoded><description>&lt;p&gt;It's important to keep a consistant style when writing CSS. When you have a team of developers you might want to consider writing a guideline that everyone follows and agrees to.&lt;/p&gt;

&lt;p&gt;Here are some guidelines I follow...&lt;/p&gt;</description></item></channel></rss>
