<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>Pete Roome Blog</title>
    <description>Web Developer, Ruby on Rails examples, Wordpress hacking</description>
    <link>http://peteroome.com/articles.rss</link>
    <item>
      <title>Database Adapter Specific SQL Queries with Heroku Cloud Hosting</title>
      <description>&lt;p&gt;Heroku is a brilliant cloud hosting service and i would highly recommend their service. But i have recently stumbled across a minor issue with a named_scope i Rails.&lt;/p&gt;

&lt;p&gt;I am building a site for the Nottingham Trent University Photography Degree Show. The sites homepage feaures a number of images fading in and out using JQuery to create some movement. In order to keep the page fresh, the images selected are a random collection each time the page is refreshed. &lt;/p&gt;

&lt;p&gt;This was done simply using the 'rand()' function on the order for the named_scope:&lt;/p&gt;

&lt;p&gt;:order =&gt; 'RAND()'&lt;/p&gt; 

&lt;p&gt;However, to my surprise this did not work when it came to deploying to my staging version of the site on Heroku. As anyone who is familiar with Heroku will know, the hosting service uses a grid based Postresql database solution which translates your database on deploy; all very clever and impressive but beyond the scope of this post.&lt;/p&gt;

&lt;p&gt;Anyway, it turns out that the MySQL 'rand()' function, in PostgreSQL, is actually &quot;random()'. This made for some irritating scenarios of forgetting to make the change each time i deployed.&lt;/p&gt;

&lt;p&gt;Fortunately, it's possible to target specific database types with my named_scopes and provided sufficiently edited code to work either locally on my MySQL setup or remotely on the Heroku account:&lt;/p&gt;

&lt;p&gt;case ActiveRecord::Base.connection.adapter_name
when 'PostgreSQL'
     named_scope :for_home_page, :conditions =&gt; {:published =&gt; true}, :limit =&gt; 28, :order =&gt; 'RANDOM()'
else
     named_scope :for_home_page, :conditions =&gt; {:published =&gt; true}, :limit =&gt; 28, :order =&gt; 'RAND()'
end&lt;/p&gt;

</description>
      <pubDate>Fri, 14 May 2010 22:38:02 +0000</pubDate>
      <link>http://peteroome.com/articles/16-database-adapter-specific-sql-queries-with-heroku-cloud-hosting.rss</link>
      <guid>http://peteroome.com/articles/16-database-adapter-specific-sql-queries-with-heroku-cloud-hosting.rss</guid>
    </item>
    <item>
      <title>Downloading a Facebook &quot;Page&quot; feed via Wget</title>
      <description>&lt;p&gt;So today i had to set up some Cron jobs to download a few feeds from various websites. I built a Social networking timeline on a site we are about to deploy here at Kyan and didnt want to hit the individual websites directly every couple of minutes in order to acquire the data.&lt;/p&gt;

&lt;p&gt;To overcome this i decided that setting up cron jobs to download the feeds would be a more reliable method. This way our own site would not be affected by any downtime experienced by any of the sites who were providing our feeds. &lt;/p&gt;

&lt;p&gt;I used the wget tool to download the feeds but found i was unable to download the Facebook feed i wanted. An error was returned and i checked out the page which showed that my browser wasnt supported.  Fortunately wget will allow you to supply a user-agent string with your command in order to force a download in this scenario:&lt;/p&gt;

&lt;p&gt;wget --user-agent=&quot;some user agent string&quot; &quot;download link&quot;&lt;/p&gt;

&lt;p&gt;For added sugar, you can also rename the file your downloading with wget too:&lt;/p&gt;

&lt;p&gt;wget -O some_file_name.ext &quot;download link&quot;&lt;/p&gt;

