<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-US">
  <title>Web-Dev - A story of just another web developer</title>
  <updated>2013-09-01T14:46:11+03:00</updated>
  <link type="text/html" rel="alternate" href="http://hamza.khan-cheema.com"/>
  <link type="application/atom+xml" rel="self" href="http://hamza.khan-cheema.com/index.atom"/>
  <id>http://hamza.khan-cheema.com/index.atom</id>
  <entry>
    <link type="text/html" rel="alternate" href="http://hamza.khan-cheema.com/show/ruby-testing"/>
    <id>http://hamza.khan-cheema.com/show/ruby-testing</id>
    <title>My Ruby Testing Setup</title>
    <published>2013-09-01T14:46:11+03:00</published>
    <updated>2013-09-01T16:04:25+03:00</updated>
    <content type="html">&lt;p&gt;I have been through many ways of testing Ruby applications through the years.  I have recently started another phase, Integration testing.  I used Cucumber for a client I worked for, a few years ago but I never liked it much.  The main reason for this was the clients would not read the cucumber tests anyway and the joined planning of writing the scenarios is not really a reality in a large (2nd in its industry) company.  So the extra effort and time in writing Cucumber tests did not seem worth the effort.&lt;/p&gt;
&lt;p&gt;I once asked the developer who helped make all those cucmber tests(which took 30 mins to run) and helped hack pickle to do more cleaver things with relationships, does anyone outside of the tech team read the tests?  He said &amp;#8220;no, but it keeps us honest&amp;#8221;.  This kind of answer is precisely why i turned my back on Integration and full stack testing (which was an error on my part).&lt;/p&gt;
&lt;p&gt;In this post I am listing my current Ruby (Sinatra and Rails) Integration full stack setup.h2. Current setup&lt;/p&gt;
&lt;h3&gt;&lt;a href="http://rspec.info/"&gt;Rspec&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;I have always felt that Rspec is just too big and clever for a testing framework.  That is why I am in favour of using MiniTest::Spec.  But after battling with other gems that all talk about Rspec, I have gone back to using Rspec to keep things simple from a setup perspective.&lt;/p&gt;
&lt;h3&gt;&lt;a href="https://github.com/jnicklas/capybara"&gt;Capybara&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Capbara allows you to write integration tests in Ruby code.  I am using the scenario/feature way of writing tests and am finding it joy to use.  I would highly recommend using Capybara.  For a quick primer check out this  &lt;a href="http://robots.thoughtbot.com/post/33771089985/rspec-integration-tests-with-capybara"&gt;short blog post by thoughtbot&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;&lt;a href="https://github.com/jonleighton/poltergeist"&gt;Poltergeist&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;For Javascript testing I am using the Poltergeist JS driver which uses the &lt;a href="http://phantomjs.org/"&gt;PhantomJS&lt;/a&gt; engine.  This is great as it allows full headless testing which makes the setup much more easier then selenium.  It also means I do not have to have a x server on the CI server anymore.  It seems better then the &lt;a href="https://github.com/thoughtbot/capybara-webkit"&gt;capybara-webkit&lt;/a&gt; driver as you do not have to install QtWebKit.  Also I have been reading that it performs faster.&lt;/p&gt;
&lt;h3&gt;&lt;a href="https://github.com/guard/guard"&gt;Guard&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;I have been using autotest (ZenTest), as long as I can remember.  But after using Guard I will not be going back.  Just the ease of being able to configure the setup is worth it.&lt;/p&gt;
&lt;h3&gt;&lt;a href="https://github.com/sporkrb/spork"&gt;Spork&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;We all know that Rails takes ages to load so we do not want to load the Rails server each time we run our tests.  This is where spork comes into play.  I would recommend watching the excellent &lt;a href="http://railscasts.com/episodes/285-spork"&gt;RailsCast&lt;/a&gt; about setting up Spork.&lt;/p&gt;
&lt;h3&gt;&lt;a href="http://integrity.github.io/"&gt;Integrity CI Server&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;I have used Jenkins in the past and it is very impressive.  I am not surprised that it is the go-to CI server.  But the problem is that it runs on Java.  If you are running on a memory constrained VM then Java is not really your friend (I started out as Java web guy).  I just wanted something simple.  I tried a few ruby CI servers out there and settled on Integrity.  I have managed to get the post hook working with bitbucket, but still not got it to work with testing new branches automatically.&lt;/p&gt;
&lt;h3&gt;Closing thoughts&lt;/h3&gt;
&lt;p&gt;There you have it, I think it is the best Integration testing setup to date. No Cucumber in sight :)&lt;/p&gt;
&lt;p&gt;On a closing note I do not want create the impression that I am belittling  the work that has been put into Rspec/Cucumber/Pickle.  To work on open source is very difficult. I have not managed to ship version 0.1 of Sinatra Commerce, but I am still working on it :).  The amount of options for &lt;span class="caps"&gt;BDD&lt;/span&gt;/&lt;span class="caps"&gt;TDD&lt;/span&gt; within ruby is really crazy and I for one think it helps push the boundaries of successful software development.&lt;/p&gt;
&lt;p&gt;Image from: &lt;a href="http://www.flickr.com/photos/lorentey/5592629831/"&gt;lorentey&lt;/a&gt;&lt;/p&gt;</content>
    <author>
      <name>Hamza Khan-Cheema</name>
    </author>
  </entry>
  <entry>
    <link type="text/html" rel="alternate" href="http://hamza.khan-cheema.com/show/sinatracommerce"/>
    <id>http://hamza.khan-cheema.com/show/sinatracommerce</id>
    <title>Sinatra Commerce</title>
    <published>2012-10-20T20:06:08+03:00</published>
    <updated>2012-10-20T20:02:27+03:00</updated>
    <content type="html">&lt;p&gt;I am working on an open source project called &lt;a href="http://www.sinatracommerce.com"&gt;Sinatra Commerce&lt;/a&gt;  You guessed it from the name, it is a flexible modular e-commerce system built using Sinatra.&lt;/p&gt;
&lt;p&gt;In this post I share some of my thoughts on why I started it and why I didn&amp;#8217;t choose to use Rails/Spree.I have used Spree on two sites which I developed.  The first site was my own &lt;a href="http://www.glimmeringlights.com/"&gt;Glimmering Lights&lt;/a&gt; and the second was another client project.  First of let me say that I completely respect the creator of Spree and all the contributors, if you want a rails e-commerce solution, then Spree is the one to choose.  It has a proven track record.&lt;/p&gt;
&lt;p&gt;Having said that I did have a few problems with spree:&lt;/p&gt;
&lt;ol&gt;
	&lt;li&gt;It was really difficult to test your code&lt;/li&gt;
	&lt;li&gt;The over use of class_eval to do most things.&lt;/li&gt;
	&lt;li&gt;The payment gateway&amp;#8217;s were not that easy to set up&lt;/li&gt;
	&lt;li&gt;Not as fast as I think it should be (most likely due to its architecture)&lt;/li&gt;
	&lt;li&gt;There is no way of using the stock system for different web shops.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Now please take these points with a pinch of salt as I have not used Spree in a while and it may have addressed some of these issues.&lt;/p&gt;
&lt;h2&gt;What I want from an e-commerce system&lt;/h2&gt;
&lt;p&gt;The points below are some of the criteria I am using while developing Sinatra Commerce.&lt;/p&gt;
&lt;ol&gt;
	&lt;li&gt;Must be built in Ruby :)&lt;/li&gt;
	&lt;li&gt;Built using a micro-framework e-commerce platform that is minimal but flexible enough for developers to extend.&lt;/li&gt;
	&lt;li&gt;A modular system that separates &lt;b&gt;stock&lt;/b&gt;, &lt;b&gt;admin&lt;/b&gt; and the &lt;b&gt;store&lt;/b&gt; front end.  These need to be able to run independently and could be swapped out easily.&lt;/li&gt;
	&lt;li&gt;Easily testable solution.  All the modules need to be able to be put through their paces using mini-test.&lt;/li&gt;
	&lt;li&gt;The stock module has to be able to handle multiple shop front ends. This way all the stock information is in one place of a company with multiple e-commerce sites.  This also means that the stock module can be given more individual system resources irrespective of the other two modules.&lt;/li&gt;
	&lt;li&gt;Has to be easy to extend by Ruby developers&lt;/li&gt;
	&lt;li&gt;Eventually do what Datamapper does, put each module in its own gem (after the concept has been tested).&lt;/li&gt;
	&lt;li&gt;Not to use class_eval :)&lt;/li&gt;
	&lt;li&gt;The Stock system needs to be able to be accessed via a Restful &lt;span class="caps"&gt;API&lt;/span&gt;. This &lt;span class="caps"&gt;API&lt;/span&gt; is the only way the other modules can communicate with it.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;Why use Sinatra?&lt;/h2&gt;
&lt;p&gt;I have not been happy with Rails for a while now.  I feel that it has become far too bloated for what it needs to be.  It reminds me of Firefox when it started out and what it is now.  This is just a progression with popular software I guess.  I worked on a project using Rails for a large firm and the performance bottlenecks were a real headache for me.  After that project I stared looking into Ruby alternatives, of course I tried Sinatra, but I also spent some time looking at &lt;a href="https://github.com/Ramaze/innate"&gt;Innate&lt;/a&gt;.  Innate is the core of the &lt;a href="https://github.com/Ramaze/ramaze"&gt;Rameze framework&lt;/a&gt; .  The only thing it relies on is Rack!  This simplicity really appealed to me and is very hard to argue with.  I then went about developing this blog with Innate and I have also developed a classifieds site using Innate.  The performance is amazing (with my limited testing).  I thought about using Innate to develop an e-commerce platform, but I decided against it as it would be another hurdle for developers to cross.  Although Sinatra is not as quick as Innate, it is fast enough for what I wanted to achieve.&lt;/p&gt;
&lt;h2&gt;Progress so far &amp;#8230;&lt;/h2&gt;
&lt;p&gt;I have got pretty far with development.  I have built the stock, admin and started on the shop module.  The stock module uses a Restful &lt;span class="caps"&gt;API&lt;/span&gt; which the other modules call to get details about products, categories etc.  I know what you are thinking, you are thinking that we now need to make two requests instead of one.  This is of course true and with this modular setup is unavoidable.  However in production I was thinking that there would be a cache layer behind the &lt;span class="caps"&gt;API&lt;/span&gt;, memcached or Redis which returns the information it needs.  The data would expire when a edit/delete request comes through the simple &lt;span class="caps"&gt;API&lt;/span&gt;.  This modular system makes it super easy to scale the stock layer using a simple caching solution.  I am also playing around with security solutions for the &lt;span class="caps"&gt;API&lt;/span&gt; and have currently settled on the stock system only being available to local requests, this way we do not have to authenticate any requests coming into the &lt;span class="caps"&gt;API&lt;/span&gt;. As in the stock module should never be accessible from the outside.  Any thoughts on this would be appreciated, but I figured the time spent not authenticating the &lt;span class="caps"&gt;API&lt;/span&gt; call is invaluable.  I am also thinking about a hybrid solution that authenticates on all &lt;span class="caps"&gt;API&lt;/span&gt; requests apart from get.&lt;/p&gt;
&lt;p&gt;I am about 3-4 weeks away from a version 0.0.1 and my aim is to get it out the door with a sample shop module without the payment gateways working.  Version 0.0.2 will have paypal integration (as this is what I need at the moment).  This will most likely also be a module (and eventually a gem).&lt;/p&gt;
&lt;p&gt;On another note I have started using my twitter account &lt;a href="http://twitter.com/hamzakc"&gt;@hamzakc&lt;/a&gt; so feel free to follow me for updates to Sinatra Commerce.&lt;/p&gt;
&lt;p&gt;I would love to hear peoples thoughts on what I am trying to achieve with Sinatra Commerce.&lt;/p&gt;
&lt;p&gt;Thanks&lt;br /&gt;
Hamza&lt;/p&gt;</content>
    <author>
      <name>Hamza Khan-Cheema</name>
    </author>
  </entry>
  <entry>
    <link type="text/html" rel="alternate" href="http://hamza.khan-cheema.com/show/responsive-web-design"/>
    <id>http://hamza.khan-cheema.com/show/responsive-web-design</id>
    <title>Responsive Web Design</title>
    <published>2012-10-19T18:52:03+03:00</published>
    <updated>2012-10-19T21:04:57+03:00</updated>
    <content type="html">&lt;p&gt;I have finally read up on responsive web design from the excellent short book by Ethan Marcotte, &lt;a href="http://www.abookapart.com/products/responsive-web-design"&gt;Responsive Web Design&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Here are some thoughts on the book and the whole responsive design movement.h3. Fluid Layouts v2&lt;/p&gt;
