The Hitchhiker’s Guide to Ruby On Rails Galaxy

Records of my voyage through RoR Galaxy

Posts Tagged ‘ruby’

RubyConf India 2010 – India’s First Ruby Conference

Posted by arjunghosh on March 15, 2010

 

   
  The Ruby Community in India, together with the Innovation & Technology Trust, is pleased to announce RubyConf India 2010 on Mar 20, 21 at the Royal Orchid Hotel, Old Airport Road, Bangalore.

This dual-track event will feature prominent speakers like:        

Ruby is an OS dynamic language that offers an ideal development environment for Agile practitioners. It has one of the most active open source communities worldwide which produces and supports tools and projects like Ruby on Rails – a powerful web application development framework that works well on different platforms, and significantly reduces time-to-market and operating costs.

BrainstormNetwork and Learn about the latest technology changes first-hand!

Follow us on twitter @rubyconfindia

 
  Platinum & Technology Sponsor:-   
ThoughtWorks        

Gold Sponsors:-
Hashrocket
Castle Rock Research India

Castle Rock Research India is a part of Castle Rock Research Corporation, a premier educational resource development company headquartered in Edmonton, Canada, offering print and digital educational resources in K-12 and higher education market. We represent the technology division of Castle Rock Research Corp and our focus is to build technology-based educational products for North American market. Our products address evolving needs of three primary groups – the student, the parent, and the education service providers, both in K-12 and higher education market.

Silver Sponsor:-
Mahashwami Software

 


I'm attending RubyConf India 2010

   

Posted in Uncategorized | Tagged: , , , , , , , , | 2 Comments »

How to parse a tweet text from Twitter using Ruby to parse-out ‘@’ and ‘#’

Posted by arjunghosh on March 5, 2009

Well lot of us love @twitter and also Ruby, and some time work on both 🙂

And often we need to do the folowing with a tweet

Well I had to do the following quite often:-

Take out the ‘@’ (i.e. @replies )and ‘#’ (i.e. hashtags ) from a tweet and separate it from the text part.

For example, we have a tweet:

@myfriend1 @myfriend2 this is a sample text #link #text

Now I want this tweet to be seperated into the following Array:

[‘myfriend1′,’myfriend2’]

[‘link’,’text’]

and the text only – [“this is a sample text “]

So first had to build a RegE, and then using the ever useful .gsub method of Ruby, created the following:

parsed_text = tweet.text.gsub(/ ?(@\w+)| ?(#\w+)/) { |a| ((a.include?(‘#’)) ? tags : replies) << a.strip.gsub(/#|@/,”); ” }

So the parsed_text has the final text only.  tags is an Array which will contain the hashtags and replies is an Array which will contain the @replies.

The RegEx / ?(@\w+)| ?(#\w+)/ extracts and seperates the hashtags & the @replies and place them in two seperate arrays.

The RegEx /#|@/,” only reples the ‘@’ and ‘#’ symbols in the extracted array elements.

And you can download it from Gist here http://gist.github.com/78498

Also while working on creating the above regular expressions, I found this interesting RegEx testing site called www.rubular.com which will help you write regular expressions very easily.

Posted in Uncategorized | Tagged: , , , , , , | 8 Comments »

Two of the best help & guide sites for RubyOnRails and Ruby

Posted by arjunghosh on February 27, 2009

Well this is essentially a note to self and well to others too.
The best help documents online for Ruby On Rails and Ruby are these AJAXified websites which allows real-time searching of sytanx and commands.

For Ruby On Rails, it is:

www.railsbrain.com

And for Ruby, we have:

www.rubybrain.com

And the best part is you can even download them so that you can use it offline!

Another good resource for Rails documentaion and help guides is the newly created collaborative effort Rails Guide project. This was started by @lifo as a project to give the rails community a good documentaion which was painfully lacking till now. Since its a collaborative effort, you can participate here. There is even buzz about this project on @twitter

Posted in Uncategorized | Tagged: , , , , , , | Leave a Comment »

Using ERB as a dynamic template to create a file whose contents are dynamic

Posted by arjunghosh on February 17, 2009

The following code will create a temporary file for say attaching a vcard file to email.The following code is dynamic to use ERB as a template to create the file dynamically every time with the variable “telephone”,”location”,”email” which gets binded to the ERB file and is under scope.
The code is:-

{
telephone = “347-27456”
location = “New Delhi”
email = “xyz@gmail.com”
vcard = ERB.new( File.open(‘address.vcard.erb’ ){ |f| f.read } ).result( binding )
f = File.new(“temp_file.vcf”,”wb”)
f.puts vcard
f.close
}

and in pastie is here

Posted in Uncategorized | Tagged: , , , , , , , | 1 Comment »

How to Install Ruby, Rails 2.x, MySQL, SVN, then setup Rails 2.x Application, Configure the database, Run the Rake Tasks, Install plugins and, finally run RSpec for Models on your Local Windows System

Posted by arjunghosh on April 25, 2008

A.) How to setup a Rails 2.x Application on your local system:–
[NOTE: The following steps are for Windows OS environment]

  1. Setup Ruby and Rails on the local system:-
    • Install Ruby on Windows:
      The easiest way is using the One-Click-Installer
      Once the installation is complete, check that path to ruby\bin directory is in your PATH variable (Run “cmd”, then type “path” at the prompt and check that the path is there.
      The great thing about the one-click installer is that it comes with Ruby Gems, Scite pre-installed. The thing to watch out for is that one-click installer does not have the very latest version of Ruby, so when you are reading Ruby Docs, make sure you know which version of Ruby you have (run “ruby -v” in the command prompt)
    • Installing MySQL on Windows:
      First, download and run the latest MySQL. After the files are unzipped, an Instance Config should run automatically (you can run it manually at any time from your MySQL bin directory just run “MySQLInstanceConfig.exe”). Then go through the step as directed.
    • Install Rails on Windows:
      Run the following command: gem install rails –-include-dependencies
      (If this command gives you an error, you do not have the latest version of gems installed. Run “gem -v” to check for the version of RubyGems. It should be 0.9.4. Otherwise, you may probably need to update RubyGems as well.: gem update –system [NOTE: It is recommended that RubyGems version 0.9.4 is used as Rails 2.x had some issue with version 0.9.5. Though this issue had been subsequently resolved]
    • Installing SVN on Windows:
      We use the TortoiseSVN SVN client on our local machine to use SVN.
      We have SVN version on our local system: 1.4.3
      The SVN version installed on the Server, which we were using, can be found by running the command on the server: svn –version
  2. Create a rails 2.x application:-
    SQLite3 is the new default database. So when a rails 2.x application is created, by default the database support, which comes preconfigured, is for SQLite3. So to create a rails 2.x application with MySql support preconfigured, you simply need to run the following command: rails -d mysql testapp
    This will create the skeleton structure for the rails 2.x application with mysql database adapter.
  3. Configuring the database for the application:-
    Now a database.yml file is created in the /config under your application root folder. You need to set the development, production and test database names there. Also you need to put in the database password,if there exist any,So for your database in this .yml file. This password is same as the one you put in while installing mysql on your machine.

    • So for a rails application, database.yml file configuration is as follows:
      development:
      database: testapp_development
      adapter: mysql
      encoding: utf8
      username: root
      password: mypassword
      [Note: password is set here if any]
      socket: /tmp/mysql.sock [NOTE: Similarly for production and test database]
  4. To create the database on the local machine:-
    Run the following command: rake db:create:all
    The above command will create all the three database i.e. development, production and test database as set in the database.yml file
    If you want to start from scratch, you can do rake db:drop:all And in the middle of development we can do rake db:rollback to undo the latest migration file.
  5. To seed the database with initial database:-
    Run the following command: rake db:populate
    This will populated the database with initial data as written in populate rake file. Also a rake task called rebuild has been created so that it becomes easy to do the above steps from dropping a db, re-creating the db,running all the migration and then finally populating it with the initial seed data.
    Run the following command:rake db:rebuild. [NOTE:This rebuild rake task will easily do all the above db related steps. See my previous post for “How to create a rake db:rebuild task”
  6. To run your Rails 2.x application on the local system:-
    Need to first go to root folder of your rails application. For example: F:/Projects/testapp/trunk
    Then run the following command: ruby script/server
    This will run the application in development mode. To run in production mode: ruby script/server -e production
  7. To install rspec plugin for rails application:-
    Run the following commands at the command line:
    ruby script/plugin install http://rspec.rubyforge.org/svn/tags/REL_1_1_3/rspec
    ruby script/plugin install

    and http://rspec.rubyforge.org/svn/tags/REL_1_1_3/rspec_on_rails
    Once the plugin is installed, you must bootstrap your palnglue rails app with RSpec. Stand in the root of your Rails app and run: ruby script/generate rspec
    This will generate the various files needed to use RSpec with Rails.
  8. To run the rspec with rake on the local machine:-
    Run the following command at the root folder of the application: rake spec
    or run specs with scripts/spec command: ruby script/spec spec

B.) How to install a Plugin for Application:–

Stand in the root of your rails app and run:

ruby script/plugin install <here the url path of the plugin to be installed>

C.) Running the RSpec test cases for Models:–

Run using the command:

rake spec:models

D.) Running the RCov:–

Coverage tests can be run using the command:

rake spec:rcov

Posted in Uncategorized | Tagged: , , , , , , , , , , | 3 Comments »

What does “ruby script/about” command do?

Posted by arjunghosh on April 17, 2008

Well this is more of a note to self.
You can tell what version of Rails your application uses with this command under your rails application folder:

ruby script/about

Posted in Uncategorized | Tagged: , , , | Leave a Comment »