First six months of 2011

The first half of 2011 was intense and super inspiring!

I worked plenty of hours and I liked it.

I shipped my first official Rails project and started another. I loved it! Rails manages to to serve me with a full stack, high level web framework but at the same time doesn’t hide the low level stuff, doesn’t get in the way and gives me freedom to solve customer business problems.

I also hacked on a personal project based on Sinatra, perfect for situations where you don’t need the full stack of Rails.

I deployed to heroku and I absolutely loved it! Heroku is all that and a bag of cookies! Even more so now that they expand beyond Ruby.

I shipped my first official MongoDB project. A great experience and I’d love to learn more about when to use a SQL db, when not to and how to properly design for noSQL.

I learned a bit of python hacking on a Django project. I would recommend you use Ruby/Rails instead. Django is a hack compared to rails. It is left behind, has none of the test tools of Rails, no cloud hosting (at least not on par with the rails hosting). Languages are a matter of personal taste, me and python has issues..

Oh yeah! Also! Winning the the first 24h computer programming comp I’ve ever entered was awesome! :-)

Posted in Tech | Tagged , , , | Leave a comment

Room for improvement: Online payments.

I’ve come to understand that many of my friends who are not computer savvy hesitate to use their credit/debit card(s) for online payments. I can understand this. It is not from lack of available security implementations that they rather pay more and be invoiced.

It is all to do with perception and user experience. Perhaps they’ve had a bad experience with earlier bad implementations and stolen user databases that has plagued the business. Perhaps they often, like me, find online stores to be cumbersome, sluggish, awkward and user unfriendly.

Two major areas needs improvement

  1. There is no excuse for poor security implementations. We have the tools, lets use them!
  2. The user experience needs major improvement! It should be simplified and it should feel fun to buy stuff!

Security

We have SSL. Lets use it.

We know how to store user information in a secure way, hash it, salt it, persist it! But only if you really need to! If there’s no real benefit for the either the end user or you as an online store to persist, then don’t.

User Experience

When I tried (yes, tried and failed) to purchase a book online this morning I was guided through this path of interaction:

  1. Clicked on a Add-to-cart-button next to the book I wanted to purchase.
  2. Clicked on shopping cart icon.
  3. Clicked check out.
  4. Entered my details such as name, address, phone number(s), country, email etc for online store.
  5. Clicked check out with paypal.
  6. Entered my details such as name, address, phone number(s), country, email and card details for paypal.
  7. Was told that paypal was not able to use my VISA card. This I think is because my bank provides me the service of limiting the use of my card to scandinavian countries. They also, free of charge, offer me something called Verfied by VISA, a ‘security service’ which requires end users to enter a second PIN number.
  8. Tried American Express card instead only yo find out that paypal could not use that card either. I don’t know why since I use it on a regular basis for all kinds of other purchases like taxi rides and clothes.
  9. Gave up.

We live in a global, capitalistic world, there is no reason why my cards should be limited to a country or region!

There is no excuse for online stores who forces their users to enter their details twice! It leads to very poor user experience making users less likely to come back.

The globalization of consumerism leads me to thinking that the bitcoin people just might be on to something.. In an increasingly smaller and faster world there is an increaslingly larger need for a slimmer, more agile middle man (bank). Bitcoin might be something, it is just that there is so much more in money than numbers. The real value lies in the trust of the currency.

Meanwhile, lets make online shopping something pleasant and fun! ☺

Posted in Tech | Tagged , , , , | Leave a comment

Creating your first cucumber test with rails 3

When creating a new rails app you can skip the unit tests skeleton by passing the -T arg, what more, we can tell it to use mysql as a database backend, like so:

rails new testapp -T -d mysql

Add rspec and cucumber gems to Gemfile

group :development, :test do
  gem 'rspec-rails'
  gem 'cucumber-rails'
  gem 'capybara'
  gem 'database_cleaner'
end

Download and install all needed gems:

bundle install

Install RSpec and cucumber

rails generate rspec:install
rails generate cucumber:install --rspec --capybara

Here I specify that I want capybara as the driver for my web tests.

Now, lets specify our first feature! Copy this text snippet and store it in feature/browse_articles.feature

Feature: Browse articles

  So that I can browse through the articles
  As a visitor
  I want to be able to see an article from a full list of articles and read it

  Scenario: Browsing a list of articles
    Given an article with the title "stickad tröja"
    And an article with the title "stickad mössa"
    When I am on the articles page
    Then I should see "stickad tröja"
    And I should see "stickad mössa"

Setup your database like so:

rake db:migrate ; rake db:setup

Now, if we run our test, like so:

bundle exec rake cucumber

…Cucumber will tell us that:

You can implement step definitions for undefined steps with these snippets:

Given /^an article with the title "([^"]*)"$/ do |arg1|
  pending # express the regexp above with the code you wish you had
end

Soo.. lets do just that! Implement your first step definition by entering the following text snippet into features/step_definitions/browse_articles_steps.rb

Given /^an article with the title "([^"]*)"$/ do |text|
  Article.create! :title => text
end

Create routes for your new article type by adding the following to your config/routes.rb file

resources :articles

If running the cucumber tests now you’ll see it fails cause we do not yet have a Article model. Lets create it!

rails g model article title:string
rake db:migrate
rake db:test:prepare

We will also need a controller for our articles so lets create that too:

rails generate controller articles

Add a simple index method to it:

def index
    @articles = Article.all
end

For the test to be able to see the created articles we’ll need a view so lets create app/view/articles/index.html.erb and put this in it:

 <ul>
    <% @articles.each do |article| %>
      <li><%= article.title %></li>
    <% end %>
  </ul>

We can now run our cucumber scenario:

bundle exec rake cucumber

and we should see something along the lines of:

Feature: Browse articles

  So that I can browse through the articles
  As a visitor
  I want to be able to see an article from a full list of articles and read it

  Scenario: Browsing a list of articles             # features/browse_articles.feature:7
    Given an article with the title "stickad tröja" # features/step_definitions/browse_articles_steps.rb:1
    And an article with the title "stickad mössa"   # features/step_definitions/browse_articles_steps.rb:1
    When I am on the articles page                  # features/step_definitions/web_steps.rb:44
    Then I should see "stickad tröja"               # features/step_definitions/web_steps.rb:105
    And I should see "stickad mössa"                # features/step_definitions/web_steps.rb:105

1 scenario (1 passed)
5 steps (5 passed)
0m1.544s
Posted in Tech, Uncategorized | Tagged , , , | 1 Comment

Remove trailing slash using apache mod_rewrite

Either I’m a poor googler or there are is no proper instruction on how construct a decent RewriteRule to remove trailing slash from URL’s in apache using mod_rewrite.

Anyho, here’s my recipe for just that.

RewriteRule ^(.+)/(\?.+)?$ $1$2 [R=301,L]

This captures two groups of characters with a “/” in between. The first group contains the base URL. The second groups is optional and contains eventual request parameters.

Here’s a spec to test it. (yes yes, I should test it using perl since that is what apache uses for regexps, but ruby’s regex is not too far from perls.)

require 'rspec'
class TrailingSlashRemover
  def perform_removal(url)
    url.gsub(/^(.+)\/(\?.+)?$/, '\1\2')
  end
end
describe TrailingSlashRemover do
  before(:all) do
    @tsr = TrailingSlashRemover.new
  end
  it "it should remove the trailing slash" do
    url = "http://example.com/path/"
    result = @tsr.perform_removal(url)
    result.should == "http://example.com/path"
  end
  it "it should remove the trailing slash from url with params" do
    url = "http://example.com/path/?foo=bar"
    result = @tsr.perform_removal(url)
    result.should == "http://example.com/path?foo=bar"
  end
end

Comments? Improvements? Yes, please!

Posted in Tech | Tagged , , , , | Leave a comment

fatal: git-http-push failed

So you’ve cloned a git repository, made some really clever changes, commited them and now you want to push them upwards. And so you do ‘git push’ but it tells you #fail and it makes you a little bit sad but now that you’ve stumbled upon this blogpost you feel a tad better and also you’re just about to find out why it fails and how to fix it. neat!

It fails because you’ve cloned a repository using http and it is not possible to push using the http scheme. You need to either use git or https.

You fix it using the ‘git remote’ command. Lets say you cloned using this URL:    http://github.com/jtinfors/dotvim.git. You can find out by issuing ‘git remote -v’. Change it to git scheme like so: git remote set-url –push origin git@github.com:jtinfors/dotvim.git

Posted in Tech | Tagged , , | 2 Comments

Installing WinXP in VirtualBox on Ubuntu 10.10

NOTE: Microsoft has removed all but one windows XP virtual disks from their website. The only virtual disk still up there is the IE6 one.

I am a web developer/programmer. I use ubuntu-linux on my workhorse laptap. Many people do. Many more people do not. Often they use windows. Often they use old, less capable browsers. They are my customers. I Love my customers. I’d do anything for them. Among the things I do is to test all sites I develop in Internet Explorer 6, 7 and 8 (looking forward to start testing in IE9 as well).

Now, many people use ietester to verify their sites in all versions of IE but I find it not stable enough. Instead I use SUN’s Oracle’s open source virtualization software VirtualBox to run three instances of windows XP, one for each version IE. Microsoft is kind enough to lend us, the people, preinstalled virtual harddrives of their XP and Vista OS’s. They pre-pack a couple of harddrives with preinstalled versions of IE. Microsoft says they require Windows7 but I find they work perfectly fine in VirtualBox on ubuntu 10.10. The Windows XP OS license expire after three months after which you’ll have to reinstall. That’s all good and well, after all they come for free and, as we’ll soon see, the installation can be done on the command line and thus be scripted.

Installing WinXP in Virtualbox on Ubuntu 10.10.

First of all, start downloading the virtual harddrive you’re interested in. The URL to the images changes constantly (it’s microsoft what do you expect..) thus here’s a link to a google search which should lead you in the right direction http://tinyurl.com/4n5aob7.

The downloaded .exe file is actually a compressed rar archive and so you’ll need to install unrar in order to unpack it. You’ll also need virtualbox itself and their guest additions (provides for smoother integration with host OS). Open up a terminal window and execute:

sudo aptitude -y install unrar virtualbox-ose virtualbox-guest-additions

In that same terminal window, enter the following commands to create and start up your new virtual machine. I’ve downloaded the harddrive prepared with Internet Explorer 8 thus I have choosen the name “ie8″ for my virtual machine, choose a name that suites your personal preferences. The command below assumes that the downloded harddrive “~/Downloads/IE8-on-XPSP3.exe”. NOTE: Speed-Tip: copy-paste all commands below into a script file, edit to suite your configuration and execute.

mkdir -p ~/.VirtualBox/HardDisks/
unrar x -xReadMe.txt -xVPC_EULA.txt -c- -o+ ~/Downloads/IE8-on-XPSP3.exe ~/.VirtualBox/HardDisks/
UUID=`VBoxManage internalcommands sethduuid ~/.VirtualBox/HardDisks/WinXPIE8.vhd | grep UUID | awk '{print $4}'`
VBoxManage createvm --name ie8 --ostype WindowsXP --register --uuid $UUID
VBoxManage storagectl $UUID --name "IDE Controller" --add ide
VBoxManage storageattach $UUID --storagectl "IDE Controller" --port 0 --device 0 --type hdd --medium WinXPIE8.vhd
VBoxManage storageattach $UUID --storagectl "IDE Controller" --port 1 --device 0 --type dvddrive --medium /usr/share/virtualbox/VBoxGuestAdditions.iso
VBoxManage modifyvm ie8 --memory 1024
VBoxManage startvm ie8
  • Log in with password “Password1″
  • NOTE: Click “No” or “Cancel” at anything that pops up. Installing proper network drivers is essential to get done prior to first reboot!

In windows, open up the windows control panel and at least set the keyboard layout to match your hardware as we’ll enter some commands in the “cmd” in the next step. You might want to set display size as well.

  • Open up the “cmd” application and execute: D:\VBoxWindowsAdditions-x86.exe /extract /D=C:\Drivers

Go back to the control panel and configure the network card, point the wizard to the location of the driver extracted in the previous step; C:\Drivers\x86\Network\AMD

Reboot and activate.

There is more neat thing that will make life in the virtual world a tad smoother and that is to install the other guest additions (we used the network driver from guest additions above). The guest additions gives us mouse integration, video driver and what-not.
When the virtual machine is up and running, click “Device” in the menu and then click “Install Guest Additions..”. Click “Next” and “Continue” until done.

Expired license

As I mentioned above the license will expire after 3 months and the virtual machine will have to be reinstalled. This is easily done by simply removing the virtual machine and remove the contents of the VirtualBox folder in your homedir.

VBoxManage storagectl ie8 --name "IDE Controller" --remove
VBoxManage unregistervm ie8 --delete
rm -rf ~/.VirtualBox

After that, simply redo the installation steps above.

~/Downloads/IE8-on-XPSP3.exe
Posted in Tech | Tagged , , | 1 Comment