&lt;p&gt;Perfect.&lt;/p&gt;</description>
      <pubDate>Fri, 29 Jan 2010 17:09:15 +0000</pubDate>
      <link>http://peteroome.com/articles/15-downloading-a-facebook-page-feed-via-wget.rss</link>
      <guid>http://peteroome.com/articles/15-downloading-a-facebook-page-feed-via-wget.rss</guid>
    </item>
    <item>
      <title>Rails form object id fixed. Comments working once more.</title>
      <description>&lt;p&gt;Little did i know until about five minutes ago that my comments system was a little bit dead. Clicking on the button to post a comment caused the nasty default Rails &quot;Something went wrong&quot; error message to appear. And before you say anything, i know i know, i should have tests to make sure this all works before deploying, or at least some sort of exception notification so i know when things break. I guess thats my next plan of action, to develop a little Cucumber testing suite to make sure everything works. It's not quite the BDD way of doing it but any tests are better than no tests right? Even if they do come after the site has been built. &lt;/p&gt;

&lt;p&gt;Anyway, it turned out i was using @article.id on the comment form to generate the forms url. A quick change to just @article fixed the problem and all is now working. &lt;/p&gt;

&lt;p&gt;So bring it on people, show me your commenting skills :-)&lt;/p&gt;</description>
      <pubDate>Sun, 10 Jan 2010 23:48:36 +0000</pubDate>
      <link>http://peteroome.com/articles/13-rails-form-object-id-fixed-comments-working-once-more.rss</link>
      <guid>http://peteroome.com/articles/13-rails-form-object-id-fixed-comments-working-once-more.rss</guid>
    </item>
    <item>
      <title>&quot;heroku db:pull&quot; for development environment data in Rails.</title>
      <description>&lt;p&gt;I'm going to get right to the point: the &quot;heroku db:pull&quot; command for the heroku rails gem is brilliant. Simply put, running this command will extract and download the data from your &lt;a href=&quot;http://heroku.com/&quot;&gt;Heroku&lt;/a&gt; hosted application database and import it right into your development environment database. One command, 13 characters; easy. All that was required was for me to install the &quot;&lt;a href=&quot;http://github.com/ricardochimal/taps&quot;&gt;Taps&lt;/a&gt;&quot; gem. This gem is the code that does the actual database transfer. Anyway, this little command is awesome for testing with.
&lt;/p&gt;

&lt;p&gt;Thats all for now :-)&lt;/p&gt;</description>
      <pubDate>Sun, 10 Jan 2010 21:11:39 +0000</pubDate>
      <link>http://peteroome.com/articles/12-heroku-dbpull-for-development-environment-data-in-rails.rss</link>
      <guid>http://peteroome.com/articles/12-heroku-dbpull-for-development-environment-data-in-rails.rss</guid>
    </item>
    <item>
      <title>Weird Thinking Sphinx going ons.</title>
      <description>So i had a quick request from the guys over at &lt;a href=&quot;http://thefourohfive.com&quot;&gt;The 405&lt;/a&gt; to update what could be searched on the site. A fair enough request. They have been using the site with Thinking Sphinx on for abut 4 or 5 months now without complaint which is great. 

Anyway, i went to make the change to the code and then test it but was faced with horrible error messages when trying to get the searchd running locally on my laptop (OS X Snow Leapord). I was also unable to run the rebuild or index tasks for TS (Thinking Sphinx) at all. I have just spent a couple of hours looking into this without avail. 

Unfortunately, like a proper newbie i accidentally closed my terminal screen without taking a copy of the errors i was getting. So i dont have anything for you to compare. The errros were to do with a PATH issue in the environment for cron/
passenger/etc. 

Anyway, i'll cut to the chase, although i am still unaware why my install of TS stopped working, i did find that development on the Gem has progressed considerably. As a result i did a fresh install of Sphinx and the TS gem and everything seems to be back to normal now. Indexing rake tasks are working fine, starting and stopping the searchd is working fine also. 