&lt;p&gt;Initially when I read about response web design, I thought it was just the whole fluid layout argument again.  I had looked into fluid layouts in the past but always stuck to fixed pixel layouts.  Mainly as I found it easier to code the &lt;span class="caps"&gt;CSS&lt;/span&gt; (I am a little lazy :).&lt;/p&gt;
&lt;p&gt;However I have just bought a kindle and I wanted a few books to read on it. I went to &lt;a href="http://www.abookapart.com"&gt;A Book Apart&lt;/a&gt; and bought a few books that looked interesting.  I had previously seen the responsive design book, but as I didn&amp;#8217;t have a device to read it on, I didn&amp;#8217;t buy it.  I hate reading e-books on a monitor.  E-Ink is far more pleasurable to read.&lt;/p&gt;
&lt;p&gt;The book is short and is split up into 5 easy to follow chapters.  It starts out introducing the concept of responsive design and then talks about a fluid grid, then onto flexible images (&lt;a href="http://www.alistapart.com/articles/fluid-images/"&gt;read an excerpt here&lt;/a&gt; ).  After that, media queries and finally concluding with real world solutions to problems with responsive design.&lt;/p&gt;
&lt;h3&gt;Boston Globe&lt;/h3&gt;
&lt;p&gt;Although Ethan does not mention the site by name, he has worked on &lt;a href="http://www.bostonglobe.com"&gt;The Boston Globe&lt;/a&gt; website to make it responsive.  If you play around with your browser window width (or view it via your phone or tablet) you will see that it is an excellent example of responsive design on a content heavy site.  This site really lead me to purchase the book, it impressed me that much!  I have worked on content heavy sites in the past and I have a lot of admiration for the overall design of the site alongside the thought put behind the smaller screen designs.&lt;/p&gt;
&lt;h3&gt;Every design?&lt;/h3&gt;
&lt;p&gt;I am not saying that every application should be responsive and neither is Ethan.  For example 37signals have a &lt;a href="http://37signals.com/svn/posts/3269-behind-the-speed-basecamp-mobile"&gt;post&lt;/a&gt; stating how they have mobile specific templates for pages in the new basecamp as the amount of javascript they use is not feasible for a mobile browser. I&amp;#8217;d agree with this approach but we do need to take it with a pinch of salt. A lot of people browse from their home on tablets which would be considered mobile.  Some of the new tablets are very capable machines with multiple cores. So this argument is not as black and white as 37signals have stated. Just some food for thought.&lt;/p&gt;
&lt;h3&gt;Mobile first&lt;/h3&gt;
&lt;p&gt;I have read about this technique before, but it never really clicked with me.  However reading it in this book (chapter 5) it did seem to make a lot of sense.&lt;/p&gt;
&lt;p&gt;As some of you might know I love &lt;a href="http://hamza.khan-cheema.com/show/water-jug-theory-ui"&gt;minimal design and UI&lt;/a&gt; so the step to designing mobile first was an easy one.&lt;/p&gt;
&lt;p&gt;For those who do not know, mobile first is designing for the smallest screen real estate first and then working your way up to a fully featured desktop client.  This technique forces you to to think about what is necessary in the design and what is a nice to have.  That way the user only gets the important stuff.&lt;/p&gt;
&lt;p&gt;I am currently working on a personal project (one of many :) and I had a fixed width design that I ditched and started with the mobile first strategy.  I am loving the design constraints this has brought about.  It is forcing me to think real hard about the UI.  It is also challenging my preconceived ideas of where certain UI should be placed, (like navigation for example).&lt;/p&gt;
&lt;p&gt;In conclusion, I would highly recommend purchasing &lt;a href="http://www.abookapart.com/products/responsive-web-design"&gt;Responsive Web Design&lt;/a&gt; and trying to think about how you can apply its principles to your day to day design.&lt;/p&gt;
&lt;p&gt;Please let me know your thoughts.&lt;/p&gt;
&lt;p&gt;Thanks.&lt;br /&gt;
Hamza&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.flickr.com/photos/adactio/5818096043/"&gt;Image taken from adactio&lt;/a&gt;&lt;/p&gt;</content>
    <author>
      <name>Hamza Khan-Cheema</name>
    </author>
  </entry>
  <entry>
    <link type="text/html" rel="alternate" href="http://hamza.khan-cheema.com/show/water-jug-theory-ui"/>
    <id>http://hamza.khan-cheema.com/show/water-jug-theory-ui</id>
    <title>Water Jug Theory and Usability</title>
    <published>2011-10-09T09:53:22+03:00</published>
    <updated>2011-10-09T10:27:46+03:00</updated>
    <content type="html">&lt;p&gt;I am currently in the Middle East and needless to say it is very hot here.  The temperature hovers from 37 to 45+ Celsius.  So as you can imagine the AC&#8217;s are on all day and you tend to want to drink a lot of water.  A funny thing happened to me, as I was about to start dinner at a friends house. He had a nice jug of water on the table, glasses and some appetizers.  The main food was a bit delayed so after the starters were finished the jug of water was left.  By then I had already had one glass of water but as there was nothing else on the table apart from the water and it was in front of me in an easy to pour jug, I kept on drinking it, until I nearly finished it.&lt;/p&gt;
&lt;p&gt;This got me thinking, I have water at home but never this much, why was it that I drank more on this occasion (under the same circumstances).  The simple and obvious truth is that it was the only thing available and in an easy to pour jug.  If the water had been in a big 6 litre bottle that was difficult to pour, I would definitely not have had as much as I did. This is all well and good, but why am I writing about it?&lt;/p&gt;
&lt;p&gt;Well I am no usability expert but I do like to try and design clean interfaces for the web apps I make.  So from my experience with a jug of water I can take the following lessons as regards to designing interfaces.&lt;/p&gt;
&lt;ol&gt;
	&lt;li&gt;Remove all distractions from the user, focus on one aspect at a time (in my case I only had water, so I kept on drinking it).  If the user can only do one thing, more then likely they will do that.  An example of this is if I am reading an article I clicked on, show me the article in a distraction free way.  No related articles no recommendations just the text.&lt;/li&gt;
	&lt;li&gt;Make the design overly accessible (Big links, no small text, obvious copy).   As the water jug was easy to pour I kept on pouring it. This could also translate to , &amp;#8216;not making the user think&amp;#8217;.  By using defined defaults, blue links, links underlined etc.  Although related to point 1, this could also include removing the navigation and allowing them to navigate to only one page and including context relevant links.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;This might sound obvious and silly to many but I just thought it was interesting, so I wanted to blog about it.  I am calling it the &#8220;Water Jug Theory&#8221; :)&lt;/p&gt;
&lt;p&gt;As a side point I have redesigned this site to reflect the Water Jug Theory.   I will keep that post for another time though.  I will cover the design decisions I made and the inspiration I took for it and how that translated to the Ruby web framework I used (no, not Rails 3).  I also plan on making the simple blog engine open source, so stay tuned.&lt;/p&gt;
&lt;p&gt;Hamza&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.flickr.com/photos/jenny-pics/3617215730/"&gt;Image from Jenny Downing&lt;/a&gt;&lt;/p&gt;</content>
    <author>
      <name>Hamza Khan-Cheema</name>
    </author>
  </entry>
  <entry>
    <link type="text/html" rel="alternate" href="http://hamza.khan-cheema.com/show/36-glimmeringlights"/>
    <id>http://hamza.khan-cheema.com/show/36-glimmeringlights</id>
    <title>Glimmering Lights Launched</title>
    <published>2010-11-21T00:00:00+03:00</published>
    <updated>2011-09-30T14:57:05+03:00</updated>
    <content type="html">&lt;p&gt;&lt;img src="http://hamza.khan-cheema.com/images/glimmeringlights_product.jpg" alt="" /&gt;&lt;/p&gt;
&lt;p&gt;Just a quick note to say that we have launched &lt;a href="http://www.glimmeringlights.com"&gt;www.glimmeringlights.com&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Glimmering Lights is a joint business endeavour to bring the beauty of hand made high quality lighting from around the world to the UK market.&lt;br clear ="all"/&gt;
&lt;/p&gt;
&lt;h2&gt;Background Story&lt;/h2&gt;
&lt;p&gt;Travelling around the grand bazaar in Istanbul or around the very impressive Marrakech Souk you will come across very high quality and hand made products.  These products are still made in the old traditional ways.&lt;/p&gt;
&lt;p&gt;We were very impressed with the lighting from these markets.  Multiple colours and designs all in different sizes.&lt;/p&gt;
&lt;p&gt;After purchasing some of these lights we returned back to the UK and everyone who saw them loved them and wanted to know where they could purchase them.  With all this attention we both decided that it might be a good idea to test a niche market and start selling these lights online.  Little did we know the massive amount of work entailed in importing these lights and selling them in the UK.  Making the e-commerce website was the easy part!&lt;/p&gt;
&lt;h2&gt;Products&lt;/h2&gt;
&lt;p&gt;We decided to focus on products from Turkey and Morocco to begin with.  The lights from Turkey are from the old Ottoman times, you will find variations of them in most of the old Ottoman buildings around Istanbul.  But these are obviously to a massive scale.&lt;/p&gt;
&lt;p&gt;The lights from Morocco are completely different.  For example the Turkish pendents are made from glass while the Moroccan ones are made from a very light metal.  We really like the Henna lamps from Morocco.  They are free standing lamps that have a metal base with canvas surrounding it with hand painted henna designs.  This means that one lamp is never the exact same design.&lt;/p&gt;
&lt;h2&gt;Technology&lt;/h2&gt;
&lt;p&gt;Of course we used Ruby on Rails to build this site based on the excellent open source e-commerce application; &lt;a href="http://www.spreecommerce.com"&gt;Spree&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Although I did have a few interesting bugs upgrading from versions I would highly recommend using it.&lt;/p&gt;
&lt;p&gt;For payment we are currently using Paypal express.  We are in the process of getting a merchant account so we can process the payments directly.  Unfortunately we can only ship to the UK due to the fragile nature of the lights.&lt;/p&gt;
&lt;p&gt;I know this is not on topic of this blog, but I thought I would share some of the background story of Glimmering Lights.&lt;/p&gt;
&lt;p&gt;I would love to hear your comments on our product range.&lt;/p&gt;
&lt;p&gt;Stay tuned for lights from Indonesia.&lt;/p&gt;</content>
    <author>
      <name>Hamza Khan-Cheema</name>
    </author>
  </entry>
  <entry>
    <link type="text/html" rel="alternate" href="http://hamza.khan-cheema.com/show/35-rake-command-line-rails"/>
    <id>http://hamza.khan-cheema.com/show/35-rake-command-line-rails</id>
    <title>Rake and command line arguments with Rails</title>
    <published>2010-09-18T00:00:00+03:00</published>
    <updated>2011-09-30T14:57:30+03:00</updated>
    <content type="html">&lt;p&gt;&lt;img src="http://hamza.khan-cheema.com/images/rake.jpg" alt="" /&gt;&lt;/p&gt;
&lt;p&gt;I needed to make a Rake task in Rails to take a command line argument alongside the Rails environment.&lt;/p&gt;
&lt;p&gt;It is not that obvious, so I thought I would post a simple example.&lt;br clear ="all"/&gt;
&lt;/p&gt;
&lt;h2&gt;Rake Task&lt;/h2&gt;
&lt;pre class="ruby"&gt;&lt;code class="ruby"&gt;desc "Task description"
task :task_name, [:arg_name] =&amp;gt; :environment do |t , args|
  puts "#{args.arg_name}"
end&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here&amp;#8217;s how it is called:&lt;/p&gt;
&lt;pre class="ruby"&gt;&lt;code class="ruby"&gt;rake task_name[arg_name]&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It will also read in the RAILS_ENV environment.&lt;/p&gt;
&lt;p&gt;I know it is not the best syntax, but that is how it is currently implemented in Rake.&lt;/p&gt;
&lt;p&gt;Picture taken from &lt;a href="http://www.flickr.com/photos/28481088@N00/3294454259/"&gt;tanakawho&lt;/a&gt;&lt;/p&gt;</content>
    <author>
      <name>Hamza Khan-Cheema</name>
    </author>
  </entry>
  <entry>
    <link type="text/html" rel="alternate" href="http://hamza.khan-cheema.com/show/34-Generate-a-Barcode-in-Ruby-with-Barby-and-a-small-extension"/>
    <id>http://hamza.khan-cheema.com/show/34-Generate-a-Barcode-in-Ruby-with-Barby-and-a-small-extension</id>
    <title>Generate a Barcode in Ruby with Barby and a small extension</title>
    <published>2010-03-22T00:00:00+03:00</published>
    <updated>2011-09-30T15:39:22+03:00</updated>
    <content type="html">&lt;p&gt;&lt;img src="http://hamza.khan-cheema.com/images/barcode_2.png" alt="" /&gt;&lt;/p&gt;
&lt;p&gt;For an inventory application I am currently developing, I needed a way to generate a barcode for products that were input into the system.&lt;/p&gt;
&lt;p&gt;Fortunately &lt;a href="http://tore.darell.no"&gt;Tore Darell&lt;/a&gt; has developed a super simple barcode library named &lt;a href="http://toretore.github.com/barby/"&gt;Barby&lt;/a&gt; &lt;a href="http://toretore.github.com/barby/"&gt;Barby&lt;/a&gt;  generated the barcodes perfectly.  I choose to use the RMagick outputter, as I already had that set up on my system.&lt;/p&gt;
&lt;h2&gt;Simple Example using the RMagick Outputter&lt;/h2&gt;
&lt;pre class="ruby"&gt;&lt;code class="ruby"&gt;require 'rubygems'
require 'barby'
require 'barby/outputter/rmagick_outputter'&lt;/code&gt;

