header image

Archive for the 'Ruby' Category

The Sadly Neglected Pickaxe-killer

Wednesday, September 27th, 2006

I have just finished reading Ruby for Rails: Ruby techniques for rails developers from David A. Black. Here is my (WARNING: highly opiniated) review…

I have been a Python fanatic for quite some time, and decided to give Ruby a shot. After some googling, I found most references pointing to a book called the ‘Pickaxe’. Quite a strange name for a programming book, thought to myself, but picked it up nevertheless. I have been instantly converted after a few dozen pages - mining Ruby with the pickaxe was an awesome experience! Since then, I have finished reading the second edition and became a Ruby enthusiast.

After lurking around a bit, I have learned that the common standpoint is that every newcomer/beginner should grab a copy of the Pickaxe to get started. Based on my previous, positive experience I could not agree more - until I came across R4R.

Ruby for Rails is awesome: The technical depth is just right to not distract beginners, yet detailed enough for even the more advanced readers. I did not skip a single page (though years of programming experience and tons of similar programming books I came across during that time could allow me) and finished reading it in no time.

I could write some more about how cool this book is (and it would deserve every bit of it), but I think you can read about that just anywhere (a nice review can be found here), so I would like to point out something different: If we consider the Pickaxe THE book for newcomers, then IMHO R4R is a Pickaxe killer.

Don’t get me wrong: I am a great fan of the Pickaxe, which is another very high-quality technical book - but if someone wants to apply the ‘right tools for the right job’ principle, I think newcomers who already decided to learn Ruby should grab Ruby for Rails. Programming Ruby’s Part I is absolutely well suited to get the ‘feeling’ of Ruby, and it’s next chapters are great to learn the advanced stuff - however in my opinion, the leap between the first and the next chapters is too big for an absolute beginner. Ruby for Rails is there to fill this gap.

Maybe someone might not advice this book to a newbie eager to learn Ruby, since it has ‘Rails’ in it’s title. However, R4R is still primarily a Ruby book, and while I found the Rails parts to be very helpful, I can recommend it to anyone who would not like to learn Rails at all - though the full potential of the book comes through if one would like to learn both.

Conclusion: Ruby for Rails is an awesome book on Ruby. If you are beginner, would like to get a solid understanding of the Ruby principles, or your goal is to polish up your Ruby knowledge to grasp the Rails framework - R4R was made just for you! Check it out - you won’t be disappointed.

tags:

Announcing screen-scraping series

Wednesday, June 14th, 2006

I am planning to write a series of entries on screen scraping, automated Web navigation, deep Web mining, wrapper generation, screen scraping from Rails with Ajax and possibly more, depending on my time and your feedback. Since these entries are going to be longer, I will be posting them to separate pages, and announce them on my blog.

The first article is ready, you can read it here.

It is an introduction to screen scraping/Web extraction with Ruby, evaluation of the tools along with installation instructions and examples.

Feedback would be appreciated (leave your comment here/on the article page, or send me a mail at peter@[name of this site].com), I will update/extend the document and publish new ones based on your feedback.

tags:

Programming is hard

Sunday, June 11th, 2006

Programming is great fun (mainly with Ruby ;-) . However, this statement does not contradict with the fact that sometimes programming can be also hard. I came across a nice site today which can offer some help in these moments: Programming is hard. Judging from the size of Ruby/Rails/ActiveRecord tags (there is even a script.aculo.us tag!) it seems that it has a nice dose of Ruby/Rails stuff - solutions for common problems and also links to tutorials, frequenty asked nuby questions etc. Be sure to check it out!

tags:

Gems or Snakes?

Thursday, June 8th, 2006

After being a very happy Python programmer for 2 years, i have switched to Ruby a few months ago, and though Python is still my 2nd favourite language, i have never thought of going back to it for a second. In fact, this feeling was so natural that i did not even think about it’s reason for some time.

If someone compares these two languages just from the technical point of view, the difference is de facto non-existent. Both languages are built on similar principles, both of them serve essentially the same purpose. What is the secret sauce of Ruby then? Why did i get attracted to it immediately, past the point of no return? Here are a few points that came to my mind:

‘He is the ONE

  • If a beginner stumbles onto Ruby, there is ONE book he will be pointed to. The PickAxe.
  • If somebody asks which web framework should he use in Ruby, he will be pointed to a specific ONE: Ruby on Rails.
  • If he asks for a starter book on RoR, he will be advised to buy the coolest ONE: Agile Web Development with Rails.
  • If he asks for a discussion list/newsgroup, he will be pointed to the only ONE: ruby-talk.
  • If he looks for an XML processing library, he will be pointed to the standard ONE: REXML.