I just felt it was worth noting this incase anyone else was having any issues similar to those i described. </description>
      <pubDate>Sat, 09 Jan 2010 19:27:55 +0000</pubDate>
      <link>http://peteroome.com/articles/11-weird-thinking-sphinx-going-ons.rss</link>
      <guid>http://peteroome.com/articles/11-weird-thinking-sphinx-going-ons.rss</guid>
    </item>
    <item>
      <title>undefined method `crop_resized!'</title>
      <description>&lt;p&gt;I was making some updates on a old site i built a couple of years ago for a friend of mine. Unfortunately after i made the changes he was having issues uploading images; receiving a 500 error in the browser. The site uses attachment_fu for file uploads.&lt;/p&gt;

&lt;p&gt;Checking the production log revealed that the following error was occuring:&lt;/p&gt; 

&lt;p&gt;NoMethodError (undefined method `crop_resized!' for #&lt;ImageScience:0xb6fd05a0&gt;)&lt;/p&gt;

&lt;p&gt;The object being resized was an ImageScience object and not the RMagick one i was expecting. Clearly the wrong image processor was being used on the production stack. All that was required was for me to define the processor to be used within the model where the upload was taking place: &quot;:processor =&gt; 'Rmagick'&quot;.&lt;/p&gt;
 

&lt;p&gt;  has_attachment  :content_type =&gt; :image,
                  :storage =&gt; :file_system,
                  :max_size =&gt; 5.megabytes,
                  :resize_to =&gt; '680x560&gt;',
                  &lt;strong&gt;:processor =&gt; 'Rmagick',&lt;/strong&gt;
                  :thumbnails =&gt; { :thumb =&gt; 'crop: 150x122'}&lt;/p&gt;</description>
      <pubDate>Tue, 08 Dec 2009 00:52:26 +0000</pubDate>
      <link>http://peteroome.com/articles/10-undefined-method-crop_resized.rss</link>
      <guid>http://peteroome.com/articles/10-undefined-method-crop_resized.rss</guid>
    </item>
    <item>
      <title>Uninitialized constant MysqlCompat::MysqlRes</title>
      <description>&lt;p&gt;For some reason i have recently been having issues with MySql on my Snow Leopard installation. Now i've had MySql issues on OS X before and i seem to remember going round in circles for a good few hours then too. Anyway the error i was getting was: &quot;uninitialized constant MysqlCompat::MysqlRes&quot;. &lt;/p&gt;

&lt;p&gt;Basically it turns out the MySql 2.8 gem is pointing at the wrong directory for the gems library. Instead of pointing at: &quot;/usr/local/mysql/lib/libmysqlclient.15.dylib&quot; the gem was in fact pointing at: &quot;/usr/local/mysql/lib/mysql/libmysqlclient.15.dylib&quot; (notice the extra &quot;mysql&quot;. &lt;/p&gt;

&lt;p&gt;Anyway, there is a bit of a hack to symlink this if your adamant to use the latest version of the mysql gem. However i wasn't entirely comfortable with that so i decided to go with uninstalling 2.8 and installing 2.7. As it happens this has fixed the problem and everything is working as it should now. The command i used to install this version of the gem correctly was: &lt;/p&gt;

&lt;p&gt;&lt;script src=&quot;http://gist.github.com/245861.js?file=mysql_2.7_gem_install&quot;&gt;&lt;/script&gt;&lt;/p&gt;</description>
      <pubDate>Mon, 30 Nov 2009 23:12:59 +0000</pubDate>
      <link>http://peteroome.com/articles/8-uninitialized-constant-mysqlcompatmysqlres.rss</link>
      <guid>http://peteroome.com/articles/8-uninitialized-constant-mysqlcompatmysqlres.rss</guid>
    </item>
    <item>
      <title>Website index showing contents of public folder</title>
      <description>&lt;p&gt;I have just been tipped off that one of my sites wasn't loading properly. &lt;a href=&quot;http://www.myteamtweet.com&quot; title=&quot;My Team Tweet&quot;&gt;My Team Tweet&lt;/a&gt; is a site that i built at the start of this years Football/Scocer season. It's aim is to Tweet live commentary so fans can keep up with their teams progress in games each week via Twitter. The site is hosted on &lt;a href=&quot;http://www.hostingrails.com/home/3225209988&quot; title=&quot;Hostingrails&quot;&gt;Hostingrails&lt;/a&gt; and when i just visited the home page, for some strange reason it was loading the contents of the 'public' directory of the Rails app. &lt;/p&gt;

&lt;p&gt;Anyway, having had a quick scout about, i soon found out this was something that had happened to people before, as is the case with most of these situations. It turned out that the '.htaccess' file was missing from the public folder. So all that was required to get the site back up was recreating this file and redeploying the application. All seems fine now and &lt;a href=&quot;http://www.myteamtweet.com&quot; title=&quot;My Team Tweet&quot;&gt;My Team Tweet&lt;/a&gt; is back online.&lt;/p&gt;

&lt;p&gt;Unfortunately, it does appear the BBC have removed the live text feed pages that were used for this site to operate, so the site hasn't reported any commentary for a couple of weeks. Hopefully we can find another commentary source for this very soon.&lt;/p&gt;</description>
      <pubDate>Wed, 25 Nov 2009 20:44:09 +0000</pubDate>
      <link>http://peteroome.com/articles/7-website-index-showing-contents-of-public-folder.rss</link>
      <guid>http://peteroome.com/articles/7-website-index-showing-contents-of-public-folder.rss</guid>
    </item>
    <item>
      <title>Spare Google Wave Invites</title>
      <description>&lt;p&gt;Oh, just to let anyone who is interested know, i have 17 spare Google Wave invites. If you would like one, then just leave a comment and ask nicely. :-)&lt;/p&gt;

