Archive for the “Ruby on Rails” Category
I saw this piece of code mentioned on reddit and it absolutely blew my mind. The code below is written in the Ruby programming language and when compiled, produces compilable Python code which is impressive in itself. And when you compile the outputted Python code, it produces Perl code, which generates Lua code, which generates OCaml code, which generates Haskell code, which generates C code, which generates Java code, which generates Brainfuck code, which generates Whitespace code, which generates Unlambda code. And as a finale, the Unlambda brings everything full circle and generates the original Ruby code! Truly an amazing piece of work.
# ruby
l=92.chr;eval s="s=s.dump[r=1..-2].gsub(/("+l*4+"){4,}(?!\")/){|t|'\"+l*%d+\"'%(t
.size/2)};5.times{s=s.dump[r]};puts\"# python\\nprint(\\\"# perl\\\\nprint(\\\\\\
\"# lua"+l*4+"nprint("+l*7+"\"(* ocaml *)"+l*8+"nprint_endline"+l*15+"\"-- haskel
l"+l*16+"nimport Data.List;import Data.Bits;import Data.Char;main=putStrLn("+l*31
+"\"/* C */"+l*32+"n#include<stdio.h>"+l*32+"nint main(void){char*s[501]={"+l*31+
"\"++intercalate"+l*31+"\","+l*31+"\"(c(tail(init(show("+l*31+"\"/* Java */"+l*32
+"npublic class QuineRelay{public static void main(String[]a){String[]s={"+l*31+"
\"++intercalate"+l*31+"\","+l*31+"\"(c("+l*31+"\"brainfuck"+l*64+"n++++++++[>++++
<-]+++++++++>>++++++++++"+l*31+"\"++(concat(snd(mapAccumL h 2("+l*31+"\"110"+l*31
+"\"++g(length s)++"+l*31+"\"22111211100111112021111102011112120012"+l*31+"\"++co
ncatMap("+l*32+"c->let d=ord c in if d<11then"+l*31+"\"21002"+l*31+"\"else"+l*31+
"\"111"+l*31+"\"++g d++"+l*31+"\"22102"+l*31+"\")s++"+l*31+"\"2100211101012021122
2211211101000120211021120221102111000110120211202"+l*31+"\"))))))++"+l*31+"\","+l
*63+"\""+l*64+"n"+l*63+"\"};int i=0;for(;i<94;i++)System.out.print(s[i]);}}"+l*31
+"\")))))++"+l*31+"\",0};int i=0;for(;s[i];i++)printf("+l*63+"\"%s"+l*63+"\",s[i]
);puts("+l*63+"\""+l*63+"\");return 0;}"+l*31+"\");c s=map("+l*32+"s->"+l*31+"\""
+l*63+"\""+l*31+"\"++s++"+l*31+"\""+l*63+"\""+l*31+"\")(unfoldr t s);t[]=Nothing;
t s=Just(splitAt(if length s>w&&s!!w=='"+l*31+"\"'then 501else w)s);w=500;f 0=Not
hing;f x=Just((if x`mod`2>0then '0'else '1'),x`div`2);g x= reverse (unfoldr f x);
h p c=let d=ord c-48in(d,replicate(abs(p-d))(if d<p then '<'else '>')++"+l*31+"\"
."+l*31+"\");s="+l*31+"\"# ruby"+l*32+"n"+l*31+"\"++"+l*31+"\"l=92.chr;eval s=\"+
(z=l*31)+\"\\\"\"+s+z+\"\\\""+l*31+"\"++"+l*31+"\""+l*32+"n"+l*31+"\""+l*15+"\""+
l*7+"\")"+l*4+"n\\\\\\\")\\\")\"########### (c) Yusuke Endoh, 2009 ###########\n"
To properly try this, you’ll require the following versions of each compiler:
* ruby 1.8.7-p72
* Python 2.5.2
* perl v5.10.0
* Lua 5.0.3
* OCaml 3.10.2
* ghc-6.8.2
* gcc 4.3.2
* java "1.5.0_17"
* beef 0.0.6-2
* whitespace 0.3-2
* unlambda 2.0.0-5
Credit goes to Yusuke Endoh for this masterpiece of programming art.
Popularity: 2% [?]
5 Comments »
This post is a response to Derek Siver’s post on the O’Reilly blog. Over two years ago, he decided to ditch a hundred thousand lines of messy PHP code in favor of rewriting his whole site with Ruby on Rails. Two years later, he isn’t even half done and has decided to go back to PHP. Just two months with PHP again and the project is complete.
He gives seven reasons of why he switched back to PHP after 2 years of unsuccessfully. I agree with some but not others. Here are his 7 reasons, you can read them in more detail on the original post.
- “Is there anything Rails/Ruby can do that PHP can’t do? … (thinking)… NO.â€?
- Our entire company’s stuff was in PHP: Don’t underestimate integration.
- Don’t want what I don’t need.
- It’s small and fast.
- It’s built to my tastes.
- I love SQL.
- Programming languages are like girlfriends: The new one is better because *YOU* are better.
Comparing Apples and Oranges
First of all, I would like to present the analogy of building a tree house. You can either build a tree house with precut pieces of wood and material (Ruby on Rails) or you can build a tree house by chopping down your own trees and making your own pieces (PHP).
Building a typical tree house is very easy with precut pieces. It is then just a matter of putting things together in the right order. However, if you wanted to deviate from a regular tree house and put in, say, an electric elevator, then you would have to find someone that has built something similar and copy it or modify your existing material to do so.
Building a tree house from chopping down your own trees is more time consuming but you have full control every step of the way. If you want a circular piece of wood, then you create a circular piece of wood. You still have some pre-built materials given to you like nails and screws (built-in PHP functionality) but all the custom stuff needs to be created.
Ruby on Rails is a framework. It streamlines the process building a web application or website. You can do many things with it but some may require little hacks and workarounds. If one wishes to compare Rails and PHP, it would make more sense to compare Rails with a PHP framework such as Zend or CakePHP.
What I Do Agree With
Although I think the comparison is a poor one, Derek does raise some very good points. First, I do find that sometimes it is easier to comply with what is already in place instead of trying to overhaul an entire system. I’ve worked at places where the entire system backend was built on layers and layers of poorly documented UNIX scripts. It would take an enormous amount of time to go through and figure out exactly how everything fit together in order to recreate the whole system in a more structured manner. Throughout the way, dependency problems will undoubtedly arise and everyone that has already gotten used to the old system will have to be retrained (which is no easy task).
Second, no matter how you look at it, a properly written PHP application will be faster than a Rails application. One of the drawbacks with Rails is that it is said to be hard to scale. There are solutions but for the same amount of computing power, PHP applications are typically more efficient since it leaves off a lot of extra unused fluff that is present in frameworks.
Anybody out there move back to PHP after trying Rails? I know I did for a while since I had a tight deadline on one project and couldn’t learn all the insides and outs of Rails in time.
Popularity: 5% [?]
11 Comments »
As a follow up to a previous article about Portable Web Development on a USB Drive, here are a couple programs you can include to make it Ruby on Rails compatible.
InstantRails
In the original article, I recommended XAMPP Lite as a portable Apache, PHP, MySQL server that doesn’t require installation. You can add a Rails installation to XAMPP but an easier way is to get InstantRails.
InstantRails includes an Apache, PHP/MySQL and Rails preinstalled and preconfigured, all you need to do is to unzip it to your USB drive. InstantRails is based off EasyPHP (similar to XAMPP) so it is also extensible if you wish to install other software onto it as well.
RadRails
RadRails is a plug-in for the Eclipse IDE. It streamlines many of Rail’s features so you don’t even have to touch the command line to create or migrate your rail files. RadRails is currently supported by the Aptana team so you can get it from the Aptana site as either a plug-in for Aptana/Eclipse.
Also, check out this post for instructions on configuring Aptana/Eclipse to run independently off a USB drive.
Configuring Aptana/Eclipse to work with InstantRails
Before you can get started developing Rails applications, you’ll need to configure either Aptana or Eclipse to work with the InstantRails server.
To do this, navigate to Window->Preferences.
Under Ruby->Installed Interpreters, you’ll need to add a new RubyVM pointing to:
\InstantRails\ruby
Under Rails->Configuration (in version 3.3), set the Rails and Rake path to:
\InstantRails\ruby\bin\rails
\InstantRails\ruby\bin\rake
These paths assume you have InstantRails unzipped to the root of the drive (which is recommended).
With all these Portable applications, it seems like 512mb drives might not be enough anymore!
Popularity: 7% [?]
7 Comments »
When I first decided to learn Ruby on Rails, I came across two book recommendations on the official Ruby on Rails site. The first book is an introduction to web development with Rails, called Agile Web Development with Rails. The second is called Rails Recipes which includes many tutorials on using Rails in various situations. Not sure how deep I had wanted to dive into Rails, I only bought the first book.
I ordered mine (second edition) from Amazon and came out to about $25 US after tax and shipping. When it arrived, I was surprised at the size of it. I mean for only $25 I expected a nice compact introductory book but instead it came in at a hefty 700+ pages! Talk about bang for your buck.
The Authors
Agile Web Development with Rails is written primarily by Dave Thomas (not the late Wendy’s founder) and David Heinemeier Hansson (creator of Rails). Dave Thomas is of The Pragmatic Programmer fame (another book which I own and highly recommend). His pragmatic philosophy of programming really shines through in this book. This philosophy stresses the importance of being functional and practical (i.e. thinking ahead, writing highly maintainable and adaptable code etc.). The style of writing is very easy to read and follow in that it offers tons of real-life examples and situations that really illustrate the points that are covered.
Prerequisites
The book begins with the assumption that the reader has some prior knowledge of Ruby — if there is none, the Appendix provides a short but sufficient tutorial for any intermediate programmer to get started with. There really isn’t much to Ruby — if you’ve done previous object-oriented programming, it’s just a matter of getting used to the syntax.
Part 1 – Getting Started
The book is divided into 4 sections (plus an Appendix). The first section gives a little introduction and some history on Ruby and Ruby on Rails. It also walks the reader through the steps of acquiring the necessary software and development environments on the computer for all operating systems. This section is simple enough and for the most part, can easily be skipped if you have some knowledge of Rails prior.
Part 2 – Learning By Example
The second section walks the reader through the process of creating an entire web application in Rails. In this case, a shopping cart program (that uses AJAX!). I consider this to be the best part of the book. I would recommend that you take your time going through this section and actually follow along on your own computer. Also, I highly recommend doing the little exercises at the end of each chapter — if you’re stuck, there is always the online forum where other readers of the book gather to tackle these extra exercises. This “Learning by Example” method really gives you insight into the entire process of developing a web application. As I was following through the example, it was simple to see how different concepts could be extended to my own projects and how easy it would be to implement compared to PHP!
Part 3 – Rails Framework
In most books, this section would come at the beginning. It introduces the framework and goes into detail of what each component of it is responsible for. But having already developed a web application, I found that the explanation of the framework suddenly made a lot more sense. If anything, this section serves as very good reference material — meaning this isn’t just one of those read-it-and-forget-it books.
Part 4 – Security and Deployment
After developing the newest and best web application, it is important to make sure it is secure and of course, deploy it. The security section covered the usual stuff: SQL Injection attacks, Cross-Site Scripting etc. This wasn’t too exciting since Rails has most of its bases covered. What I was surprised by however, is how much detail the book went into when it came to deployment. It talked about production servers, compared different web servers, discussed setting up the deployment server and finally the launch.
Criticisms
My main criticism of the book is that although there is some humor, much of the book is very dry. It wasn’t as fun a read as The Pragmatic Programmer but that could be due to the fact that the book features many guest writers aside from Dave and David.
Second, you would think that with all their web experience, they could create a better looking website! It’s functional but could definitely use a bit of work in my opinion. But then again, we’re talking about web development and not web design. Also, I got the feeling that Dave and David didn’t like Vim very much as they promoted Emacs in several places in the book!
Conclusion
If you’re a budding web developer looking to dive into the wonderful world of Rails, I would highly recommend this book as a starting point. For those of you already familiar with Rails, this book would make a good reference but there are definitely better choices out there. But really, for twenty-something bucks, you can’t really go wrong with this hefty little book jam-packed with information.
If anyone else has read this book or has a book recommendation for getting started with Rails, I’d love to hear your comments!
Popularity: 4% [?]
6 Comments »
I’ve mentioned Aptana before as a very nice (free) alternative to Dreamweaver if you are primarily a coder like myself. I have been switching back and forth between the two for a while now, undecided on which one is better. On one hand, Dreamweaver has great FTP and site organization with an interface I’m very used to. On the other hand, Aptana is free, cross-platform and is designed more for the web coder than designer. This past week sealed the deal.
I’ve recently started playing with and using Ruby on Rails (it’s great by the way) and I am using Radrails as my editor. Now Radrails isn’t a standalone editor, it is actually a plug-in for Aptana. So with the great extensive Rails support, I can now comfortably leave Dreamweaver behind. But wait, it gets better.
Aside from web development coding, I also do a lot of Java development as well. Wouldn’t it be great to have a single development environment for all 3 languages? Enter Eclipse.
Eclipse
Perhaps this isn’t the first time you’ve heard about Eclipse but what I don’t think a lot of people realize is that Aptana is built upon the Eclipse platform. In fact, Aptana is available as a plug-in for Eclipse! So after installing Eclipse with base Java support, the Aptana plug-in and the Radrails plug-in, you suddenly have a free all-in-one cross platform program for all your coding needs. Additional plug-ins will extend support to pretty much any other language out there.

One criticism of Aptana is its lack of PHP support and that’s where PHPEclipse comes in. It’s not as good as Dreamweaver’s PHP support but for most uses, it’s fine. So with Eclipse’s extensibility, Aptana and its integrated FTP, Radrails and its integrated everything-related-to-rails, you have one powerful web development tool.
Since it is cross-platform, this makes Linux look a little bit sweeter. Oh did I mention you can run it completely off a USB stick? (Instructions to follow soon!)
Popularity: 6% [?]
19 Comments »
|