&lt;code class="ruby"&gt;barcode = Barby::Code128B.new('Barcode Code Here')
File.open('code128B.png', 'w'){|f|
  f.write barcode.to_png
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Produces&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://hamza.khan-cheema.com/images/code128B_1.png" alt="" /&gt;&lt;/p&gt;
&lt;p&gt;See the &lt;a href="http://barby.rubyforge.org/rdoc/"&gt;Barby documentation&lt;/a&gt; for the different barcodes that are currently supported.  The above example uses 128 with type B. (I don&amp;#8217;t really understand all the different types of barcodes yet).&lt;/p&gt;
&lt;p&gt;&lt;br clear="all"/&gt;&lt;/p&gt;
&lt;h2&gt;Extension&lt;/h2&gt;
&lt;p&gt;The above image is fine, but I needed to also output the code that was input underneath the barcode.  The reason for this is so a human can recognise the codes without getting the barcode scanner out.&lt;/p&gt;
&lt;p&gt;So I wrote this very quick extension to the Rmagic Outputter.  It basically uses Rmagic to extend the canvas by 10 px in height and outputs the code at the bottom&lt;/p&gt;
&lt;p&gt;Here is the extension with example usage at the bottom:&lt;/p&gt;
&lt;pre class="ruby"&gt;&lt;code class="ruby"&gt;
require 'rubygems'
require 'barby'
require 'barby/outputter/rmagick_outputter'&lt;/code&gt;

&lt;code class="ruby"&gt;module Barby
  class CustomRmagickOutputter &amp;lt; RmagickOutputter
    register :to_image_with_data
    def to_image_with_data
      #Make canvas  bigger
      canvas = Magick::ImageList.new
      canvas.new_image(full_width , full_height + 10)
      canvas &amp;lt;&amp;lt; to_image
      canvas = canvas.flatten_images
      #Make the text
      text = Magick::Draw.new
      text.font_family = 'helvetica'
      text.pointsize = 14
      text.gravity = Magick::SouthGravity
      text.annotate(canvas , 0,0,0,0, barcode.data)
      canvas
    end
  end
end&lt;/code&gt;

&lt;code class="ruby"&gt;barcode = Barby::Code128B.new('Barcode Code Here')
barcode.to_image_with_data.write('barcode_2.png')&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;This outputs&lt;/strong&gt;:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://hamza.khan-cheema.com/images/barcode_2.png" alt="" /&gt;&lt;/p&gt;
&lt;p&gt;As you can see the code is on the bottom which is what I needed.  I hope this has helped someone. &lt;strong&gt;I would love to hear your comments&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;You might also have noticed I have removed all the spam comments and am now using &lt;a href="http://disqus.net"&gt;Disqus&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Hamza&lt;/p&gt;
&lt;p&gt;&lt;br clear="all"/&gt;&lt;/p&gt;</content>
    <author>
      <name>Hamza Khan-Cheema</name>
    </author>
  </entry>
  <entry>
    <link type="text/html" rel="alternate" href="http://hamza.khan-cheema.com/show/29-local-assets-dead-simple-blog"/>
    <id>http://hamza.khan-cheema.com/show/29-local-assets-dead-simple-blog</id>
    <title>Local Assets - Dead Simple Blog</title>
    <published>2009-04-04T00:00:00+03:00</published>
    <updated>2011-09-07T00:51:31+03:00</updated>
    <content type="html">&lt;p&gt;&lt;img src="http://hamza.khan-cheema.com/images/flickr_logo.jpg" alt="" /&gt;&lt;br /&gt;
I am still in the process of making my simple blog engine opensource.  I just need to sort out some fundamental issues.  One of these issues is how to address the storage of external assets, mainly images.While I was working at openDemocracy and developing the new version of the site, we took the decision to move all images to our pro &lt;a href="http://www.flickr.com/"&gt;flickr&lt;/a&gt; account.  We used the automated thumbnail system to display the image on the homepage and then to display the bigger image in the actual article.&lt;/p&gt;
&lt;p&gt;Together with caching this process worked very well and saved on bandwidth and hard drive space.  We did not have to thumbnail the images manually, we did not have to upload the images while publishing articles.  All we needed was the flickr image ID and the system would automatically look up the image. All the image managment and orginisation was managed by flickr&amp;#8217;s excellent interface.&lt;/p&gt;
&lt;p&gt;While developing this current blog engine I am thinking that I will use a similar technique to manage external assets.  If this is done the blog interface can be quite minimal.  After all I am trying to go for a no thrills simple blog engine.  &lt;a href="http://www.mephistoblog.com/"&gt;Mephisto&lt;/a&gt; handled assets in a nice way.  But what if they did not have to?  I am sure the interface would be less cluttered.&lt;/p&gt;
&lt;p&gt;In my effort to make things minimal, I do not want to remove functionality which people have come to expect from any blogging platform.  Pushing things to external services seems like a good option to me.  I am also looking into using an external service for managing comments and discussions. That will allow me to remove all of the comment functionality from my code.&lt;/p&gt;
&lt;p&gt;I am going to try and take this as far as I can, just because I want to see where it gets and what kind of minimal but functional interface can be built.&lt;/p&gt;
&lt;p&gt;Any thoughts?&lt;/p&gt;</content>
    <author>
      <name>Hamza Khan-Cheema</name>
    </author>
  </entry>
  <entry>
    <link type="text/html" rel="alternate" href="http://hamza.khan-cheema.com/show/32-git-linux-group-access"/>
    <id>http://hamza.khan-cheema.com/show/32-git-linux-group-access</id>
    <title>Git and Linux group access</title>
    <published>2009-02-20T00:00:00+03:00</published>
    <updated>2011-09-07T00:52:01+03:00</updated>
    <content type="html">&lt;p&gt;&lt;img src="http://hamza.khan-cheema.com/images/no-tresspass.jpg" alt="" /&gt; For a recent project I had to setup a remote Git repository that was going to be used by multiple contributors.  I had a few issues with permissions that I had to work thorough, so I thought I would make a note of them in case anyone else has similar issues.&lt;/p&gt;
&lt;p&gt;I first created a new Linux user for the project  and then created a bare Git repository by following &lt;a href="http://paulbarry.com/articles/2008/12/29/quick-and-dirty-git-repository"&gt;these instructions&lt;/a&gt; in the new users home directory.  For examples sake lets say that the new git repository is owned by the &lt;strong&gt;work&lt;/strong&gt; user with the &lt;strong&gt;work&lt;/strong&gt; group.&lt;/p&gt;
&lt;p&gt;I then created new user accounts for each of the developers.  This would allow them to have ssh access to the box and commit to the repository.&lt;/p&gt;
&lt;p&gt;I then added each new user to the &lt;strong&gt;work&lt;/strong&gt; group by using the following command:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;usermod -G [group_name] [user_name]&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;So I thought that was that, but then I came across a few problems and found out that I also needed to change the default group of the new developer accounts I created.  This would enable the user to maintain the correct group ownership when they change the repository (through git pull for example). In our example it will make/update files with the group &lt;strong&gt;work&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;To do this I did:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;newgrp [group_name]&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;To verify the default user group just type in this command whilst logged in as the user.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;id&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The first &lt;strong&gt;gid&lt;/strong&gt; should be set to the new group. Or you could just create a file and have a look at the group ownership.&lt;/p&gt;
&lt;p&gt;I also found out that I need to add the following line into my &lt;strong&gt;config&lt;/strong&gt; file under my remote git repository&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;sharedrepository = 1&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It all seems to be working correctly. Multiple people can commit to the repository and they can do git pulls on the server maintaining correct group permissions.&lt;/p&gt;
&lt;h2&gt;References:&lt;/h2&gt;
&lt;ul&gt;
	&lt;li&gt;&lt;a href="http://www.cyberciti.biz/faq/unix-add-user-to-group/"&gt;How To: &lt;span class="caps"&gt;UNIX&lt;/span&gt; Add A User To A Group&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;&lt;a href="http://articles.techrepublic.com.com/5100-22_11-5349294.html"&gt;Tech Tip: Manage user groups in Linux&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;small&gt;&lt;br /&gt;
Image from : &lt;a href="http://www.flickr.com/photos/silversprite/2636812931/"&gt;silversprite&lt;/a&gt;&lt;br /&gt;
&lt;/small&gt;&lt;/p&gt;</content>
    <author>
      <name>Hamza Khan-Cheema</name>
    </author>
  </entry>
  <entry>
    <link type="text/html" rel="alternate" href="http://hamza.khan-cheema.com/show/28-rspec-rjs-redirect"/>
    <id>http://hamza.khan-cheema.com/show/28-rspec-rjs-redirect</id>
    <title>RSpec - RJS redirect (page.redirect_to)</title>
    <published>2009-01-26T00:00:00+03:00</published>
    <updated>2011-09-07T00:52:26+03:00</updated>
    <content type="html">&lt;p&gt;&lt;img src="http://hamza.khan-cheema.com/images/diversion.jpg" alt="" /&gt;&lt;/p&gt;
&lt;p&gt;Recently I wanted to use RSpec to test if a javascript request to my controller was being redirect to the correct place.  I was using &lt;em&gt;page.redirect&lt;/em&gt; like so:&lt;/p&gt;
&lt;p&gt;&lt;br clear="all"/&gt;&lt;/p&gt;
&lt;pre class="ruby"&gt;&lt;code class="ruby"&gt;render :update do |page|
    page.redirect_to edit_my_account_cropping_url(resource.id)
end&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I could not just use the standard &lt;i&gt;response.should redirect  to()&lt;/i&gt; because the response was actually rendering html that was outputting a javascript redirect.&lt;/p&gt;
&lt;p&gt;In the end it turned out that it was quite simple.  Here is the code:&lt;/p&gt;
&lt;pre class="ruby"&gt;&lt;code class="ruby"&gt;it "should redirect to cropping controller" do
    do_put # (not shown)
    response.body.should =~ /#{my_account_cropping_url(@traveller)}/
end&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Basically the &lt;strong&gt;do_put&lt;/strong&gt; is a method call that I have defined which issues a &lt;i&gt;put&lt;/i&gt; request.  The &lt;em&gt;response&lt;/em&gt; has a body element that issues a javascript redirect.  We then check to see if the expected url is included in the body.  If it is we can assume that the redirect is working.&lt;/p&gt;
&lt;p&gt;Let me know if there is a better way of doing this.  I don&amp;#8217;t have any issues with the above implementation though.&lt;/p&gt;
&lt;p&gt;Picture taken from &lt;a href="http://www.flickr.com/photos/getdown/2107792115/"&gt;getdown&lt;/a&gt;&lt;/p&gt;</content>
    <author>
      <name>Hamza Khan-Cheema</name>
    </author>
  </entry>
  <entry>
    <link type="text/html" rel="alternate" href="http://hamza.khan-cheema.com/show/26-linode-rails"/>
    <id>http://hamza.khan-cheema.com/show/26-linode-rails</id>
    <title>Linode Ruby on Rails Setup Script</title>
    <published>2008-12-31T00:00:00+03:00</published>
    <updated>2011-09-07T00:53:01+03:00</updated>
    <content type="html">&lt;p&gt;&lt;a href="http://www.linode.com/?r=cbb442225d119fe4ef6ddf4128084a34e0604e1b"&gt;&lt;img src="http://hamza.khan-cheema.com/images/linode_logo.png" alt="" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;As I stated in my &lt;a href="http://hamza.khan-cheema.com/posts/25-new-site"&gt;previous post&lt;/a&gt; I have just launched the redesign/redevelopment of my site.&lt;/p&gt;
&lt;p&gt;Along with this change I am also using a new Virtual Machine Host called &lt;a href="http://www.linode.com/?r=cbb442225d119fe4ef6ddf4128084a34e0604e1b"&gt;Linode&lt;/a&gt; I am sure you know of them from &lt;a href="http://railsrumble.com"&gt;Rails Rumble&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I have to say that I am very impressed with them so far.  I have been on a lot of &lt;span class="caps"&gt;VPS&lt;/span&gt; solutions and this is one of the fastest I have used and above all the price can&amp;#8217;t be beaten!&lt;/p&gt;
&lt;p&gt;However before I deployed the new site, I had to install Ruby on Rails and all that goes along with it.&lt;/p&gt;
&lt;p&gt;I made a shell script that automated the entire set up process including installing Passenger and the required libraries.&lt;/p&gt;
&lt;p&gt;To start off, I opted to install Ubuntu 8.10 as my operating system of choice using the nifty interface provided by Linode.&lt;/p&gt;
&lt;p&gt;After that I went about setting up the box, doing a bunch of apt-gets and a few wgets.  So I thought that I would put all this set up into a bash shell script, just in case I had to do it again in the future or that it might help anyone else who needed a RoR quick set up.&lt;/p&gt;
&lt;p&gt;So I went about looking at my history file and making the script.  I then deleted my blank and configured vps and restored a brand new copy of Ubuntu to test if it actually worked so I could post it here with a certain degree of confidence.&lt;/p&gt;
&lt;p&gt;So this is what the script installs:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;Ruby Gems&lt;/li&gt;
	&lt;li&gt;Ruby&lt;/li&gt;
	&lt;li&gt;Ruby on Rails (with version switch)&lt;/li&gt;
	&lt;li&gt;Apache2&lt;/li&gt;
	&lt;li&gt;Passenger  (including the passenger module)&lt;/li&gt;
	&lt;li&gt;Mysql 5&lt;/li&gt;
	&lt;li&gt;RedCloth&lt;/li&gt;
	&lt;li&gt;Vim&lt;/li&gt;
	&lt;li&gt;Git&lt;/li&gt;
	&lt;li&gt;haml (Because all your apps should be using this kick ass template language)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;It also installs a few dependency libraries so all the above apps install.&lt;/p&gt;
&lt;p&gt;All you have to do now is upload you app, and add a virtual host and away you go.&lt;/p&gt;
&lt;h2&gt;Passenger&lt;/h2&gt;
&lt;p&gt;I did have a few issues with passenger.  For some silly reason I uploaded my app as root and tried to start Passenger.  Passenger does not like this (rightfully so).  If it detects that &lt;i&gt;environment.rb&lt;/i&gt; is owned by root it &lt;a href="http://www.modrails.com/documentation/Users%20guide.html#user_switching"&gt;bails&lt;/a&gt;  So make sure that your app is not owned by root.&lt;/p&gt;
&lt;p&gt;So all this talk and no link?&lt;/p&gt;
&lt;p&gt;Here is the file&lt;/p&gt;
&lt;p&gt;&lt;a href="/rails_linode.txt"&gt;rails_linode.txt&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;You wil notice that I have a few variables at the top.  This is if you want to change the version of Ruby Gems or Rails.  I am using the 2.1 branch, so the script sets the version to that.  Pretty easy to change.&lt;/p&gt;
&lt;p&gt;Let me know if anyone has any problems or improvements.&lt;/p&gt;
&lt;p&gt;Hamza&lt;/p&gt;</content>
    <author>
      <name>Hamza Khan-Cheema</name>
    </author>
  </entry>
  <entry>
    <link type="text/html" rel="alternate" href="http://hamza.khan-cheema.com/show/25-new-site"/>
    <id>http://hamza.khan-cheema.com/show/25-new-site</id>
    <title>New Site Launched</title>
    <published>2008-12-28T00:00:00+03:00</published>
    <updated>2011-09-07T00:55:09+03:00</updated>
    <content type="html">&lt;p&gt;&lt;img src="http://hamza.khan-cheema.com/images/new-site.jpg" alt="" /&gt;&lt;/p&gt;
&lt;p&gt;It has been along time since I have posted anything to this blog. Life has been hectic lately.&lt;/p&gt;
&lt;p&gt;In my spare time I have been working on the new design for this site (using &lt;a href="http://960.gs"&gt;grid960&lt;/a&gt; , which I highly recommend) and rolling my own simple blog system (using Rails 2) which I deployed today.&lt;/p&gt;
&lt;p&gt;I am also pushing myself a bit more as a freelance Ruby on Rails developer, so if anyone is interested just &lt;a href="/portfolio"&gt;let me know&lt;/a&gt; .&lt;/p&gt;
&lt;p&gt;I wanted something a bit simpler then &lt;a href="http://mephistoblog.com/"&gt;Mephisto&lt;/a&gt; . I have great respect for the platform and it does a good job.  But I feel that the code is quite complex.  I also feel that some of the stuff is unnecessary in the admin interface.  For example if I want to change the theme, I don&amp;#8217;t want to change it using the admin pages, I want to change the file by hand.  I also do not want to use Liquid as the templating language (I know you can change that though). I also do not want to have the options to set posts to use Textile or Markdown or plain html.  I feel that it should not give these options, just make a &lt;a href="http://gettingreal.37signals.com/ch04_Make_Opinionated_Software.php"&gt;decision and stick with it&lt;/a&gt; . I also have a few more problems with it, but I don&amp;#8217;t want to take away from the great job it is currently doing.&lt;/p&gt;
&lt;p&gt;So I made a back to basics blog system (it seems to be all the rage now) called &lt;b&gt;dead-simple-blog&lt;/b&gt; for people who know there way around a rails app.  I have tried to keep the code and features as light as possible.  That way anyone can change the code as they see fit.&lt;/p&gt;
&lt;p&gt;I will be realising it soon (2-3 weeks) on github, if anyone is interested.  I just need to sort out a few things first, and test it in the wild.&lt;/p&gt;
&lt;p&gt;Hopefully this will lead to more blogging in the future.  I sure hope so!&lt;/p&gt;
&lt;p&gt;Hamza&lt;/p&gt;</content>
    <author>
      <name>Hamza Khan-Cheema</name>
    </author>
  </entry>
  <entry>
    <link type="text/html" rel="alternate" href="http://hamza.khan-cheema.com/show/24-Attach-Files-Using-Paperclip-"/>
    <id>http://hamza.khan-cheema.com/show/24-Attach-Files-Using-Paperclip-</id>
    <title>Attach Files Using Paperclip </title>
    <published>2008-05-05T00:00:00+03:00</published>
    <updated>2011-09-16T22:18:29+03:00</updated>
    <content type="html">&lt;p&gt;&lt;img src="http://hamza.khan-cheema.com/images/paperclip.jpg" alt="" /&gt;&lt;/p&gt;
&lt;p&gt;I have used a number of plugins to attach files to applications with Rails.  These include file_upload (remember that) , acts_as_attachment and attachment_fu.&lt;/p&gt;
&lt;p&gt;I came across a plugin called &lt;a href="http://www.thoughtbot.com/projects/paperclip"&gt;Paperclip&lt;/a&gt; a few months ago.  I have recently had the opportunity to use it on a project I am working on.  I have to say that I am very impressed so far, and if any of you have not used it yet, I would advise you to give it a go.&lt;/p&gt;
&lt;p&gt;It looked like the best solution I have seen to simple file attachments since file_upload and it did not rely on the memory monster that is RMagick.  I said to myself the next project I work on, paperclip is the way to go.&lt;/p&gt;
&lt;p&gt;In terms of tutorials, I would highly advise that you start with this &lt;a href="http://jimneath.org/2008/04/17/paperclip-attaching-files-in-rails/"&gt;tutorial&lt;/a&gt; by Jim Neath.   I have to say that I was a bit confused in the beginning, but this tutorial helped me on my way.&lt;/p&gt;
&lt;h2&gt;Image Permissions&lt;/h2&gt;
&lt;p&gt;As part of the project I needed to direct all requests to the image through an action, to check if the current user that is logged in has permission to see the image.  I had a few issues doing this, so I thought I would share how I did that here.&lt;/p&gt;
&lt;h3&gt;Model:&lt;/h3&gt;
&lt;pre class="ruby"&gt;&lt;code class="ruby"&gt;class User &amp;lt; ActiveRecord::Base&lt;/code&gt;

&lt;code class="ruby"&gt; has_attached_file :photo, :styles =&amp;gt; { :medium =&amp;gt; "300x300&amp;gt;", :thumb =&amp;gt;  "100x100&amp;gt;" } ,
 :url =&amp;gt; "/images/show/:id/:style/",
 :path =&amp;gt; "#{RAILS_ROOT}/attachments/:class/:id/:style/:basename.:extension"&lt;/code&gt;

&lt;code class="ruby"&gt; end&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I removed all the files from the public directory.  That way I was sure that no one can get access to it.  That is where the :path =&amp;gt; Hash is used.  I stored the images in a folder called &amp;#8216;attachments&amp;#8217; contained within the Rails root folder  Here is a list of what the url  params are used for:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;class &amp;#8212; This is the name of the class the attachment is associated to.  In this case User&lt;/li&gt;
	&lt;li&gt;id &amp;#8212; This is the unique ID of the model the attachment is associated to.&lt;/li&gt;
	&lt;li&gt;style &amp;#8212; The name of the style.  In this case we would have a folder called &amp;#8216;thumb&amp;#8217; and a folder called &amp;#8216;medium&amp;#8217; and also a folder called &amp;#8216;original&amp;#8217;&lt;/li&gt;
	&lt;li&gt;basename &amp;#8212; The file name without the file extension&lt;/li&gt;
	&lt;li&gt;extension &amp;#8212; Filename extension&lt;/li&gt;
&lt;/ul&gt;
&lt;div style="text-decoration:line-through;"&gt;
&lt;p&gt;For some reason I could not get the :url hash to work when I used url placeholders.  It just did not seem to want to pass on the parameters to my controller.  So the only option I had was to create the url using the good old fashioned way.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;The :url hash is directing all image requests to the images controller, making sure to pass all the relevant parameters along with it.&lt;/p&gt;
&lt;p&gt;Next I am going to detail the very simple controller :&lt;/p&gt;
&lt;pre class="ruby"&gt;&lt;code class="ruby"&gt;class ImagesController &amp;lt; ApplicationController&lt;/code&gt;

&lt;code class="ruby"&gt;  def show
    if logged_in? &amp;amp;&amp;amp; current_user.allowed_to_view_image?(params[:id])
      send_file(current_user.photo.path(params[:style]) , :disposition =&amp;gt; 'inline')
    else
      '#'
    end    
  end 
end&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;As you can see it is very simple.  All requests are passed to the show action.  The first thing it does is check to see if the user is allowed to see the image using a method called on the User object (I have not detailed it here as it will be different for everybody).&lt;/p&gt;
&lt;p&gt;Once permission has been granted simply display an inline send_file request with the same directory structure as defined in the :path url.&lt;/p&gt;
&lt;h3&gt;Linking&lt;/h3&gt;
&lt;p&gt;As I am not using Rails 2 for this project, I came across a problem with using image_tag as it saw fit to append a .png to the request.  I am not sure how to turn this off and I know it has been &amp;#8216;fixed&amp;#8217; in Rails 2.  My only current solution is to use the old school &amp;#8220;img&amp;#8221; tag in my views.&lt;/p&gt;
&lt;p&gt;Let me know your thoughts&lt;/p&gt;
&lt;h3&gt;&lt;span class="caps"&gt;UPDATE&lt;/span&gt;&lt;/h3&gt;
&lt;p&gt;As you can see from Jon Yurek&amp;#8217;s (creator of this plugin) comment, the old way I was doing it was not necessary.  So I have updated the code to reflect those changes and tested it.  However if you do this, you will also have to add an extra Route to your config.  Here is the one I added :&lt;/p&gt;
&lt;pre class="ruby"&gt;&lt;code class="ruby"&gt;map.connect '/images/:action/:id/:style' , :controller =&amp;gt; 'images'&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Thanks Jon!&lt;/p&gt;
&lt;p&gt;Hamza&lt;/p&gt;</content>
    <author>
      <name>Hamza Khan-Cheema</name>
    </author>
  </entry>
  <entry>
    <link type="text/html" rel="alternate" href="http://hamza.khan-cheema.com/show/23-Arabibay-and-Responds-to-parent-error"/>
    <id>http://hamza.khan-cheema.com/show/23-Arabibay-and-Responds-to-parent-error</id>
    <title>Arabibay and Responds to parent error</title>
    <published>2007-12-26T00:00:00+03:00</published>
    <updated>2011-09-07T00:56:09+03:00</updated>
    <content type="html">&lt;p&gt;I know it has been a very very long time since I last posted.  Quite a few things have been happening in my life the past 4 months.  But I will not bore you with the details :)&lt;/p&gt;
&lt;p&gt;I have been working on a few sites lately.  The latest project which has just been made live is &lt;a href="http://www.arabibay.com"&gt;Arabibay.com&lt;/a&gt; Arabibay is a free classifieds website that allows people to post adverts around the world.  As you can tell by the title, it is aimed at the Middle East, but all countries are supported.  Check it out and leave some feedback, as always your comments are greatly appreciated.&lt;/p&gt;
&lt;h2&gt;Responds To Parent&lt;/h2&gt;
&lt;p&gt;As I can&amp;#8217;t post without mentioning something technical (however insignificant).  For this project I needed to allow users the ability to upload images to the system via &lt;span class="caps"&gt;AJAX&lt;/span&gt;.  I came across this very &lt;a href="http://khamsouk.souvanlasy.com/2007/5/1/ajax-file-uploads-in-rails-using-attachment_fu-and-responds_to_parent"&gt;good tutorial&lt;/a&gt;  and a really useful plugin called &lt;a href="http://code.google.com/p/responds-to-parent/"&gt;Responds to Parent&lt;/a&gt; .&lt;/p&gt;
&lt;p&gt;However I had a few issues setting up the plugin. I installed the plugin like so&lt;/p&gt;
&lt;pre&gt;
&lt;code&gt;
  script/plugin install http://responds-to-parent.googlecode.com/svn/trunk/ 
&lt;/code&gt;
&lt;/pre&gt;
&lt;p&gt;It installed it into a folder called trunk, so immediately I changed the folder name to &lt;b&gt;responds-to-parent&lt;/b&gt;.  So far so good.&lt;/p&gt;
&lt;p&gt;I then tried to restart the app but the app failed to start with this plugin installed.  So I looked around on the net for the error I was getting, but nothing came about.&lt;/p&gt;
&lt;p&gt;To cut a long story short, I needed to rename the folder to &lt;b&gt;responds_to_parent&lt;/b&gt;  as in the init.rb, it is obviously requiring RespondsToParent, which assumes responds_to_parent.&lt;/p&gt;
&lt;p&gt;Hopefully this can save someone some time :)&lt;/p&gt;
&lt;h2&gt;Future Posts&lt;/h2&gt;
&lt;p&gt;I know that I have said this before, but now that I have settled down a bit, I am hoping to blog on a more regular basis.&lt;/p&gt;
&lt;p&gt;Hamza&lt;/p&gt;</content>
    <author>
      <name>Hamza Khan-Cheema</name>
    </author>
  </entry>
  <entry>
    <link type="text/html" rel="alternate" href="http://hamza.khan-cheema.com/show/22-attachment_fu-Thumbnail-Size"/>
    <id>http://hamza.khan-cheema.com/show/22-attachment_fu-Thumbnail-Size</id>
    <title>attachment_fu Thumbnail Size</title>
    <published>2007-05-18T00:00:00+03:00</published>
    <updated>2011-09-07T00:56:43+03:00</updated>
    <content type="html">&lt;p&gt;As I mentioned earlier, when working with attachment_fu and image science the width and height of thumbnails were not being set correctly.  So here is a method that I use to make sure that the data is set. &lt;pre&gt;&lt;code class="ruby"&gt;&lt;/p&gt;
&lt;p&gt;def set_image_dimensions&lt;br /&gt;
  if &lt;code&gt;image.width.blank? || @image.height.blank?
    ImageScience.with_image("#{RAILS_ROOT}/public/" &amp;lt;&amp;lt; @image.public_filename) do |img|
      @image.height = img.height
      @image.width = img.width
    end
    @image.update_attribute('height',&lt;/code&gt;image.height)&lt;br /&gt;
    &lt;code&gt;image.update_attribute('width',&lt;/code&gt;image.width)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Is anyone doing it differently ?  Has this been addressed ?&lt;/p&gt;
&lt;p&gt;Comments welcome.&lt;/p&gt;
&lt;p&gt;Hamza&lt;/p&gt;</content>
    <author>
      <name>Hamza Khan-Cheema</name>
    </author>
  </entry>
  <entry>
    <link type="text/html" rel="alternate" href="http://hamza.khan-cheema.com/show/21-Fun-with-attachment_fu"/>
    <id>http://hamza.khan-cheema.com/show/21-Fun-with-attachment_fu</id>
    <title>Fun with attachment_fu</title>
    <published>2007-05-12T00:00:00+03:00</published>
    <updated>2011-09-07T00:57:10+03:00</updated>
    <content type="html">&lt;p&gt;As I mentioned in my previous post I am going to outline my experiences with attachment_fu. I will try to extend the brilliant &lt;a href="http://clarkware.com/cgi/blosxom/2007/02/24"&gt;tutorial&lt;/a&gt; that first introduced me to attachment_fu and to ImageScience.h2. The problem&lt;/p&gt;
&lt;p&gt;The simple problem I had was that I wanted to be able to associate a image (and thumbnails) to a article. Although this sounds easy, I had some trouble along the way (hence the post).&lt;/p&gt;
&lt;h2&gt;Write the Migration models&lt;/h2&gt;
&lt;pre&gt;&lt;code class="ruby"&gt;

class CreateImages &amp;lt; ActiveRecord::Migration
  
  def self.up
    create_table :images do |t|
      t.column :parent_id,  :integer
      t.column :content_type, :string
      t.column :filename, :string    
      t.column :thumbnail, :string 
      t.column :size, :integer
      t.column :width, :integer
      t.column :height, :integer
      t.column :content_id, :integer
    end
  end

  def self.down
    drop_table :images
  end