&lt;p&gt;No need to buy off &lt;a href=&quot;http://shop.ebay.co.uk/?_from=R40&amp;_trksid=p3907.m38.l1313&amp;_nkw=google+wave&amp;_sacat=See-All-Categories&quot; title=&quot;Google Wave invites on eBay&quot;&gt;eBay&lt;/a&gt;!&lt;/p&gt;</description>
      <pubDate>Tue, 17 Nov 2009 22:47:48 +0000</pubDate>
      <link>http://peteroome.com/articles/6-spare-google-wave-invites.rss</link>
      <guid>http://peteroome.com/articles/6-spare-google-wave-invites.rss</guid>
    </item>
    <item>
      <title>Monthly blog activity totals animated with jQuery UI interface components</title>
      <description>&lt;p&gt;So this evening i seem to have effortlessly (i surprise myself sometimes) added a jazzy little animation to the monthly blog activity totals at the top of the blog pages on my site.&lt;/p&gt;

&lt;p&gt;Although i am slightly undecided as to whether this is exceedingly irritating or if it is quite a nice little effect, i was very pleased with the small amount of code it required.&lt;/p&gt;

&lt;p&gt;Firstly i wanted to use the 'slide' effect which required loading in the jQuery UI library into my pages. Unfortunately this adds an extra 197kb to the page size but it was essential for this exercise (I may have to look into only loading this file on specific pages). The library though can be downloaded from &lt;a href=&quot;http://jqueryui.com/&quot; title=&quot;jQuery UI Library&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Anyway, here is the code i used for the effect:&lt;/p&gt;

&lt;p&gt;&lt;script src=&quot;http://gist.github.com/235569.js&quot;&gt;&lt;/script&gt;&lt;/p&gt;

&lt;p&gt;The top figures are determined by simply working out the percentage of posts which are created, based on the total blog posts i have written, each month. This figure is then used as the height (as a %) of the inner div to give the bar graph effect.&lt;/p&gt;

&lt;p&gt;The javascript, cycles through each of the months, hiding the inner div with the light blue background, before sliding it up to give the appearance that the bar graph is growing on each reload of the page. As the javascript cycles through each month, it gives a pleasant delayed effect from one to the next.  &lt;/p&gt;</description>
      <pubDate>Sun, 15 Nov 2009 23:42:34 +0000</pubDate>
      <link>http://peteroome.com/articles/5-monthly-blog-activity-totals-animated-with-jquery-ui-interface-components.rss</link>
      <guid>http://peteroome.com/articles/5-monthly-blog-activity-totals-animated-with-jquery-ui-interface-components.rss</guid>
    </item>
    <item>
      <title>Some Ajax jazz with jQuery: &quot;I like this&quot;.</title>
      <description>I jazzed up my &quot;I like this&quot; button a little bit today with the addition of some Ajax onto the site. I have set the link up at the bottom of every post to send a GET request to the &quot;like&quot; action in my controller, preventing the page from refreshing and from the user submitting multiple times (unless they manually refresh the page for now).

