Scaling up with Rails and EC2 Update

This should make things a bit easier to understand
Posts from HyperionReactor - Ruby On Rails...

This should make things a bit easier to understand
A challenge I faced recently was "scaling up on demand" (without manual intervention). EC2 was the my platform of choice because I could write a small script to manage all my machines. EC2 being Xen based also allowed me to create custom images of my application servers.
Example:
I have a base of 2 machines, and no real limit set to the maximum number of ec2 machines that can launched. The script is set to send me a mail every time a new machine is launched or terminated.
Now I am trying to automate creation of MySQL Slaves
After months of hard work and sleepless nights, we finally launched the second version of change.org. I generally try to talk about cool things I am working on; but this was not possible with change.org because there was no time to waste. Every minute counted.
Today we launched the second release of the site, which not only helps you support changes you would like to see in the world. But also find politicians that are willing to support your cause. We spent hours discussing if change politics should be a site of its own, because some of us did not support the idea diverting focus away from the non profits ( at some point I belonged to this camp ) but after careful evaluation we managed to find our own middle path.
Ruby on Rails is quickly becoming one of the most popular modern programming language framework combinations. Specifically, Ruby is a programming language that has been around for a few years and Rails is a framework for Ruby that is a bit newer and is just about the hottest thing in application and web development right now. Rails' seamless integration into web servers and databases and its elegant framework make it the ideal candidate for every programmer wishing to develop the latest and greatest web application.
I started writing a blog article on how to integrate the cool prototype windows and ajax_scaffold, half way through I got bored of writing it and just decided to upload my mutated version of it.
You need to manually install the prototype window javascript. Any one with basic rails knowledge should be able to do this.
Its just a quick hack by the way..
h3. What is monotone?
Monotone is a free distributed version control system. it provides a simple, single-file transactional version store, with fully disconnected operation and an efficient peer-to-peer synchronization protocol. it understands history-sensitive merging, lightweight branches, integrated code review and 3rd party testing. it uses cryptographic version naming and client-side RSA certificates. it has good internationalization support, has no external dependencies, runs on linux, solaris, OSX, windows, and other unixes, and is licensed under the GNU GPL.
_Taken from the monotone website_
This is a update to my previous blog post. All credits to the authors and contributors. I just host these files.
Installation for ruby support and ruby electric. Add the following lines to your .emacs file
(require 'ruby-mode)
(require 'ruby-electric)
Installation for ruby on rails support. Add the following lines to your .emacs file
(defun try-complete-abbrev (old)
(if (expand-abbrev) t nil))
(setq hippie-expand-try-functions-list
'(try-complete-abbrev
try-complete-file-name
try-expand-dabbrev))
(require 'rails)
class Smokers < ActiveRecord:: Base
belongs_to :heart_failure_statistics
has_many :cigarettes
attr_accessor :mins_since_last_puff
before_validation :check_cigarettes
def smoke?
if mins_since_last_puff >= 60
write_warren("Smoke?")
end
end
end
Finally after a long wait its finally here! There have been soo many changes since the early 0.5 days. I still remember the good ol' days where you had to do so many things manually. Thanks to the rapid development of the framework, most of this is taken care of now. I remember times where I had to spend time on apache to get things right and now every thing seems to work out of the box.
The community has grown from 10 to over 400 users (on IRC we lost a good few though). Hope to see Rails establish it self as the next industrial standard.
Since Rails .5 I have launched over 5 applications and 3 more are in the pipe line, one of them being the rewrite of Global Drum and Bass and the other being OurProject.org
David "DJ Cookie" Killingsworth and I have been working on this side project called Global Drum and Bass, we are near completion of the project, we have pratically everything we need lined up for this.
We are going to replace Xoop with Ruby on Rails. I have already touch my first internal Beta. Just waiting for a good design before releaseing a Public Beta (Web 2.0 Required from what I understand).
As with all our projects, this is going to be free of charge for everyone.
I have got a lot of emails and messages from people who are interested in the code. I am still actively working on it right now. I will be release the code pretty soon, the code is going to be used in a major application I am writing; which will need to support at least 10 languages.
Some of you have already integrated my patch, some of you have already figured out how to use it without any help ( that was the initial plan after all ). As for those who don't, here goes.
I did promise earlier that the support will be modular just like our views, but since the system loads all the languages into memory before serving request, I decided to drop it for now.
Step 1. Locale directory
All the language files are supposed to be stored here.
Step 2. Create the lyml file
This is where you store all your language strings, it is recommended you use the iso standard eg. en-gb.lyml, en-us.lyml etc...
Step 3. Add strings
You now need to add all the strings you are going to use in your application, since this is yaml you dont need to be a genius to add stuff, and remember to use a editor that supports utf like emacs or vi.
file: en-gb.lyml
en-gb:
hello: Hello-gb
world: World-gb
file: en-us.lyml
en-us:
hello: Hello-us
world: World-us
Step 4. Setting the default language
The system stores the language to use in session[:language]. You now need to add some code to set a language if it has not been set, I am working on a way where you can specify your default language in environment.rb
Step 5. Usage
Now in your views you can simply just do a <%= t 'hello' %><%= t 'world' %> and depending on the language you have set, it will use the correct strings. You can also do a <%= t 'hello', 'en-gb' %> where it will output the hello string for en-gb even if the language environment is set to en-us
Technorati Tags: Ruby on Rails
Not everyone speaks the same language, Google and Yahoo have lead the way to multilingual web applications. Rails promotes Web 2.0, and I think accessing your favorite application in your own language is a must for Web 2.0. I spent some time yesterday trying out the different ways of making my application support multiple languages, most of them were too complex for a Rails newbie to install and use. Rails has always been all about “out of the box” features, so I decided to sit and code up support for multilingual Rails.
Background
I had to build a complex event management and tracking system. The old developer simply provided a link to Webmaps. I really did not like this approach, and decided to check out Google and Yahoo maps. So I signed up for a Google and Yahoo Developer Id.
I started off with YahooMaps, since I have a lot of friends at Yahoo, I knew it would be easy to get help from them if I get stuck somewhere down the road. After a quick read through their documentation I found out:
They also have this really cool YahooMap Live Traffic Update, which is cool in its own way...
I then moved on to GoogleMaps. We all know how cool they are :) Google seems easy to implement. Not as easy as Yahoo though. So this is what I found out about Google:
GoogleMaps won hands down, mainly cause of their ability to embed the map on your page.
Implementation
You will first need to signup for a GoogleDeveloper Id. After you get the developer id; you need to get the key to embed the map on your homepage. These keys work only for a specific urls e.g. http://www.hyperionractor.net/maps/ so now the maps will work on all the pages under '/maps' can will work but not under '/'.
You will need to signup for a geocoder service now. This is because you will need to convert your address to a latitude and longitude. I am using geocoder.us/ it is a free service; but I suggest you make a donation or a subscribe to their service if your are using it for commercial purposes. They support XML-RPC, REST and SOAP. I picked XML-RPC.
Controller code (sample)
def view
event = Event.find(params[:id])
server = XMLRPC::Client.new2('http://rpc.geocoder.us/service/xmlrpc')
result = server.call2('geocode', event.address)
@lat = result[1][0]['lat']
@long = result[1][0]['long']
end
View code (sample)
application.rhtml
<%= @content_for_head_t %>
>
view.rhtml
Add that code where you want to display the map
It is important that you create a onload() function, this is because IE has issues if the map is generated before the page is loaded or something like that. What we are going to do is load the entire page, and then load the map. In this way the map will work across all browsers. If you dont you should keep getting a "Operation Aborted" error. This goes at the bottom of your page: This will automatically be added to the head tag. You have to replace my_key with your Google Key. and every thing else stays the same. This will add the onload='onload()' to your body tag. This will tell the browser to start loading the map, only after the entire page has loaded. You can also create some kind of GoogleMap Helper if you are using a lot of maps. If you have found a better way to use GoogleMaps and YahooMaps please do leave a comment. Technorati Tags: Ruby on Rails, Google Maps These are the people I blame for burning a $3700 hole in my pocket... in no particular order. David Heinemeier Hansson This is for all you AudioScrobbler junkies. We now have a RubyOnRails Group. Click here to go there. Yahoo Research has just come out with a really cool application called The Buzz Game. The game is a fantasy stock market, where you start off with $10,000 and you can invest it in the technology you like. I signed up and invested all of it on Rails. and withen 5 minutes I jumped up from $26 to $28. By the time I finished this blog it jumped up to $30. From the ROR Weblog Puzzled as to what all this would mean, I asked recognized internet entrepreneur Thomas Madsen-Mygdal. As the founder of internet conference Reboot, co-founder of wifi hotshot Organic, and a slew of other companies, I knew he would know. While Rails was trading at $22, he predicted: I see the core fundamentals in the Rails market taking it to 80 dollars six months. A strong buy recommendation. Just took some time off to tell you guys why you should not use the much hyped Ruby on Rails, if you have more reason please feel free to leave a comment and I will add it to the list. None of us really want this. Hence I suggest you go and use some good Java or PHP Framwork. ;)
<% content_for('head_t') do %>
<% end %>
<% content_for('body_t') do %>onload='onload()'<% end %>
These are the people I *blame* for burning a $3700 hole in my pocket
Jamison Hiner
Jason Wong
Kapil Karekar
Scott Barron
Sam StephensonRails on Audioscrobbler
Got that Buzz?
Some reasons why you should not use Rails
Here goes...
(Was kinda lazy to think of some thing new)