end
&lt;/code&gt;&lt;/pre&gt;

&lt;pre&gt;&lt;code class="ruby"&gt;
class CreateContents &amp;lt; ActiveRecord::Migration
  
  def self.up
    create_table :contents do |t|
      t.column :title , :string
      t.column :summary, :text
      t.column :body, :text
      t.column :status, :string
    end
  end

  def self.down
    drop_table :contents
  end
end
&lt;/code&gt;
&lt;/pre&gt;
&lt;p&gt;The only thing to note here is that I have placed a content_id foreign key into the image table, to allow them to be linked.&lt;/p&gt;
&lt;h2&gt;Write the models&lt;/h2&gt;
&lt;p&gt;The models are going to have two different associations, both of type &lt;i&gt;has_one&lt;/i&gt;. The first association has an extra condition that allows it to only return the parent image, the second association returns the parent image and all its associated thumbnails.&lt;/p&gt;
&lt;pre&gt;&lt;code class="ruby"&gt;
class Content &amp;lt; ActiveRecord::Base
  has_one :image, :conditions =&amp;gt; 'parent_id is null'
  has_one :all_images, :class_name =&amp;gt; 'Image' # all photos + thumbnails
end
&lt;/code&gt;
&lt;/pre&gt;
&lt;p&gt;The Image model has the standard attachment_fu declaration along side the thumbnail declarations.&lt;/p&gt;
&lt;pre&gt;&lt;code class="ruby"&gt;
class Image &amp;lt; ActiveRecord::Base
  has_attachment :content_type =&amp;gt; :image, 
                   :storage =&amp;gt; :file_system,
                   :thumbnails =&amp;gt; { :thumb =&amp;gt; '107x76&amp;gt;'}    
end
&lt;/code&gt;
&lt;/pre&gt;
&lt;h2&gt;Write the form view&lt;/h2&gt;
&lt;pre&gt;&lt;code class="ruby"&gt;
&amp;lt;% form_for(:content, :url =&amp;gt; { :action=&amp;gt;'create'}, 
                      :html =&amp;gt; { :multipart =&amp;gt; true }) do |f| -%&amp;gt;

&amp;lt;p&amp;gt;
  &amp;lt;label for="title"&amp;gt;Title&amp;lt;/label&amp;gt;&amp;lt;br/&amp;gt;
  &amp;lt;%= f.text_field :title %&amp;gt;
&amp;lt;/p&amp;gt;

&amp;lt;p&amp;gt;
  &amp;lt;label for="summary"&amp;gt;Summary&amp;lt;/label&amp;gt;&amp;lt;br/&amp;gt;
  &amp;lt;%= f.text_area :summary %&amp;gt;
&amp;lt;/p&amp;gt;

&amp;lt;p&amp;gt;
  &amp;lt;label for="title"&amp;gt;Body&amp;lt;/label&amp;gt;&amp;lt;br/&amp;gt;
  &amp;lt;%= f.text_area :body %&amp;gt;
&amp;lt;/p&amp;gt;

 &amp;lt;p&amp;gt;
    &amp;lt;label for="image"&amp;gt;Associate Image:&amp;lt;/label&amp;gt;&amp;lt;br/&amp;gt;
    &amp;lt;%= file_field 'image','uploaded_data' %&amp;gt;
  &amp;lt;/p&amp;gt;
  &amp;lt;p&amp;gt;
    &amp;lt;%= submit_tag 'Create' %&amp;gt;
  &amp;lt;/p&amp;gt;
&amp;lt;% end -%&amp;gt;
&lt;/code&gt;
&lt;/pre&gt;
&lt;p&gt;As you can see I have placed the image in a different hash, as you can&#226;&#8364;&#8482;t associate the file directly to the model. All of the other fields are pretty standard. To test out the update method you just need to change the &lt;span class="caps"&gt;URL&lt;/span&gt; to point to the update method and pass it the content id. I will leave it out here for simplicity.&lt;/p&gt;
&lt;h2&gt;Write the controller&lt;/h2&gt;
&lt;p&gt;This is where I was having most trouble. No matter what I did, it just did not save the dam thing. So here is my create and update actions in my contents controller&lt;/p&gt;
&lt;pre&gt;&lt;code class="ruby"&gt;
def create
    #Create the content
    @content = Content.new(params[:content])
    respond_to do |format|
      if @content.save
        #Here comes the important bit!
        if !params[:image][:uploaded_data].blank?
          @content.image = Image.create(params[:image])       
        end
        flash[:notice] = 'Content was successfully created.'
        format.html { redirect_to :action=&amp;gt;'show', :id=&amp;gt;@content }
      else
        format.html { render :action =&amp;gt; "new" }
      end
    end
  end  
&lt;/code&gt;
&lt;/pre&gt;
&lt;p&gt;OK that was not that hard :). But I was having problems on the update action. The create action seemed to be working fine. Here is the update action.&lt;/p&gt;
&lt;pre&gt;&lt;code class="ruby"&gt;
  def update
      @content = Content.find(params[:id])
      respond_to do |format|
        if @content.update_attributes(params[:content])
          # Heres the important bit!
          if !params[:image][:uploaded_data].blank?
            #find current image
            @image = @content.image ||= Image.new
            @image = @content.image.build(params[:image])
            @image.save       
          end
          format.html { redirect_to :action=&amp;gt;'show', :id=&amp;gt;@content }
        else
          format.html { render :action =&amp;gt; "edit" }
        end
      end
    end
 &lt;/code&gt;
&lt;/pre&gt;
&lt;p&gt;As you can see I am using the build method to create the image. I am not sure why, but If I put the build method into the create method it just fails. Oh yeah and in a real application I would group the image methods into their own respective functions.&lt;/p&gt;
&lt;h2&gt;The content view&lt;/h2&gt;
&lt;p&gt;So for all the code we have written we can now show the images that are associated with a specific article.&lt;/p&gt;
&lt;pre&gt;
&lt;code class="ruby"&gt;
  &amp;lt;h2&amp;gt;&amp;lt;%=@content.title%&amp;gt; &amp;lt;/h2&amp;gt;
  &amp;lt;p&amp;gt;&amp;lt;%=@content.summary%&amp;gt;&amp;lt;/p&amp;gt;

&amp;lt;%if !@content.image.blank?%&amp;gt; 
  &amp;lt;p&amp;gt;
    Original Image : &amp;lt;%=image_tag @content.image.public_filename %&amp;gt;
  &amp;lt;/p&amp;gt;
  &amp;lt;p&amp;gt;
    Thumbnail : &amp;lt;%=image_tag @content.image.public_filename(:thumb) %&amp;gt;
  &amp;lt;/p&amp;gt;
  &amp;lt;p&amp;gt;
    &amp;lt;%=@content.body%&amp;gt;
  &amp;lt;/p&amp;gt;
&amp;lt;%end%&amp;gt;
&lt;/code&gt;
&lt;/pre&gt;
&lt;h2&gt;Outstanding issues&lt;/h2&gt;
&lt;p&gt;There a few bugs in attachment_fu that I came across, they are :&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;The width and the height are not being set for thumbnails when I use ImageScience and attachment_fu.&lt;/li&gt;
	&lt;li&gt;The size (in the database field) of the thumbnails are not correct. They just display the original file&#226;&#8364;&#8482;s image size.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I will blog again regarding these issues in the near future.&lt;/p&gt;
&lt;h2&gt;Code&lt;/h2&gt;
&lt;p&gt;In writing this post, I made a test rails app so I could make sure that the code I have above is correct and compiles without any errors.  If anyone wants this I can put a link to it here, just leave a comment.&lt;/p&gt;
&lt;p&gt;As usual all comments welcome.&lt;/p&gt;
&lt;p&gt;Hamza&lt;/p&gt;</content>
    <author>
      <name>Hamza Khan-Cheema</name>
    </author>
  </entry>
  <entry>
    <link type="text/html" rel="alternate" href="http://hamza.khan-cheema.com/show/20-Compiling-FreeImage-on-OS-X-%28Power-PC%29"/>
    <id>http://hamza.khan-cheema.com/show/20-Compiling-FreeImage-on-OS-X-%28Power-PC%29</id>
    <title>Compiling FreeImage on OS X (Power PC)</title>
    <published>2007-05-03T00:00:00+03:00</published>
    <updated>2011-09-07T00:57:59+03:00</updated>
    <content type="html">&lt;p&gt;I was very excited when I read this excellent &lt;a href="http://clarkware.com/cgi/blosxom/2007/02/24"&gt;blog post&lt;/a&gt; by Mike Clark, detailing how to use attachment_fu.  Even more interesting was that I did not have to use RMagick anymore.  I could not quite get it working correctly for me, not to mention the reported memory leaks and &lt;span class="caps"&gt;CPU&lt;/span&gt; cycles it takes up.Instead I could use &lt;a href="http://seattlerb.rubyforge.org/ImageScience.html"&gt;ImageScience&lt;/a&gt; which is a small Inline Ruby library that re-sizes images.  However for me to install ImageScience I had to install &lt;a href="http://freeimage.sourceforge.net/"&gt;FreeImage&lt;/a&gt; on my mac.&lt;/p&gt;
&lt;p&gt;Whatever I did I could not get it installed on my power pc mac laptop.  I tried the instructions given, but nothing worked.  I then noticed that there was a problem with the current release for macs and was advised to use the subversion repository.  I tried to do this, but whenever I tried to run make, it just kept on complaining that it can&amp;#8217;t find the libs that were related to the Intel 386 platform.  So the make file was not correctly working for the power pc architecture.&lt;/p&gt;
&lt;p&gt;I posted to the forums, and luckily Josh emailed me with a makefile that stripped out all of the 386 calls (i tried this myself but did not get very far).  The new make file did the trick.  Thanks Josh :)&lt;/p&gt;
&lt;p&gt;So if anyone else is having the same problem here is the &lt;a href="http://hamza.khan-cheema.com/assets/2007/5/3/Makefile.osxppc"&gt;make file&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;In my next post I will be talking about my adventures with attachment_fu and extending the tutorial laid out in Mike Clark&amp;#8217;s blog post.&lt;/p&gt;
&lt;p&gt;Hamza&lt;/p&gt;</content>
    <author>
      <name>Hamza Khan-Cheema</name>
    </author>
  </entry>
  <entry>
    <link type="text/html" rel="alternate" href="http://hamza.khan-cheema.com/show/19-Rails-Autocomplete-Tag-List"/>
    <id>http://hamza.khan-cheema.com/show/19-Rails-Autocomplete-Tag-List</id>
    <title>Rails Autocomplete Tag List</title>
    <published>2007-03-03T00:00:00+03:00</published>
    <updated>2011-09-07T00:58:50+03:00</updated>
    <content type="html">&lt;p&gt;I wanted to make an autocomplete text field on a edit form that listed all of the tags that are already entered in the system. It is quite simple, but I thought I would share it to save some time for someone. Of course we are using acts_as_taggableThe controller :&lt;/p&gt;
&lt;pre&gt;&lt;code class="ruby"&gt;
def auto_complete_for_tag_name
  auto_complete_responder_for_tag_name params[:tag][:name]
end