In lehmans terms, the &quot;I like this&quot; link visits the controller action to update the &quot;like_count&quot; attribute for the Article. The &quot;I like this&quot; link fades out and is then faded in with some new text, thanking the user for their vote and updating the &quot;like count&quot; at the top right of the page.

I created function in my application.js file for this.

&lt;script src=&quot;http://gist.github.com/234881.js&quot;&gt;&lt;/script&gt;</description>
      <pubDate>Sun, 15 Nov 2009 00:51:26 +0000</pubDate>
      <link>http://peteroome.com/articles/4-some-ajax-jazz-with-jquery-i-like-this.rss</link>
      <guid>http://peteroome.com/articles/4-some-ajax-jazz-with-jquery-i-like-this.rss</guid>
    </item>
    <item>
      <title>jQuery content rotator with fadeIn and fadeOut</title>
      <description>&lt;p&gt;So i have been working on more and more little bits of jQuery at work recently. From my point of view this is pretty cool because my jQuery skills aren't as good as i'd like them to be at the moment, so any experience is good experience in my eyes. Plenty of clients are requesting jazzy, polished pieces of content on home pages and also with general site functionality which means it's a pretty important skill these days.&lt;/p&gt; 

&lt;p&gt;Anyway, Friday evening i spent a few extra hours in the office working on a little piece of work that needed to rotate a static set of customer testimonials with a nice fade effect too. With a little input from our in house jQuery guru &lt;a href=&quot;http://www.twitter.com/robin_reala&quot; title=&quot;Rob on Twitter&quot;&gt;Rob&lt;/a&gt;, this is what we banged out. (Obviously you will need to make sure you have jQuery attached to your page.)&lt;/p&gt;

&lt;p&gt;The Markup:&lt;/p&gt;
&lt;script src=&quot;http://gist.github.com/194209.js&quot;&gt;&lt;/script&gt;

&lt;p&gt;The JS:&lt;/p&gt;
&lt;script src=&quot;http://gist.github.com/194216.js&quot;&gt;&lt;/script&gt;

&lt;p&gt;A simple case of traversing each of the list items in the given #quotes list, removing a class of &quot;showing&quot; from the current item and adding the same class to the next item in the list. Simples.&lt;/p&gt;</description>
      <pubDate>Sat, 26 Sep 2009 13:03:12 +0000</pubDate>
      <link>http://peteroome.com/articles/3-jquery-content-rotator-with-fadein-and-fadeout.rss</link>
      <guid>http://peteroome.com/articles/3-jquery-content-rotator-with-fadein-and-fadeout.rss</guid>
    </item>
    <item>
      <title>I'm thinking, Thinking Sphinx will do the job</title>
      <description>&lt;p&gt;I have just finished some development on a site i built for a friend: &lt;a href=&quot;http://www.theforohfive.com&quot; title=&quot;The 405&quot;&gt;The 405&lt;/a&gt;, which is pulling in 25k+ hits a month at the moment. It's been a good project which has allowed me to try out some new bits and pieces, the latest one being &lt;a href=&quot;http://freelancing-god.github.com/ts/en/&quot; title=&quot;Thinking Sphinx&quot;&gt;Thinking Sphinx (TS)&lt;/a&gt;. I've been hearing lots of praise thrown towards this Search Plugin but have never used it, until now.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&quot;Sphinx is a search engine. You feed it documents, each with a unique identifier and a bunch of text, and then you can send it search terms, and it will tell you the most relevant documents that match them. If you&#8217;re familiar with Lucene, Ferret or Solr, it&#8217;s pretty similar to those systems. You get the daemon running, your data indexed, and then using a client of some sort, start searching.&quot;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;So once i had compiled Sphinx all that was required was for me to start the search daemon and index my data.&lt;/p&gt;

&lt;p&gt;rake thinking_sphinx:start (of course &quot;stop&quot; and &quot;restart&quot; and valid commands here too)&lt;/p&gt;

&lt;p&gt;For the 405 i wanted to index the Article and Review models. These contain the most searchable data and are the obvious choices. Once i had defined what i wanted to be able to search it was simply a case of running the index rake task. The only minor gotcha here is that you need to re-index TS whenever you add a model to the index. This seems pretty obvious now, but it cost me 10 minutes of wondering why i wasn't able to search the Reviews on the website. :-)&lt;/p&gt;

&lt;p&gt;Fortunately there is a very easy method for searching all indexed methods with ThinkingSphinx too. Simply calling: ThinkingSphinx.search will do this for you.&lt;/p&gt; 

&lt;p&gt;There are numerous options for customising how the search tool works, not all of which i have delved into just yet as Sphinx works, currently, exactly as i want it to straight out the box. One nice feature i like though is the ability to add &quot;WHERE&quot; statements into the index method of your model that you are making searchable with TS.&lt;/p&gt; 

&lt;p&gt;All in all i'd highly recommend ThinkingSphinx, i have it's indexing rake task running hourly on a cron job which means the search results are very up to date without affecting the performance of the site too much.&lt;/p&gt;

&lt;script src=&quot;http://gist.github.com/189956.js&quot;&gt;&lt;/script&gt;
</description>
      <pubDate>Sun, 20 Sep 2009 22:11:53 +0000</pubDate>
      <link>http://peteroome.com/articles/2-im-thinking-thinking-sphinx-will-do-the-job.rss</link>
      <guid>http://peteroome.com/articles/2-im-thinking-thinking-sphinx-will-do-the-job.rss</guid>
    </item>
    <item>
      <title>Site launched on Heroku - Easy</title>
      <description>&lt;p&gt;So i have just launched Version 1 of my new site with the help of &lt;a href=&quot;http://heroku.com/&quot; title=&quot;Heroku&quot;&gt;Heroku&lt;/a&gt;. Deploying is made incredibly easy with their own &lt;a href=&quot;http://docs.heroku.com/heroku-command&quot; title=&quot;Getting started with Heroku&quot;&gt;Gem&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;The only issue i have recently run into is using my own &quot;Custom Domain&quot;. This is a free service (as it should be) with Heroku, but the only slight difficulties i ran to were with GoDaddy, where i purchases &lt;a href=&quot;http://peteroome.com&quot; title=&quot;Pete Roome&quot;&gt;peteroome.com&lt;/a&gt; from. Unfortunately they don't make it especially easy to edit your own DNS details. This domain was previously pointed at the Media Temple name servers, so DNS control was only allowed once these name servers had been removed. Pretty obvious i guess really. &lt;/p&gt;

&lt;p&gt;So here i am. Online, once again. The site, i know, is not going to win any design awards, but its more functional than anything else at the moment; it's purpose to serve as an outlet for the little bits of code i play with, ideas i have and sites i build. Frequent updates will be made to the site, as i begin to understand how i want to use it exactly. Ideas in the pipeline include a portfolio area and hosting this site on a self built cloud instance with Amazon. All ideas for now though, we shall see.&lt;/p&gt;

&lt;p&gt;Just for those of you wondering. This site is built with Rails. It took about a week (of evenings after work) to put together, has a repo of 2.8mb and is currently running on Heroku's free hosting plan (for the mean time).</description>
      <pubDate>Tue, 15 Sep 2009 21:06:32 +0000</pubDate>
      <link>http://peteroome.com/articles/1-site-launched-on-heroku---easy.rss</link>
      <guid>http://peteroome.com/articles/1-site-launched-on-heroku---easy.rss</guid>
    </item>
  </channel>
</rss>