The list could go on and on…
A Rubyist with no previous Python experience may ask ‘Well, what’s so cool about this? It’s normal’. Well, i am glad that in Ruby is, but Python is a different story. I think it lacks the books like PickAxe and Agile Web Development with Rails, and also the community is divided up between Django, Turbogears, Pylons, Subway, … and the other dozen of web frameworks.
nice application of the DRY principle :-)

Rolling on Rails

If you would ask random people to summarize in one point why Ruby is so popular today, i am quite sure most of them would say ‘because of Ruby on Rails’. This framework is really that cool, believe it or not. Some people are already apostrophing it ‘the language/framework of web2.0′, pointing out that Rails is the next big thing in the web space.

Spread the word

A programming language is essentially a bunch of boring definitions: Some grammar, rules, constructs etc. Even if it is very very cool, no one will notice it unless it is evangelized. That’s why great stuff needs great evangelizators: Perl+Larry Wall. Microsoft+Bill Gates. Ruby+DHH. To follow the logic, i should have written Ruby+Matz. But i would not write Matz, just as i would not pair Python with Guido van Rossum in this sense. These smart gentlemen are really good at language crafting, but the analogy with Perl/Larry Wall stops here. Fortunately Ruby has a great evangelizator, too, although an ‘indirect’ one: David Heinemeier Hansson, who, in my opinion made Ruby really popular through the Rails framework.

Community

After a few dozen of mails, i have much much better experience with the ruby-talk ML than with python-tutor. Of course one should not judge based on a few dozen mails, but the Ruby community feels to me like a big family, whereas the Python community is more like a bunch of engineers in white suits. Matz’s ‘Why does Ruby suck’ kind of style appeals me much much more than Python’s agnostic approach - ‘Maybe it is not even sure that there is a problem - first you should define what do you think the term ‘problem’ means, anyway’ etc. Of course this rigorous style may appeal to some - but not for me.

Integration [with Java]

From the JRuby page: [JRuby is] A 1.8.2 compatible Ruby interpreter written in 100% pure Java
On the Jython page, i could not even find the compatibility with java - but according to the page, “The final release of Jython-2.1 occurred on 31-dec-2001″
For comparison: Ruby 1.8.2 is almost the latest stable, and JRuby’s last release was on 27-march-2006. JRuby makes also some Rails integration possible already, and the authors are focusing on other J2EE issues like calling EJBs etc.
I think in a world where Java is the king of the hill (at the moment), Java integration can be a deciding factor.

Goodies

T-shirts. Cofee Mugs. Baseball caps. Other kind of good-for-nothing junk - must haves for all geeks! Of course with their favourite stuff on it. Well, after looking on cafepress.com (and on google in general) Ruby is a winner again when compared to Python.

The list could continue on, but since this entry is already too long i am going to stop here ;-) Of course, as everything on this blog, this article reflects my opinion, my perception of Ruby/Python. If you think Python is better suited for you, i am not arguing or anything - it would not make sense. However, i think Ruby has much more potential to become widely accepted as a mainstream language right now than Python - and this, besides that i like to code in Ruby much more, will keep me in the Ruby camp for a long-long time…

tags:

Ruby on Rails is spreading like fire

Wednesday, May 31st, 2006

Just two weeks after Ruby on Rails was featured in the prominent Dr Dobb’s Journal, it gets into the limelight again, in even greater power than before: Guess who is staring at you from the frontpage of Linux Journal? Yes, it’s DHH… and the reason? The current issue is full of Ruby and Rails articles, tips and tricks etc. Read the full story at David’s blog.

tags:

WWW::Mechanize problem (probably Ubuntu only(?))

Tuesday, May 16th, 2006

I am working on a small screen-scraping utility written in Ruby, and since I have been working previously with RubyfulSoup, I wanted to give WWW::Mechanize a try this time.

So i have installed the WWW::mechanize gem:

sudo gem install mechanize

I wanted to try a ‘Hello world’ application first, to see wheter it works. Here are some official examples (click on ‘Examples’). I Copy&pasted the first one, run and got the following error:

/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:21:in
`require__': no such file to load -- net/https (LoadError)
from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:21:in `require'
from /usr/lib/ruby/gems/1.8/gems/mechanize-0.4.4/lib/mechanize.rb:15
...
...

After some googling i have found the answer: I had to install libopenssl-ruby, and the error was gone.

I wonder if you have to install this amount of additional packages on other distributions also? From the time I am using Ruby/Rails I did not have other distro than Ubuntu, but back in my Python days I have been running on gentoo and I don’t remember such problems. Ubuntu is really very cool, but it seems you have to know well which packages do you need and install them manually when it comes to coding/development…

tags:

Getting Ruby on Rails up and running on Ubuntu Dapper

Saturday, May 13th, 2006

I have just installed Ubuntu Dapper Drake Flight 6 on my desktop machine, and because I had had different problems to install Rails from scratch several times (even the recent session was no exception), I have decided to write a step-by-step guide, which assumes a clean, fresh install of Ubuntu ( i.e. at this point you do not even have Ruby on your machine) and leads you through installing Rails and creating a working test application. Why is this writeup better than any other how-to-install-rails tutorials out there?

  • Because it will tell you to install really just what you need, not 50 packages more
  • It will also show you how to configure the DB and other things to really make Rails work, not just installed

Let’s get started! Note: Some people asked if this manual is for dapper only. I would say mostly yes, because i have had different problems on breezy (for example i had to compile ruby-mysql driver manually). Its not entirely impossible that it will work with breezy - but then you will have to make sure that the packages are the same version as assumed here (e.g. MySQL > 5 etc.)

Part I: Installation

Prepare the system for the installation

  • Check /etc/apt/sources.list - make sure you have access to the ‘universe’ packages by uncommenting them:
deb http://us.archive.ubuntu.com/ubuntu dapper universe
deb-src http://us.archive.ubuntu.com/ubuntu dapper universe
  • Refresh apt packages to make sure you get the most up-to-date stuff:
sudo apt-get update
Install Ruby related packages
  • Install Ruby essentials: ruby, irb, rdoc, ri
sudo apt-get install ruby rdoc ri
  • Install gems: download, unpack, install
go to http://docs.rubygems.org/
download rubygems-0.8.11.tgz (or the latest version)  tar -xzvf rubygems-0.8.11.tgz
cd rubygems-0.8.11/
sudo ruby setup.rb
MySQL installation and configuration
  • Install MySQL:
sudo apt-get install mysql-server
  • Install ruby MySQL bindings
sudo apt-get install libmysql-ruby
Install Rails
sudo gem install rails --include-dependencies

Part II: Configuration

Setup the DB
  • Add an user, create a test database and grant acces for the user
mysqladmin -u root create test_development
mysql -u root
Into the db shell, write the following commands:
create user 'batman'@'localhost' identified by 'robin';
grant all on test_development.* to 'batman'@'localhost';
Don’t forget to replace the username/password (unless you happen to be Batman of course - in this case i suggest to use a different password since this can be guessed easily by social engineers ;-) Create and test the rails app
  • generate the app files
Lets denote your working directory (the root directory where your future rails project s will reside rails_projects).
cd rails_projects
rails test
  • edit config/database.yml
cd rails_projects/test 
vim config/database.yml
  • It should look like this:
development:
adapter: mysql
database: test_development
username: batman
password: robin
host: localhost
  • generate a dummy model
ruby script/generate model Dummy
  • edit the migration file
vim db/migrate/001_create_dummies.rb
class CreateDummies < ActiveRecord::Migration
def   self.up
  create_table :dummies do |t|
    t.column :foo,    :string
    t.column :bar,    :string
  end
end

def self.down
  drop_table :dummies
end
end
  • run the migration
rake db:migrate
  • generate a simple maintenance app
ruby script/generate scaffold Dummy Admin
  • start the server
ruby script/server

Point your browser to http://localhost:3000/admin to see the result. If you have any problems, please leave a comment, i will try to help you.

Internet contains huge number of opportunities to earn money online. Simply create a site that you think has the potential to sell hot items using ruby on rails. Register a relevant domain name and purchase a web hosting service through hostgator, one of the better web host out there today. Get a internet connection through one of the wireless internet providers to upload your site. Work on search engine optimization to get a better traffic and also use affiliate marketing program for the same reason. Finally get a free voip phone service to contact customers directly. The pc to phone system is the most effective method of marketing.
tags:

Fresh Meat - First Impressions of Agile Web Development with Rails (2nd ed) and Ruby for Rails

Thursday, May 4th, 2006

I have bought both books recently. Maybe it is a little bit early to write a review since I am through just a few chapters in both, I have been so impressed that I had to write a (not so) short entry at least ;-) ! I have been using C++/Java/Python for years, and have been reading as much books on every possible aspect of development with these languages as I could get. In my oppinion Ruby and Rails are absolutely superior to all of these languages (and their web frameworks/related things) in this context - The Pickaxe, AWDwR and R4R cover nearly all the things you will ever need to learn the language and Rails - and not just understand the ‘how’, but also the ‘why’, learn best practices, coding and development methodologies from code style to design issues, related technologies and more.