def auto_complete_responder_for_tag_name(value)
  @tag_list = Tag.find(:all,
  :conditions =&amp;gt; [ &#226;&#8364;&#732;LOWER(name) LIKE ?&#226;&#8364;&#8482;,
  &#226;&#8364;&#732;%&#226;&#8364;&#8482; + value.downcase + &#226;&#8364;&#732;%&#226;&#8364;&#8482; ],
  :order =&amp;gt; &#226;&#8364;&#732;name ASC&#226;&#8364;&#8482;,
  :limit =&amp;gt; 10)

  render :partial =&amp;gt; &#226;&#8364;&#732;tags&#226;&#8364;&#8482;

end

def edit
  @content = Content.find(params[:id])
  @tag = Tag.new
  @tag.name = @content.tag_list
end
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;To retrieve the current tag list you need to make a new Tag object and add the tag list to it.&lt;/p&gt;
&lt;p&gt;In my _tag.rhtml partial :&lt;/p&gt;
&lt;pre&gt;&lt;code class="ruby html"&gt;
&amp;lt;ul class=&#226;&#8364;&#157;tags&#226;&#8364;&#157;&amp;gt;
  &amp;lt;% for tag in @tag_list do -%&amp;gt;
    &amp;lt;li class=&#226;&#8364;&#157;contact&#226;&#8364;&#157;&amp;gt;&amp;lt;div class=&#226;&#8364;&#157;name&#226;&#8364;&#157;&amp;gt;&amp;lt;%=h tag.name %&amp;gt; &amp;lt;/div&amp;gt;&amp;lt;/li&amp;gt;
  &amp;lt;% end -%&amp;gt;
&amp;lt;/ul&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In My _form.rhtml&lt;/p&gt;
&lt;pre&gt;&lt;code class="ruby html"&gt;
&amp;lt;p&amp;gt;Tags (Seperate with space)&amp;lt;br/&amp;gt;

&amp;lt;%= text_field_with_auto_complete :tag, :name,
{:size =&amp;gt;50, :skip_style =&amp;gt; true},
{:indicator =&amp;gt;&#226;&#8364;&#8482;searchIndicator&#226;&#8364;&#8482;,
:tokens =&amp;gt; [&#226;&#8364;&#8482; &#226;&#8364;&#732;, &#226;&#8364;&#732;\n&#226;&#8364;&#8482;]} %&amp;gt;
&amp;lt;%= image_tag(&#226;&#8364;&#157;/images/indicator2.gif&#226;&#8364;&#157;, :id =&amp;gt; &#226;&#8364;&#8482;searchIndicator&#226;&#8364;&#8482;, :style =&amp;gt; &#226;&#8364;&#732;display:none;&#226;&#8364;&#8482;) %&amp;gt;
&amp;lt;/p&amp;gt;
&lt;/code&gt;
&lt;/pre&gt;
&lt;p&gt;You will notice that I have added a search indicator, which you will need to have on your system.&lt;/p&gt;
&lt;p&gt;Thats how easy it is :)&lt;/p&gt;
&lt;p&gt;Hamza&lt;/p&gt;</content>
    <author>
      <name>Hamza Khan-Cheema</name>
    </author>
  </entry>
  <entry>
    <link type="text/html" rel="alternate" href="http://hamza.khan-cheema.com/show/18-Create-Triple-DES-SecretKey-in-Java"/>
    <id>http://hamza.khan-cheema.com/show/18-Create-Triple-DES-SecretKey-in-Java</id>
    <title>Create Triple DES SecretKey in Java</title>
    <published>2006-12-29T00:00:00+03:00</published>
    <updated>2011-09-07T00:59:30+03:00</updated>
    <content type="html">&lt;p&gt;For a project at work, I needed to integrate our website with another web application. The web application in question also had their own built in user management system. For seamless integration we wanted our users to only have to log in once.As the web application was quite a large application, they already had a &lt;span class="caps"&gt;REST&lt;/span&gt; api that allowed you to supply them with a encrypted token in the url that authenticated you on their systems. You simply had to encrypt the user id (on their system) and the current time stamp.&lt;/p&gt;
&lt;p&gt;As I had never done anything to do with encryption before in Java. I had to learn from scratch.&lt;/p&gt;
&lt;p&gt;The token had to be encrypted with Triple &lt;span class="caps"&gt;DES&lt;/span&gt; &lt;span class="caps"&gt;CBC&lt;/span&gt; scheme. They supply you with an access key. Here is where the problem lay. I could find quite a few examples that allowed you to use the inbuilt key generator in Java, but what about if you have your own key (our access key). This was a bit more difficult to find, so I thought I would blog a code snipit here. In the end it turned out to simple (it always is :)&lt;/p&gt;
&lt;p&gt;The key needed to be Triple &lt;span class="caps"&gt;DES&lt;/span&gt; (DESede)&lt;/p&gt;
&lt;pre&gt;
&lt;code&gt;
String keyString =&#226;&#8364;&#157;4d89g13j4j91j27c582ji69373y788r6&#226;&#8364;&#179;; // I made this key up by the way!

byte[] keyB = new byte[24]; // a Triple DES key is a byte[24] array

for (int i = 0; i &amp;lt; keyString.length() &amp;amp;&amp;amp; i &amp;lt; keyB.length; i++) {
  keyB[i] = (byte) keyString.charAt(i);
}
// Make the Key
SecretKey key = new SecretKeySpec(keyB, &#226;&#8364;&#339;DESede&#226;&#8364;&#157;);
&lt;/pre&gt;
&lt;p&gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;A good resource that I found was &lt;a href="http://www.owasp.org/index.php/Using_the_Java_Cryptographic_Extensions#Des_Encryption_and_Decryption"&gt;here&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Hamza&lt;/p&gt;</content>
    <author>
      <name>Hamza Khan-Cheema</name>
    </author>
  </entry>
  <entry>
    <link type="text/html" rel="alternate" href="http://hamza.khan-cheema.com/show/12-Delicious-with-Ruby-on-Rails---JSON"/>
    <id>http://hamza.khan-cheema.com/show/12-Delicious-with-Ruby-on-Rails---JSON</id>
    <title>Delicious with Ruby on Rails - JSON</title>
    <published>2006-12-13T00:00:00+03:00</published>
    <updated>2011-09-07T00:59:59+03:00</updated>
    <content type="html">&lt;p&gt;I recently (well about a month ago!) read a &lt;a href="http://kekova.ca/articles/2005/12/08/include-del-icio-us-links-on-your-page"&gt;very good post&lt;/a&gt; that informs you how to add your delicious links to your rails app.I was using that method and all was well, until I got a request that the links should open in a new window. With the simple html access to my links, that was not an option you can pass. So I had to resort to using something more complicated; &lt;a href="http://www.json.org/"&gt;&lt;span class="caps"&gt;JSON&lt;/span&gt;&lt;/a&gt; seemed the easiest for me to read in and manipulate.&lt;/p&gt;
&lt;p&gt;I would advise you to follow this &lt;a href="http://kekova.ca/articles/2005/12/08/include-del-icio-us-links-on-your-page"&gt;tutorial&lt;/a&gt; and then come back here and see how the code can be changed to use &lt;span class="caps"&gt;JSON&lt;/span&gt; instead of the &lt;span class="caps"&gt;HTML&lt;/span&gt; api.&lt;/p&gt;
&lt;p&gt;You will need to install the &lt;span class="caps"&gt;JSON&lt;/span&gt; ruby library first.&lt;/p&gt;
&lt;p&gt;gem install json&lt;/p&gt;
&lt;p&gt;If that does not work just download it from &lt;a href="http://json.rubyforge.org/"&gt;here&lt;/a&gt; and run the install script.&lt;/p&gt;
&lt;p&gt;Here is the modified method&lt;/p&gt;
&lt;pre&gt;
&lt;code class="ruby"&gt;
def delicious_links(limit ="20", aclass="grey")
    begin
      unless read_fragment(:action =&amp;gt; 'delicious_links')
        logger.info "Getting new delicious_links"
        require "open-uri"
        require 'json'
        @delicious_links = ""
        link = "http://del.icio.us/feeds/json/YOUR_USERNAME_HERE?raw=true&amp;amp;count="+limit
        @jsonObject = ""
        
        open(link) {|f|
          f.each_line {|line| @jsonObject += line }
        }
        @urls = parse(@jsonObject)
        
        for i in 0...@urls.length
          @url_obj = @urls.fetch(i)
          url =""
          title =""
          tags =""
          @url_obj.each {|key, value|  
           url = value if key == "u"
           title = value if key == "d"
           tags = value if key == "t"
          }
          @delicious_links += "&amp;lt;div class=\"blogSideBarLink\"&amp;gt;" + "&amp;lt;a href= \""+url+"\" target=\"blank_\" class=\""+aclass+"\"&amp;gt;"+ title+"&amp;lt;/a&amp;gt;&amp;lt;/div&amp;gt;"            
        end
      end
    rescue
      @delicious_links = "Not available @ this time"
    end
    logger.info "delicious_links finished"
    render_without_layout
  end
&lt;/code&gt;
&lt;/pre&gt;</content>
    <author>
      <name>Hamza Khan-Cheema</name>
    </author>
  </entry>
  <entry>
    <link type="text/html" rel="alternate" href="http://hamza.khan-cheema.com/show/17-Atheros-Wireless-Setup---Ubuntu"/>
    <id>http://hamza.khan-cheema.com/show/17-Atheros-Wireless-Setup---Ubuntu</id>
    <title>Atheros Wireless Setup - Ubuntu</title>
    <published>2006-12-11T00:00:00+03:00</published>
    <updated>2011-09-07T01:00:32+03:00</updated>
    <content type="html">&lt;p&gt;As I stated earlier, I just bought a new laptop and installed Ubuntu 6.10 (Edgy Eft) on it. All was working apart from the wireless connection. The Laptop comes with a Atheros wireless card. Ubuntu also comes installed with madwifi drivers for the card. So in theory things should just work, right ? Well no. The version of the wireless card I have (I do not have the version to hand) does not work with the current ubuntu package of madWiFi drivers.&lt;/p&gt;
&lt;p&gt;So this is a quick step by step tutorial on how I got things to work nicely :&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;Get the g++ compiler : sudo apt-get install build-essential&lt;/li&gt;
	&lt;li&gt;Download subversion : sudo apt-get install subversion&lt;/li&gt;
	&lt;li&gt;Create directory to store the drivers and navigate to it.&lt;/li&gt;
	&lt;li&gt;Download latest madwifi drivers using subversion : subversion svn checkout http://svn.madwifi.org/trunk madwifi&lt;/li&gt;
	&lt;li&gt;Get the current Kernel you are running : uname -r&lt;/li&gt;
	&lt;li&gt;Navigate to the correct lib directory : cd /lib/modules/$(uname -r) (use the output from the previous step to get the directory)&lt;/li&gt;
	&lt;li&gt;Delete the net lib files : sudo rm -rf net&lt;/li&gt;
	&lt;li&gt;Delete the madwifi files : sudo rm -rf madwifi&lt;/li&gt;
	&lt;li&gt;Delete this folder if it exists : sudo rm -rf madwifi-ng&lt;/li&gt;
	&lt;li&gt;Find the modules currently installed that you need to unload : lsmod | grep ath&lt;/li&gt;
	&lt;li&gt;From this output above issue a rmmod command for all the modules : sudo rmmod modulename&lt;/li&gt;
	&lt;li&gt;Go back to where you downloaded the new subversion drivers and run : sudo make and then sudo make install answer yes to remove the old module.&lt;/li&gt;
	&lt;li&gt;Load all of the modules you have just unloaded using modprobe. These should be:&lt;br /&gt;
      sudo modprobe ath_pci&lt;br /&gt;
      sudo modprobe ath_rate_sample&lt;br /&gt;
      sudo modprobe wlan&lt;br /&gt;
      sudo modprobe ath_hal&lt;/li&gt;
	&lt;li&gt;Check to see if modules have been loaded by typing dmesg and looking at the system log.&lt;/li&gt;
	&lt;li&gt;Open up network gui in Ubuntu and enable the wifi card and set the sessid&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The card should now be configured. However if you want a dock applet that informs you how much strength your wireless card has, I would suggest netapplet.&lt;/p&gt;
&lt;p&gt;I hope this has helped someone. This took me about 2-3 hours to get working!&lt;/p&gt;
&lt;p&gt;Hamza&lt;/p&gt;</content>
    <author>
      <name>Hamza Khan-Cheema</name>
    </author>
  </entry>
  <entry>
    <link type="text/html" rel="alternate" href="http://hamza.khan-cheema.com/show/16-PC-Nextday-Zoostorm-4-5701-17-Laptop---Wireless-problem"/>
    <id>http://hamza.khan-cheema.com/show/16-PC-Nextday-Zoostorm-4-5701-17-Laptop---Wireless-problem</id>
    <title>PC Nextday Zoostorm 4-5701 17" Laptop - Wireless problem</title>
    <published>2006-12-08T00:00:00+03:00</published>
    <updated>2011-09-07T01:02:49+03:00</updated>
    <content type="html">&lt;p&gt;So I bought a &lt;a href="http://www.pcnextday.co.uk/products/ProductDetail.asp?ProductCode=3384-5701"&gt;17 inch Zoostorm laptop&lt;/a&gt; from &lt;a href="http://www.pcnextday.com/"&gt;PCNextday&lt;/a&gt; . It got 5 stars out of 5 from &lt;a href="http://www.pcpro.co.uk/shopper/labs/96085/pc-nextday-zoostorm-45701.html"&gt;Computer Shopper&lt;/a&gt; and it worked out about &#194;&#163;200 cheaper the a 17&#226;&#8364;&#179; Dell laptop.All was well, I was aware that they did have a bad reputation for customer service, but I thought I would risk it as the saving was too much.&lt;/p&gt;
&lt;p&gt;The laptop came within 3 days of me ordering it. This was a surprise as they said that it can take up to take 3 weeks.&lt;/p&gt;
&lt;p&gt;The laptop was working well, I was impressed with the screen (even though computer shopper said it was dull). However I was having a problem with the built in wireless card (Atheros). It was getting a very low signal even though I was sitting next to the wireless router. I first thought this was my router, so I asked someone else to test it and they reported the same problems. I then went and upgraded the software to the latest driver. The windows drivers are difficult to find so here is a &lt;a href="ftp://lizzi555.dyndns.org/Download/WLAN/Atheros/"&gt;good resource&lt;/a&gt; . But this had no effect. So after tearing my hair out I could not figure it out I emailed the technical support at pcnextday. They took a long time to respond, but their response was worth the wait. They basically said to check weather the wireless card was installed correctly and gave me these pictures :&lt;/p&gt;
&lt;p&gt;&lt;img src="http://hamzakc.files.wordpress.com/2006/12/laptop.JPG?w=489&amp;amp;h=252" alt="" /&gt;&lt;br /&gt;
&lt;img src="http://hamzakc.files.wordpress.com/2006/12/laptop-wireless.JPG?w=497&amp;amp;h=481" alt="" /&gt;&lt;/p&gt;
&lt;p&gt;So I unscrewed the laptop and checked it. I found out that the card was in the correct place, however the antenna was connected to the wrong point in the card. So I changed that and tested it. Unfortunately this did not work. As there were two wires that were black, I thought maybe the person who installed it made a mistake and attached the wrong wire. So I added the other wire and it worked. Now I have an excellent signal :)&lt;/p&gt;
&lt;p&gt;I hope this experience helps someone. I think pcnextday need to work on their quality control :)&lt;/p&gt;
&lt;p&gt;I have installed Ubuntu 6.10 on the laptop. All of the things seem to work. I had to do some configuration to get the wireless card to work though, but that is another blog post.&lt;/p&gt;
&lt;p&gt;Hamza&lt;/p&gt;</content>
    <author>
      <name>Hamza Khan-Cheema</name>
    </author>
  </entry>
  <entry>
    <link type="text/html" rel="alternate" href="http://hamza.khan-cheema.com/show/15-Dual-Monitor-Setup---Ubuntu-ATI"/>
    <id>http://hamza.khan-cheema.com/show/15-Dual-Monitor-Setup---Ubuntu-ATI</id>
    <title>Dual Monitor Setup - Ubuntu ATI</title>
    <published>2006-10-16T00:00:00+03:00</published>
    <updated>2011-09-07T01:03:51+03:00</updated>
    <content type="html">&lt;p&gt;I wanted to get my dual monitor setup working at work. I have the latest veresion of Ubuntu (6.06 &lt;span class="caps"&gt;LTS&lt;/span&gt; &amp;#8211; the Dapper Drake).&lt;b&gt;aticonfig&lt;/b&gt;&lt;br /&gt;
This is a really easy way to get it working. I have a Dell Optiplex GX620 with a &lt;span class="caps"&gt;ATI&lt;/span&gt; graphics card. The card can support a dual monitor setup.&lt;/p&gt;
&lt;p&gt;It turns out that ati have supplied a program (aticonfig) that inspects your current xorg.conf file and then changes it to allow for dual monitor setup.&lt;/p&gt;
&lt;p&gt;Here is what you do in a terminal window :&lt;br /&gt;
&lt;pre&gt;&lt;br /&gt;
&lt;code&gt;
sudo aticonfig &#226;&#8364;&#8220;initial=dual-head &#226;&#8364;&#8220;screen-layout=left&lt;/p&gt;
&lt;p&gt;&lt;/code&gt;&lt;br /&gt;
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;You may want to change the left to be right, dependendant on where your main monitor is (monitor 0).&lt;/p&gt;
&lt;p&gt;As I have two monitors that support diffrent resolutions, the setup was using 1024&#195;&#8212;768 on both screens and I could not drag windows accross screens (I could drag the mouse :)&lt;/p&gt;
&lt;p&gt;To address the dragging window issue, I did this after I executed the first command :&lt;br /&gt;
&lt;pre&gt;&lt;br /&gt;
&lt;code&gt;
sudo aticonfig &#226;&#8364;&#8220;dtop=horizontal, reverse &#226;&#8364;&#8220;overlay-on=1
&lt;/code&gt;&lt;br /&gt;
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;If you look at the help page for aticonfig, you will see that dtop can take different parameters. Because my second screen was to the left of monitor 0, I had horizontal, reverse But if it was to the right I would have used horizontal only.&lt;/p&gt;
&lt;p&gt;To address the screen resolution do this (please see note)&lt;br /&gt;
&lt;pre&gt;&lt;br /&gt;
&lt;code&gt;
sudo aticonfig &#226;&#8364;&#8220;resolution=0,1600&#195;&#8212;1200,1280&#195;&#8212;1024,1024&#195;&#8212;768
&lt;/code&gt;&lt;br /&gt;
&lt;/pre&gt;&lt;br /&gt;
This now sets my monitor 0 to be able to support 1600&#195;&#8212;1200 resolution. My smaller monitor (monitor 1) will use 1024&#195;&#8212;768, which is what I want. You can simply change where it says 0 to be 1 This will now change monitor 1.&lt;/p&gt;
&lt;p&gt;Now simply restart gdm to see the effects. Or if you can&#226;&#8364;&#8482;t do that, just restart the machine.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Note&lt;/b&gt;&lt;br /&gt;
Before you start changing the resolution, you need to know which is defined as monitor 0. As in my case monitor 0 supports a higher resolution then monitor 1. The easy way to find this out is to do the first two steps, start up and then the monitor with the menubar on top of it is monitor 0. If it is not the monitor you wanted, you can simply swap around the vga cables that go into the back of the video card&lt;br /&gt;
There is a way to do it by editing the xorg.conf, but this is supposed to be a simple way of doing it :)&lt;/p&gt;
&lt;p&gt;I hope this helps someone!&lt;/p&gt;
&lt;p&gt;Hamza&lt;/p&gt;</content>
    <author>
      <name>Hamza Khan-Cheema</name>
    </author>
  </entry>
  <entry>
    <link type="text/html" rel="alternate" href="http://hamza.khan-cheema.com/show/14-RailsConf%2C-My-thoughts"/>
    <id>http://hamza.khan-cheema.com/show/14-RailsConf%2C-My-thoughts</id>
    <title>RailsConf, My thoughts</title>
    <published>2006-09-15T00:00:00+03:00</published>
    <updated>2011-09-07T01:04:18+03:00</updated>
    <content type="html">&lt;p&gt;I have just got home from two very exciting days at the rubyconf conference in London. Here are a few observations and just a few things I have learnt.&lt;/p&gt;
&lt;p&gt;Observations&lt;br /&gt;
I am not sure why, but I had a distinct impression that the majority of attendees would have been from Europe. However I seemed to come across people from the US or Canada. People who have come over from the states especially for the conference or people who are making it part of their vacation. Not that this is a bad thing. In fact it showed me that they were really committed to Rails and to Ruby. I have to say if my company was not paying for my ticket, I would never have dreamed of going to the conference. Maybe I need to get more involved :)&lt;/p&gt;
&lt;p&gt;As this is my first conference, I was not sure what to expect. It was an entire new experience. I was pleasantly surprised by the organisation of the conference by skillsmatter and also by the excellent calibre of the speakers. As I am new to the ruby world, I did not know the speakers (apart from David H), this conference allowed me to put faces and personalities to these very influential people within the Rails / Ruby community.&lt;/p&gt;
&lt;p&gt;I got to see the Rails core team. This was a real eye opener for me, as I had no idea who they were or what their thoughts were for the future of Rails (I know I should read more).&lt;/p&gt;
&lt;p&gt;Then comes David H&#226;&#8364;&#8482;s talk. I have to say that I was impressed with David&#226;&#8364;&#8482;s ideas and the way he presented himself. I really like the &lt;span class="caps"&gt;RESTFUL&lt;/span&gt; stuff and ActiveResource and also the Simply Helper. For those of you that don&#226;&#8364;&#8482;t know, this is a way of putting conventions into the view layer like he has just done for the controller using &lt;span class="caps"&gt;REST&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;Things I learned&lt;/p&gt;
&lt;p&gt;Overall I have to say that I did learn allot (especially about Ruby)&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;Rails 1.2 is to be released very soon and is going to depreciate a whole bunch of methods.&lt;/li&gt;
	&lt;li&gt;In Rails 2.0 these deprecated methods will be removed.&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
	&lt;li&gt;1.2 is going to heavily push the &lt;span class="caps"&gt;REST&lt;/span&gt; stuff.&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
	&lt;li&gt;Routing has completely been rewritten as it was a bottleneck. This is to be released in 1.2&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
	&lt;li&gt;The goals of ActiveResource, It is not going to ship with Rails 1.2, maybe 2.0 ?&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
	&lt;li&gt;With all the restful work on the controllers, the view started to look dated, so they have developed SimplyHelper, which is a convention for views.&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
	&lt;li&gt;Rails speaks &#226;&#8364;&#732;C&#226;&#8364;&#8482; &amp;#8211; This was a talk I attended. I think things like this are very important. If we have a very complex algorithm or we have some legacy C systems, we need to be able to call C code from Ruby. In the Python &lt;span class="caps"&gt;CMS&lt;/span&gt; world Zope does this for a lot of complex operations (as far as I remember, correct me if I am wrong). 4 different approaches were mentioned. I noted that &lt;span class="caps"&gt;SWIG&lt;/span&gt; seemed to be one of the better options (and it supports c++).&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
	&lt;li&gt;If you are using C to do a big &lt;span class="caps"&gt;CPU&lt;/span&gt; intensive task, or a task that will take a while to complete, then you need to use BackgroundDRB. This allows you to spawn requests in the background (surprise,surprise). So in a web app the client gets a response straight away, so he knows something is happening , a progress bar would be a good indicator in this situation.&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
	&lt;li&gt;I really enjoyed the talk about high performance. I always wondered if anyone had deployed Rails apps, which had to handle over a million hits per day. Well James Cox seemed to have allot of experience in this field, and he shared some tips with us. I will mention a few here.&lt;/li&gt;
&lt;/ul&gt;

	&lt;ul&gt;
		&lt;li&gt;Speed Perceived &amp;#8211; This is to use Ajax to make the app perceive fast to the user. The user will not know.&lt;/li&gt;
		&lt;li&gt;Always use :select, :limit and :offset in your queries.&lt;/li&gt;
		&lt;li&gt;Try and use lazy loading (:include).&lt;/li&gt;
		&lt;li&gt;&lt;span class="caps"&gt;MEMCACHED&lt;/span&gt; &amp;#8211; Basically always use this as much as possible, he really emphasised this point.&lt;/li&gt;
		&lt;li&gt;Avoid shared hosting (obvious).&lt;/li&gt;
		&lt;li&gt;Page Caching &amp;#8211; &lt;span class="caps"&gt;BAD&lt;/span&gt; &amp;#8211; Avoid this as it is a nightmare to clean up.&lt;/li&gt;
		&lt;li&gt;Fragment Caching &amp;#8211; Is better then page caching, but their are scalability issues&lt;/li&gt;
		&lt;li&gt;8 server Gem (server architecture) &amp;#8211; 2 x Proxy / Web static servers, 4 x Application servers, 2x Database servers with database replication.&lt;/li&gt;
		&lt;li&gt;Session management &amp;#8211; use memcache, not the database store&lt;/li&gt;
		&lt;li&gt;If you have one server use Apache (fcgi), but this does not scale well, so for multiple machines use mongrel.&lt;/li&gt;
		&lt;li&gt;Put Google Analytics in its own iframe, this will avoid your app waiting to show the page because it is retrieving the js from google.&lt;/li&gt;
	&lt;/ul&gt;&lt;ul&gt;
	&lt;li&gt;Django
	&lt;ul&gt;
		&lt;li&gt;Really cool!&lt;/li&gt;
		&lt;li&gt;Has built in user and groups in the framework&lt;/li&gt;
		&lt;li&gt;Uses python code to define database schema. This allows them to add rich data models. So you can define an upload field or a url field, the system will automatically know what to do with this field. This allows them to auto generate the admin interface to such a high level and what streamlined is trying to replicate for Rails.&lt;/li&gt;
		&lt;li&gt;Reusable template views with hierarchy functionality.&lt;/li&gt;
		&lt;li&gt;Try and not use &lt;span class="caps"&gt;AJAX&lt;/span&gt; in the admin section, as you do not know what kind of PC your publishers are going to publish from (old, etc.)&lt;/li&gt;
	&lt;/ul&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Please comment if you found this useful or not.&lt;br /&gt;
Hamza&lt;/p&gt;</content>
    <author>
      <name>Hamza Khan-Cheema</name>
    </author>
  </entry>
  <entry>
    <link type="text/html" rel="alternate" href="http://hamza.khan-cheema.com/show/13-RailsConf"/>
    <id>http://hamza.khan-cheema.com/show/13-RailsConf</id>
    <title>RailsConf</title>
    <published>2006-09-13T00:00:00+03:00</published>
    <updated>2011-09-07T01:04:43+03:00</updated>
    <content type="html">&lt;p&gt;I am really excited that I am going to RailsConf in London! Its going to be my first tech conference :)&lt;br /&gt;
Hopefully I can write some thoughts about it on this blog.&lt;/p&gt;
&lt;p&gt;Hamza&lt;/p&gt;</content>
    <author>
      <name>Hamza Khan-Cheema</name>
    </author>
  </entry>
  <entry>
    <link type="text/html" rel="alternate" href="http://hamza.khan-cheema.com/show/11-Search-problems"/>
    <id>http://hamza.khan-cheema.com/show/11-Search-problems</id>
    <title>Search problems</title>
    <published>2006-07-09T00:00:00+03:00</published>
    <updated>2011-09-07T01:05:07+03:00</updated>
    <content type="html">&lt;p&gt;In my last post I said that I was using acts_as_ferret.  However I was finding it difficult to create an index for a certain section of the site.  I think this was due to me having null fields some of the database fields. I could nt change this.When I was having problems I turned to &lt;a href="http://poocs.net/articles/2006/04/06/introducing-acts_as_searchable"&gt;acts_as_searchable&lt;/a&gt; . As the post states the search plugin uses &lt;a href="http://hyperestraier.sourceforge.net/"&gt;HyperEstraier&lt;/a&gt; which is an opensource search engine.  It seems to be very good and above all (for me) the &lt;span class="caps"&gt;UTF&lt;/span&gt; support seems excellent. This is demenstroated by having a Japenese language search demo on their site.&lt;/p&gt;
&lt;p&gt;I managed to get it to work :) I will post how in the next couple of days.&lt;br /&gt;
My first thoughs about &lt;a href="http://hyperestraier.sourceforge.net/"&gt;HyperEstraier&lt;/a&gt; is that it has some very good features, but most of the features I am not going to use in the near future.  Overall the set up is a bit more invloved then ferret, this is because you need to run a deamon.&lt;/p&gt;
&lt;p&gt;More thoughts soon!&lt;/p&gt;
&lt;p&gt;Hamza&lt;/p&gt;</content>
    <author>
      <name>Hamza Khan-Cheema</name>
    </author>
  </entry>
  <entry>
    <link type="text/html" rel="alternate" href="http://hamza.khan-cheema.com/show/10-acts_as_ferret-error"/>
    <id>http://hamza.khan-cheema.com/show/10-acts_as_ferret-error</id>
    <title>acts_as_ferret error</title>
    <published>2006-07-05T00:00:00+03:00</published>
    <updated>2011-09-06T12:45:13+03:00</updated>
    <content type="html">&lt;p&gt;I started using the acts_as_ferret plugin for ruby on rails today. I was having a problem with the site not getting indexed &amp;#8211; After putting the acts_as_ferret in the desired models, I searched for words that I knew existed and i was not getting any responses.&lt;/p&gt;
&lt;p&gt;I figured out that it was not being indexed. if the index directory does not exist than the plugin calls rebuild_index method. This is supposed to go through your database and create the index.&lt;/p&gt;
&lt;p&gt;The app was failing executing the rebuild_index method. I googled the error and came across this post It was an error because i was using Unicode. So I added the following to my environment.rb file and it has indexed the files :&lt;/p&gt;
&lt;pre&gt;

&lt;code&gt;
    ENV['LANG'] = 'en_GB.UTF-8'
    ENV['LC_TIME'] = 'C'
&lt;/code&gt;
&lt;/pre&gt;
&lt;p&gt;All I have to do now is figure out how to use ferret :)&lt;/p&gt;
&lt;p&gt;Hamza&lt;/p&gt;</content>
    <author>
      <name>Hamza Khan-Cheema</name>
    </author>
  </entry>
  <entry>
    <link type="text/html" rel="alternate" href="http://hamza.khan-cheema.com/show/9-Small-Bug-in-acts_as_taggable-with-acts_as_versioned"/>
    <id>http://hamza.khan-cheema.com/show/9-Small-Bug-in-acts_as_taggable-with-acts_as_versioned</id>
    <title>Small Bug in acts_as_taggable with acts_as_versioned</title>
    <published>2006-06-29T00:00:00+03:00</published>
    <updated>2011-09-07T01:05:51+03:00</updated>
    <content type="html">&lt;p&gt;I have come accross a bug if you are using acts_as_taggable and acts_as_versioned on the same model. For some reason acts_as_taggable triggers a new version to be stored in the version history. So it stores two identical versions every time. As soon as you turn off the tagging it works.&lt;br /&gt;
I have tried to get around the issue by using the method version_condition_met? in the model. I thought it worked but if the fields were null or blank it failed.&lt;/p&gt;
&lt;p&gt;I will try a few more things and post the results here.&lt;/p&gt;
&lt;p&gt;Hamza&lt;/p&gt;</content>
    <author>
      <name>Hamza Khan-Cheema</name>
    </author>
  </entry>
  <entry>
    <link type="text/html" rel="alternate" href="http://hamza.khan-cheema.com/show/8-acts_as_taggable-with-different-language-tags"/>
    <id>http://hamza.khan-cheema.com/show/8-acts_as_taggable-with-different-language-tags</id>
    <title>acts_as_taggable with different language tags</title>
    <published>2006-06-28T00:00:00+03:00</published>
    <updated>2011-09-06T12:46:12+03:00</updated>
    <content type="html">&lt;p&gt;As part of my Rails project I needed to tag items in Chinese and in English. For obvious reasons I wanted to use the acts_as_taggable plugin (not the gem). I really like the way it works. It is very clean and elegant solution for tagging.However my problem was how do I distinguish a Chinese tag from an English tag. I came up with a few solutions. One being to use the geotagging formula which would translate to Chinese_tag:English_tag. Initially this seemed like a good idea, But, it does seem a bit tied down. What if a user wanted to tag it with an English tag, but not the corresponding Chinese tag ?&lt;/p&gt;
&lt;p&gt;So the simple solution I came up with was to add a language field (&lt;acronym title="2"&gt;&lt;span class="caps"&gt;VARCHAR&lt;/span&gt;&lt;/acronym&gt;) to the tag database. If it was a Chinese tag I would simply put &#226;&#8364;&#732;ch&#226;&#8364;&#8482; in the language and if it was English I would simply put &#226;&#8364;&#732;en&#226;&#8364;&#8482;&lt;/p&gt;
&lt;p&gt;Here is the actual change I made to the plugin :&lt;/p&gt;
&lt;pre&gt;
&lt;code class="ruby"&gt;
def tag_with(list, lang)
  Tag.transaction do
    taggings.destroy_all
    Tag.parse(list).each do |name|
      if acts_as_taggable_options[:from]
         send(acts_as_taggable_options[:from]).tags.find_or_create_by_name(name).on(self) 
      else
        begin
          tag_find = Tag.find_by_name_and_language(name,lang).on(self) 
        rescue
          Tag.create(:name =&amp;gt; name, :language =&amp;gt;lang).on(self) 
        end
      end 
    end 
  end 
end
&lt;/code&gt;
&lt;/pre&gt;
&lt;p&gt;As you can see this method takes an extra parameter &#226;&#8364;&#732;lang&#226;&#8364;&#8482;. The change has been made in the else statement. It tries to find the tag with the language. If that fails then it creates the tag. This replaced a simple Tag.find_or_create_by_name(name).on(self)Its as simple as that. The tag_with method now accepts and saves the language field.&lt;/p&gt;
&lt;p&gt;I also implemented these methods which are self explanatory :&lt;/p&gt;
&lt;pre&gt;
&lt;code class="ruby"&gt;
 def tag_chinese_list
    tags.collect {|tag| tag.name.include?(" ") ? "'#{tag.name}'" : tag.name if tag.language =="ch" }.join(" ") }
end
&lt;/code&gt;
&lt;/pre&gt;
&lt;p&gt;The above method simply retrieves all of the Chinese tags. I have a similar one for English. I also added a find_tagged_with_chinese method. This is just a copy of the original find_tagged_with method with an extra &lt;span class="caps"&gt;AND&lt;/span&gt; language =&#226;&#8364;&#157;ch&#226;&#8364;&#157; at the end.&lt;/p&gt;
&lt;p&gt;I should really re-factor the code. For example making the tag_list take a language parameter.&lt;/p&gt;
&lt;p&gt;I hope this helps someone.&lt;/p&gt;
&lt;p&gt;Hamza&lt;/p&gt;</content>
    <author>
      <name>Hamza Khan-Cheema</name>
    </author>
  </entry>
  <entry>
    <link type="text/html" rel="alternate" href="http://hamza.khan-cheema.com/show/7-FCKeditor-on-Rails"/>
    <id>http://hamza.khan-cheema.com/show/7-FCKeditor-on-Rails</id>
    <title>FCKeditor on Rails</title>
    <published>2006-06-01T00:00:00+03:00</published>
    <updated>2011-09-07T01:06:25+03:00</updated>
    <content type="html">&lt;p&gt;Hi again,&lt;/p&gt;
&lt;p&gt;I found myself needing a &lt;span class="caps"&gt;WYSIWYG&lt;/span&gt; editor for the rails app I am developing. I thought FCKeditor is great. I installed it by following these &lt;a href="http://www.joshuamcharles.com/rails/fckeditor.htmlAll"&gt;instructions&lt;/a&gt; was well, but I could not get the file upload interface to work under Rails. So I did some searching and came across this &lt;a href="http://www.underpantsgnome.com/projects/fckeditor-on-rails/"&gt;project&lt;/a&gt;. Michael Moen had got it all to work very nicely.&lt;/p&gt;
&lt;p&gt;FCKeditor is fully integrated into my app. Nice!&lt;/p&gt;
&lt;p&gt;Hamza&lt;/p&gt;</content>
    <author>
      <name>Hamza Khan-Cheema</name>
    </author>
  </entry>
  <entry>
    <link type="text/html" rel="alternate" href="http://hamza.khan-cheema.com/show/6-Progress%21"/>
    <id>http://hamza.khan-cheema.com/show/6-Progress%21</id>
    <title>Progress!</title>
    <published>2006-04-04T00:00:00+03:00</published>
    <updated>2011-09-07T01:06:46+03:00</updated>
    <content type="html">&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I have made a lot of progress with Ruby on Rails. I have to say that I have taken a real liking to this framework. I have to applaud the Rails team and community.As is expected I have come across a few difficulties. But I have always got a answer on the Rails mailing list. Any big software project needs to have such a community to back it up, otherwise new people will never come on the scene.&lt;/p&gt;
&lt;p&gt;Hopefully my next post will run through a small tutorial of editing and saving a &lt;span class="caps"&gt;HTML&lt;/span&gt; Form using &lt;span class="caps"&gt;RJS&lt;/span&gt; templates. It is unbelievable easy.&lt;/p&gt;
&lt;p&gt;Hamza&lt;/p&gt;</content>
    <author>
      <name>Hamza Khan-Cheema</name>
    </author>
  </entry>
  <entry>
    <link type="text/html" rel="alternate" href="http://hamza.khan-cheema.com/show/5-Ruby-on-Rails-First-Thoughts"/>
    <id>http://hamza.khan-cheema.com/show/5-Ruby-on-Rails-First-Thoughts</id>
    <title>Ruby on Rails First Thoughts</title>
    <published>2006-03-31T00:00:00+03:00</published>
    <updated>2011-09-07T01:07:09+03:00</updated>
    <content type="html">&lt;p&gt;Well my head has been in RoR for about 4 days. I have to say I have found it quite difficult to learn. I think that is because I have been relying on tutorials and wiki entries. I think if I would have read the &lt;a href="http://www.pragmaticprogrammer.com/titles/rails/index.html"&gt;rails book&lt;/a&gt; things would be alot easier (but slower ?). I have not got to grips with it fully. I am still trying my best to learn some of the inner workings.Rails 1.1 was released a couple of days ago. It has a bunch of cool new features. But I am not sure I am at the stage of using half of the features. Nevertheless I have upgraded :) with a little bit of difficulties. This was due the version of Ruby I had was not supported. I had version 1.8.3, put that is not supported and because I was Ubuntu, I found it difficult to update it.&lt;/p&gt;</content>
    <author>
      <name>Hamza Khan-Cheema</name>
    </author>
  </entry>
  <entry>
    <link type="text/html" rel="alternate" href="http://hamza.khan-cheema.com/show/4-Ruby-on-Rails"/>
    <id>http://hamza.khan-cheema.com/show/4-Ruby-on-Rails</id>
    <title>Ruby on Rails</title>
    <published>2006-03-13T00:00:00+03:00</published>
    <updated>2011-09-07T01:07:25+03:00</updated>
    <content type="html">&lt;p&gt;Although you may have gathered I am looking into Python frameworks. I have just been asked at work, if we can use Ruby on Rails as a platform to develop a pilot project we are developing. (I can&#226;&#8364;&#8482;t give any details, just to say that it will be a bilingual site :)So this leaves me with learning two very different frameworks and languages. Such is life. I can say that the documentation for Rails is awesome, compared to TurboGrears.&lt;/p&gt;
&lt;p&gt;It is going to be an interesting few months &#226;&#8364;&#166;&lt;/p&gt;</content>
    <author>
      <name>Hamza Khan-Cheema</name>
    </author>
  </entry>
  <entry>
    <link type="text/html" rel="alternate" href="http://hamza.khan-cheema.com/show/3-Very-Interesting-Forum-Post"/>
    <id>http://hamza.khan-cheema.com/show/3-Very-Interesting-Forum-Post</id>
    <title>Very Interesting Forum Post</title>
    <published>2006-03-03T00:00:00+03:00</published>
    <updated>2011-09-07T01:07:42+03:00</updated>
    <content type="html">&lt;p&gt;I have just been reading a very &lt;a href="http://www.artima.com/forums/flat.jsp?forum=106&amp;amp;thread=146149&amp;amp;msRange=15"&gt;interesting forum post&lt;/a&gt; concerning Python Frameworks. It has a number of views from different python camps.&lt;/p&gt;
&lt;p&gt;Hamza&lt;/p&gt;</content>
    <author>
      <name>Hamza Khan-Cheema</name>
    </author>
  </entry>
  <entry>
    <link type="text/html" rel="alternate" href="http://hamza.khan-cheema.com/show/2-So-Far"/>
    <id>http://hamza.khan-cheema.com/show/2-So-Far</id>
    <title>So Far</title>
    <published>2006-02-28T00:00:00+03:00</published>
    <updated>2011-09-07T01:08:03+03:00</updated>
    <content type="html">&lt;p&gt;Hi.&lt;/p&gt;
&lt;p&gt;I have read a very interesting post about the Pylons framework here. It is done by one of its creators. The analysis is very detailed. But the analysis confirms my initial concerns that Pylons is not really there yet, but they are going in the right direction, especially with support for PasteFor those of you that don&#226;&#8364;&#8482;t know. TurboGrears have released their infamous 0.9a release It has a lot of new features, which all look very cool indeed.&lt;/p&gt;
&lt;p&gt;I think along with this release and with the experimental support for sqlalchemy TurboGears is going in the right direction for me. I have decided that this will be the first python framework that I will play about with :).&lt;/p&gt;
&lt;p&gt;I will probably try an make that 20 minute wiki first, so i can get a feel for the framework.&lt;/p&gt;
&lt;p&gt;Hamza&lt;/p&gt;</content>
    <author>
      <name>Hamza Khan-Cheema</name>
    </author>
  </entry>
  <entry>
    <link type="text/html" rel="alternate" href="http://hamza.khan-cheema.com/show/1-Python-Frameworks"/>
    <id>http://hamza.khan-cheema.com/show/1-Python-Frameworks</id>
    <title>Python Frameworks</title>
    <published>2006-02-26T00:00:00+03:00</published>
    <updated>2011-09-06T12:47:50+03:00</updated>
    <content type="html">&lt;p&gt;I have been recently thinking about Rapid Application Development (&lt;span class="caps"&gt;RAD&lt;/span&gt;) web frameworks. My requirements are:&lt;/p&gt;
&lt;ol&gt;
	&lt;li&gt;Must be a scripting language to facilitate &lt;span class="caps"&gt;RAD&lt;/span&gt;.&lt;/li&gt;
	&lt;li&gt;Ideally I would like to use Python as the programming language.&lt;/li&gt;
	&lt;li&gt;Allow the admin backend to be generated automatically&lt;/li&gt;
	&lt;li&gt;Easy/clean &lt;span class="caps"&gt;API&lt;/span&gt;&lt;/li&gt;
	&lt;li&gt;Good community&lt;/li&gt;
	&lt;li&gt;open source&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Below are the frameworks I am thinking of (in no order) :&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;Django&lt;/li&gt;
	&lt;li&gt;Turbogears&lt;/li&gt;
	&lt;li&gt;pylons&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I have also been looking into less &#226;&#8364;&#732;Magic&#226;&#8364;&#8482; frameworks. These include:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;web.py&lt;/li&gt;
	&lt;li&gt;Colubrid&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Ideally I suppose the answer would be to develop projects in all of the above programs and pick one that suits me. However this is a large task, which is impossible to do in my spare time, due to family commitments.&lt;/p&gt;
&lt;p&gt;Hopefully I should be able to post to this blog when I have made a choice on which one to go for. I will then be able to keep a kind of diary of my experiences. I hope this will help other people who are in the same dilemma.&lt;/p&gt;
&lt;p&gt;Just another point that may interest you (or not). I am currently a Java developer. I use Java Servlets and &lt;span class="caps"&gt;JSP&lt;/span&gt; every day for my job.&lt;/p&gt;
&lt;p&gt;I would love to hear other peoples input on which Python web framework they use and why.&lt;/p&gt;
&lt;p&gt;Hamza&lt;/p&gt;</content>
    <author>
      <name>Hamza Khan-Cheema</name>
    </author>
  </entry>
</feed>

