I had blogged about my recent open-source project, a Ruby wrapper for the Alibris API, ruby-alibris. Soon after, Alibris had announced their First Annual Alibris API Programming Contest, and I submitted the ruby-alibris project as an entry. And, to my surprise, I got notified that it won the “Most Developer-Friendly Code”, and a $250 cash prize. Today, Alibris released a press release announcing the winners. Here is an excerpt from the press release:
read more…
After spending about an hour, reams of pages, and pails of ink, I finally stumbled into the magic of booklet printing. My source document was a MS-Word 2010 document with 18 pages, which I wanted to print as a 2-sided, 2-pages per sheet, booklet on Letter paper. Although, MS-Word comes with an option to print a document as a booklet as shown below,
it is impossible to get it right, the way you expect it. It would print page 1 and 7 one side of the sheet, while you would expect it to print 1 and a blank. Just tried every other possibility, even with odd numbered pages, but I had no luck.
Finally, I was try to do something which made me convert the Word doc into a PDF document, and I found the solution. Acrobat Reader has a Booklet option that works! So here is what I did…
Take the Word document and Save As… a PDF document right from Word. Then open up the PDF document in Acrobat Reader, and click File -> Print. The screenshot below shows the print dialog with the settings highlighted:
As you can notice, the settings are very clear. Also notice that you can see the expected results in the preview but I only wish you could zoom in to see the page numbers. But, what the heck, it works.
The next important thing to remember before you print is that, unlike Word or other booklet printing options, Acrobat Reader will just print all the pages without asking you to flip the page to the other side. It expects that you print one page at a time and then flip it to the other side, and continue so and so forth. When you flip the page, just remember you need to make sure the keep the blank side up, and top side should still be top. To make it easier to understand, I drew a simple diagram:
Now, put one single sheet of paper at a time in the printer, print one side, flip to the other side, print and stack away. After all the sheets are printed, just fold the sheets through the center, stack them in order, staple in the middle, and you have your booklet.
Hopefully you read this post, before you wasted a lot of pages and ink and saved yourself a lot of frustration. Happy printing!
I recently wrote a Ruby wrapper (ruby-alibris) for the Alibris API. I started with the Search API, and I would finish the wrapper with the Recommendations and Reviews shortly. Read the documentation below and give it twirl. I would be interested in your comments and feedback. Alibris, is the premier online marketplace for independent sellers of new and used books, music, and movies, as well as rare and collectible titles.
You can download the ruby-alibris gem at https://rubygems.org/gems/ruby-alibris, and you can take a look at the source code at https://github.com/rupakg/ruby-alibris.
Installation
1 | gem install ruby-alibris |
Features
The Alibris API consists of three main features, namely:
This wrapper library provides access to that functionality in an easy and intuitive manner.
The Search Method
The Search object wraps up the Search method of the Alibris API. The results that are returned are called ‘works’ in Alibris’ terminology. The ‘works’ are of types books, music and videos. The Search object can search across all types of works or specifically against books, music or videos. The search object provides convenient helper methods for other operations like search by author, by title and by topic.
You can find more about the Search method at Alibris’ site.
Usage
The Search object can be instantiated by providing the Alibris API key, and optionally the output type and the number of results that the search should return. The allowed output types are xml and json, xml being the default, while the default number of results returned is 25.
Require the wrapper library:
1 | require 'alibris' |
For example, to create a Search object with output type set to ‘json’, and limit number of results returned to the default value of 25, do:
1 | s = Alibris::Search.new(:api_key => "your_alibris_api_key_here", :output_type => "json") |
And, to create a Search object with output type set to ‘json’ and limit number of results returned to 10, do:
1 | s = Alibris::Search.new(:api_key => "your_alibris_api_key_here", :output_type => "json", :num_results => 10) |
Let’s see some examples, for searching books:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | # search for books by search term results = s.books("photography") results.work.first.title # => "Making Movies" results.work.first.author # => "Lumet, Sidney" # search for books by author results = s.books_by_author("Dan Brown") results.work.first.title # => "The Lost Symbol" # search for books by title results = s.books_by_title("The Fountainhead") results.work.first.author # => "Rand, Ayn" # search for books by topic results = s.books_by_topic("Religion") results.work.last.author # => "Hardwick, Susan" results.work.last.title # => "God of freedom" |
The Search object adds some functionality by taking values passed via options, as follows:
a) sorting options: {:qsort => value}, which can be,
- r = rating/price (books searches only), default
- t = title, tr = title reverse
- a = author, ar = author reverse
- p = price, pr = price reverse
- d = date (year), dr = date reverse
b) number of results returned: {:chunk => integer}
c) number of results to skip: {:skip => integer}
And, some more examples using options as described above:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | # search for books by author and sorted by title results = s.books_by_author("Dan Brown", {:qsort => 't'}) results.work.last.author # => "Brown, Dan, and Spence, Cathryn" results.work.last.title # => "Bath: City on Show" # search for books by author and sorted by title in reverse results = s.books_by_author("Dan Brown", {:qsort => 'tr'}) results.work.last.author # => "Brown, Dan" results.work.last.title # => "The Da Vinci Code: Illustrated Screenplay" # search for books by author and sorted by title, with only 10 results returned results = s.books_by_author("Dan Brown", {:qsort => 't', :chunk => 10}) results.work.last.author # => "Birlew, Dan, and Brown, Damon" results.work.last.title # => "Resident Evil 4" |
Similarly, some examples, for searching music:
1 2 3 4 5 6 7 8 | # search for music by search term results = s.music("rock") results.work.first.title # => "Live at the Troubadour" results.work.first.author # => "Carole King & James Taylor" # search for music by author results = s.music_by_author("The Beatles") results.work.last.title # => "With the Beatles" |
Similarly, some examples, for searching videos:
1 2 3 4 5 6 7 8 | # search for videos by search term results = s.videos("kids") results.work.first.title # => "The Kids Are All Right" results.work.first.author # => "Lisa Cholodenko" # search for videos by author results = s.videos_by_author("Lisa Cholodenko") results.work.last.title # => "Laurel Canyon" |
Note: You can apply the options for sorting, number of results returned and number of results skipped as described for books to music and videos as well.
Roadmap
- Implement the other methods from Alibris API:
- Recommendations method
- Reviews method
- Update the wrapper library to work with output type ‘xml’. Currently, only ‘json’ is supported.
“CoffeeScript is a little language that compiles into JavaScript. Underneath all of those embarrassing braces and semicolons, JavaScript has always had a gorgeous object model at its heart. CoffeeScript is an attempt to expose the good parts of JavaScript in a simple way.The golden rule of CoffeeScript is: “It’s just JavaScript”. The code compiles one-to-one into the equivalent JS, and there is no interpretation at runtime. You can use any existing JavaScript library seamlessly (and vice-versa). The compiled output is readable and pretty-printed, passes through JavaScript Lint without warnings, will work in every JavaScript implementation, and tends to run as fast or faster than the equivalent handwritten JavaScript.”
1 | brew install node.js |
1 | export NODE_PATH="/usr/local/lib/node_modules" |
1 | curl http://npmjs.org/install.sh | sh |
1 | npm install -g coffee-script |
1 | $ coffee |
1 | coffee> |
1 | coffee> square = (x) -> x * x |
1 | [Function] |
1 | coffee> square(2) |
1 | 4 |
1 | square = (x) -> x * x |
1 | $ coffee -c test.coffee |
1 2 3 4 5 6 | (function() { var square; square = function(x) { return x * x; }; }).call(this); |
1 | $ coffee -c -o js --watch source |
- Syntax highlighting with a color settings preference pane
- Commenting and uncommenting of line and block comments
- Highlighting of matching braces
If you are like me, I started my Ruby on Rails development on Windows and I had my issues with installing the stack. I had issues with gems especially the ones with C-extensions. But, things have changed dramatically over the years and things are much smoother now. A great example of getting the Rails stack installed on Windows is: Rails Installer.
The Rails Welcome Kit has everything you need to hit the ground running. In one easy-to-use installer, you get all the common packages needed for a full Rails stack. Download it now and be writing (and running) Rails code in no time. Packages included are:
- Ruby 1.8.7-p330
- Rails 3.0.3
- Git 1.7.3.1
- Sqlite 3.7.3
- DevKit
Watch the RailsInstaller Introduction from Engine Yard on Vimeo.
We are happy to bring you the Issue #7, 2010 of Rails Magazine. We are trying our best to fall into a regular publishing schedule. In this edition, we have a very nice collection of articles. I am also very happy to have penned down the editorial for this edition.
In the 28-pages of full color, we bring you the following:
- Editorial by Rupak Ganguly
- An Overview of Refinery – a Rails CMS by David Jones
- Converting A Rails Site to Refinery CMS by Christopher W. Lehman
- Auditing plugin by Mihai Târnovan and Gabriel Târnovan
- Hobo – Making Application Development on Rails Even Faster by Dave Reynolds
- Installing Ruby on Rails on Windows by Victor Thiago
- Simple Unobtrusive Ruby/Rails Debugging by Stephen Rycyk
- A Well Kept Secret, Ruby and Cryptography by Richard Penwell
The digital edition (PDF) is available for free at http://www.railsmagazine.com/issues/7. You can also grab a printed copy available in US, UK and Canada (7.60 USD + shipping).
Download the free digital edition of Rails Magazine Issue #7.
I am very happy to announce the release of the Rails Magazine Issue #6. It took us a while to get this issue out but it is better late than never. We improved a lot on the backend side and revamped into a new automated publishing system. This will in future enable us to streamline the author submission, editing and publishing process. Olimpiu and Raluca Metiu, the husband/wife combo, worked very hard to get the new publishing system up.
In this beautiful 36-pages full color issue you will find some very in-depth articles and a couple of nice interviews. The issue consists of the following:
- Beautifying Your Markup With Haml and Sass by Ethan Gunderson
- Scaling Rails by Gonçalo Silva
- Interview with Sarah Allen by Rupak Ganguly
- Data Extraction with Hpricot by Jonas Alves
- Deployment with Capistrano by Omar Meeky
- Fake Data – The Secret of Great Testing by Robert Hall
- RubyConf India 2010 coverage by Judy Das
- Previous and Next Buttons by James Schorr
- RVM – The Ruby Version Manager by Markus Dreier
- Interview with Michael Day of Prince XML by Olimpiu Metiu
The digital edition (PDF) is available for free at http://www.railsmagazine.com/issues/6. You can also grab a printed copy available in US, UK and Canada (8.80 USD + shipping).
Download the free digital edition of Rails Magazine Issue #6.
Steve Jobs announced the arrival of iPhone 4 at WWDC today. The highlights of the iPhone 4 are as below:
1. New Hardware Design: Front and back camera with flash, 2 mics, integrated antennae, and 24% thinner. Quad band HSDPA, 7.2Mbps, 802.11n WiFi, GPS, compass, accelerometer.
2. Retina Display: Four times as many pixels, 326 pixels per inch (300 is the limit for the retina!), 3.5 inch display, 960 x 640 pixels, 326 pixels per inch, 800:1 contrast ratio, IPS technology (better than OLED)
3. iPhone 4 is powered by the A4 chip: Micro-SIM, larger battery – improved battery life – 7 hours of 3G talk, 6 hours of 3G browsing, 10 hours of WiFi browsing, 10 hours of video, 40 hours of music and 300 hours of standby.
4. Gyroscope: 3 axis gyro, the gyro tied to accelerometer, compass together for six axis. pitch, roll, yaw. rotation about gravity, 6-axis motion sensing.
5. New Camera system: 5 megapixel, backside illuminated sensor. 5x digital zoom, tap to focus, and an LED flash. Records HD video – 720p at 30 fps. LED flash stays for video recording. You can record, edit and email right from the iPhone. iMovie for iPhone at $4.99.
6. iOS 4: iPhone OS4 aptly renamed to iOS4. You can see the features in another post I wrote earlier.
7. iBooks: Bookshelf, PDF reader, iBookstore
8. iAds: Apple’s ad network, comes on live on July 1st, 2010 for all iOS 4 devices.
9. FaceTime: Video calls on iPhone. WiFi only. iPhone 4 to iPhone 4. No setup. Camera can be flipped to the rear or front. Portrait or Landscape. This has to be the all time, life-altering, feature in any product…
Checkout all the features, the design, and the full technical specs of the new iPhone 4 phone at Apple. Last but not the least, see it for yourself in this video of the new iPhone 4 phone and the photo gallery in all its glory…
Availability: Pre-order starts on June 24th, 2010. “AT&T is going to make an incredibly generous upgrade offer. If your contract expires at any time in 2010, you can upgrade to the iPhone 4. You can get it up to six months early.”
Colors: White and black.
Pricing: iPhone 4 – $199 for 16GB, $299 for 32GB. iPhone 3GS – $99.
iOS 4 upgrades: For the 3G, not all the features are supported, same with the iPod touch, and this excludes the first generation. Upgrades are free for all these products. Available on June 21st, 2010.
Hat tip: Engadget and gdgt did a live coverage of the event. Thank guys, for your coverage for people like us, who could not attend in person.
I have been working on some Spree based ecommerce stores lately, and I ran into this issue while creating a new Spree project. I had bumped into this a while back but did not write about it then. But, now I have decided to pen it down.
The steps to creating a new Spree project is very simple. Assuming that you have Ruby and Rails both installed, you can simply do:
$ gem install spree
$ spree mystore
$ cd mystore
$ rake db:bootstrap
$ script/server
And, voila you should have a shiny Spree store.
But, I have bumped into an issue at the step $ rake db:bootstrap as shown below:
$ rake db:bootstrap (in c:/RoRProjs/wixspree) rake aborted! stack level too deep c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2390:in `raw_load_rakefile' (See full trace by running task with --trace)
After a little digging, I found out that Spree has a dependency on the ‘jeweler’ gem which in turn has some kind of dependency on Git.
So, although it seems like a weird solution but just by initializing a git repository on your Spree project folder i.e. mystore in my example, you will be happy to see that the problem is resolved.
So, to recap, in the above steps to create your new Spree project, add a new step before the rake step:
$ git init
$ rake db:bootstrap
You should be golden by now. Hope it helps.
Note: I am running Spree 0.9.4 on Windows Vista and Rails 2.3.5 and Ruby 1.8.6 (ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-mswin32])
Note: If you do not have Git installed, you might want to do that. Here are some excellent articles which show how to do it:
http://github.com/guides/using-git-and-github-for-the-windows-for-newbies
I was recently working on some code for building an extension for Spree, when I ran into an issue while generating a extension controller. The error only happens on Windows.
The error in the console looks like this:
$ ruby script/generate extension_controller PromotionManager admin/promotions c:/ruby/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/rails/gem_dependency.rb:119:Warning: Gem::Dependency# version_requirements is deprecated and will be removed on or after August 2010. Use #requirement Loading haml-edge gem. c:/ruby/lib/ruby/1.8/pathname.rb:709:in `relative_path_from': different prefix: "c:/" and "C:/RoRPro js/spreestore" (ArgumentError) from c:/ruby/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/rails_generator/lookup.rb:110:in `use_co mponent_sources!' from c:/ruby/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/rails_generator/lookup.rb:109:in `each' from c:/ruby/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/rails_generator/lookup.rb:109:in `use_co mponent_sources!' from c:/ruby/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/rails_generator/lookup.rb:55:in `include d' from c:/ruby/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/rails_generator.rb:38:in `include' from c:/ruby/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/rails_generator.rb:38:in `send' from c:/ruby/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/rails_generator.rb:38 from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require' from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require' from c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:1 56:in `require' from c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:5 21:in `new_constants_in' from c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:1 56:in `require' from script/generate:4
The error is specifically in this line:
c:/ruby/lib/ruby/1.8/pathname.rb:709:in `relative_path_from': different prefix: "c:/" and "C:/RoRPro js/spreestore" (ArgumentError)
After a little digging, it was evident that the ‘relative_path_from’ method in ‘/ruby/lib/ruby/1.8/pathname.rb’ file had the problem. The problem was also described as a ticket at http://redmine.ruby-lang.org/issues/show/1366 and the excerpt of the issue is shown below:
On Windows, the case of the drive letter can be either upper case or lower case (eg, "C:" or "c:") on the same machine at the same time in different Command Prompt Windows (see below for details). Dir.pwd will return either lower-case or upper-case for the drive letter (“C:/” or “c:/”) depending on the Command Prompt it is run from. However, FILE always uses lower-case drive letter. This can cause an ArgumentError when comparing Dir.pwd and FILE using Pathname#relative_path_from. This happens with version 1.9.1p0 as well. Pathname#relative_path_from should deal with the case where the case of the argument is different.
Note, that I have both my ruby install folder and my project folder on c: drive. And, I am running Ruby 1.8.6 - ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-mswin32]
Solution
I monkey-patched the following lines in pathname.rb file as shown below.
def relative_path_from(base_directory) dest_directory = self.cleanpath.to_s.capitalize! base_directory = base_directory.cleanpath.to_s.capitalize!
I added the capitalize! keyword at the end of the two lines so that both the paths are in uppercase, so that later in the code (line 708-710) shown below does not barf and give us the error we got shown in the first para. of the article.
if dest_prefix != base_prefix raise ArgumentError, "different prefix: #{dest_prefix.inspect} and #{base_directory.inspect}" end
The temporary solution works after the patch. Hope it helps.





