The point is not (only) this, since you can do the same with a few Java books (although not 3, but something like 10), however you will have harder time with Python (There is a Django book on the way, and also the Turbogears guys are publishing one but neither are out yet - but no PickAxe, AFAIK) - however, the point is, based on the experiences i have had with C++/Java/Python books that neither of them are so well written/to the point/effectively explained/well built up than the Ruby ones. Simply put: The Ruby/Rails books are the best technical books i have ever read on programming and (web) development.

AWDwR 2nd ed Agile Web Development with Rails, Second Edition I begun to develop the depot application with the first edition about a month ago, and since I was new to both Ruby and Rails, I have thought: WOW! I was about halfway through the depot chapter when i have noticed the announcement about the Second Edition a few days ago. I have purchased the pdf version immediately, and I am quite sure this purchase has to be listed in my ‘Best value for money TOP 10′ list (along with R4R ;-) . It was a very refreshing experience to code the depot application from the first edition, but as I got into Rails more and more, I have felt that there are some small gaps here and there. On the mailing list, everybody was talking about migrations (i had no clue that time about them), helpers, AJAX/RJS, REST and other stuff i was not able to find during the depot development, and though the amount of information and level of coolness was overwhelming, I still sensed there is still even more than this. After redoing the depot application with the second edition, all these things (among others) are finally there! You get all the goodies from the very beginning (migrations, writing your own helpers, AJAX etc) so you do not have to search the Web for the newest features anymore.My overall impression was that the small annoying things are gone, the good things are even better, thus the overall experience of reading the book/following the code is even more delightful! I can’t wait for the next chapters! This upgrade definitely rocks! Well done Dave et al.
Ruby for Rails Ruby techniques for Rails developers I have gone through just the firs three chapters so far, and though they are supposed to be introductory chapters (entitled How Ruby works, How Rails works and Ruby-informed Rails development) I could not believe how much info I got out of them. I have to say that I am a totally mega-n00b to both Ruby and Rails, but still, I have gone through the PickAxe and half of AWDwR, 1st ed, i am a regular reader of Ruby-talk and the RoR mailing lists, so on the other hand I have some basics, and still these chapters provided me a lot of new insight. The book (or at least the first three chapters) is extremely well written, easy to grasp yet the breadth of knowledge is really impressive. It really shows the design philosophy, logics, inner working of the things rather than just providing some theory with a few examples, or being a ‘yet another Ruby/Rails book’ in any way. If you would like to find out how the things really work, and why they work that way, rather than just be a developer who can do this and that with Rails, definitely check this book out! R4R

There was a kind of flamewar on the Ruby on Rails mailing list about the pricing of the AWDwR second edition: One group argued that they should get some discount because they own the first edition, and the other party did not agree with this standpoint. Well, personally I am definitely in the second group - I did not hesitate to buy the PDF for a moment - I can understand (but not support in any way) the arguments of the first group, but I would gladly pay for this book even $100, not $20+, regardless of the editions I own. (And just FYI, I am a full time Java developer and though I would like to get a Ruby (on Rails) job ASAP, due to different constraints RoR is and will be just my hobby for some time)

Just my 2c.

tags:

Announcing rubychallenge.com

Thursday, April 20th, 2006

About a month or so ago, we begun to work on a new ruby puzzle site entitled rubychallenge.com with Alex Combas.

Some people may think after reading this line: “Yet another ‘not pron’ or ‘pythonchallenge.com’ clone”. Well, i would not say we did not borrow some basic concepts from these great puzzle sites, but our final product will have not very much in common with them: There will be programming puzzles on rubychallenge.com, and the domain suffix is equal with that of the pythonchallenge site. However, the analogy stops here. Rubychallenge will offer an entirely different programming/game/puzzle experience compared to all the similar sites out there, both in terms of game concepts and mechanics, as well as entirely unique site structure/design.

We have tons of ideas in our wiki already, and right now we are fledging out which ones to implement. Alex just set up a working development environment, so after ironing out some ideas crucial to begin, we might even write some code soon ;-) We would like to come up with a presentation/demo page as soon as possible, and possibly a development blog to inform you what’s going on. At some point we would like to incorporate some beta testers, so stay tuned!

tags:

Java and Ruby (on Rails)

Tuesday, April 18th, 2006

Being a professional Java programmer myself, i collected some links that might bridge the gap for Java programmers who would like to take a peek at Ruby:

Introductory materials

Java - Ruby integration

  • JRuby - A 1.8.2 compatible Ruby interpreter written in 100% pure Java. Charles Oliver Nutter, one of the JRuby developers in a discussion claimed that “We’re currently working to make JRuby more EJB and J2EE-friendly, so you’re certain to see more of these opportunities.”

The question from the top of every RoR/Java FAQ:

Ajax Goodies:

Not exactly java, but nice Rails+Ajax technology showoff

tags: