Posts Tagged ruby

Free ad space if you donate to RVM

Hello People,

I am very much fond of rvm http://rvm.io/ . All the apps I have deployed runs on it. RVM needs funding so that it can be developed further. I want to hasten the process of funding.

I have written a ruby programming book named ‘I Love Ruby’ thats totally free, you can get it here http://goo.gl/FW6slH (this book will be released on jan 2014 or earlier)

If you donate $2000 to RVM I will grant full page advertisement, half page for $1000 and quarter page ad for $500. If you have donated these amounts you can contact me on mindaslab at gmail dot com so that I can put your ad in it.

The advertisement will stay till Jan 31 2014. It must be designed by you.

Please donate to RVM by going to https://www.bountysource.com/fundraisers/489-rvm-2-0

, , , ,

Leave a comment

Very Simple Search for Active Records

Okay, you might encounter a need to put very simple search for active record / model in your Rails app and here is it. Put this code in your active record model:


##
# A simple search method
def self.search text
columns = [:name, :roll_no, :address, :city, :pin, :ph]
words = text.downcase.split(/\s+/)
query_array_2 = []
for word in words
query_array = []
for column in columns
query_array << "lower(#{column}) like '%#{word}%'"
end
query_array_2 << query_array.join(' or ')
end
query = query_array_2.collect{|e| "(#{e})"}.join(' and ')
self.where query
end

view raw

search.rb

hosted with ❤ by GitHub

Note this line

columns = [:name, :address, :city, :pin, :ph]

in the code snippet, give your own column names in that array.  This array can contain columns that are string and text type. Lets say you have put these stuff in a class called Person , to search it you need to issue a command like this

Person.search "Karthik chennai"

This stuff works well with Sqlite, Postgre and MySQL. If you have tried this out with other DB, please add it in comments. Bye.

, , ,

Leave a comment

Launching Ruby Links

Possible Ruby Links Logo

Possible Ruby Links Logo

Hello people. One problem with Ruby and its spinoffs like Rails, Sinatra and blah blah is that its documentation, books, tutorials are scattered all over the internet. I was wondering could this all be got under one place. In fact Google has done it. But is googlean excellent vertical specific search engine and book marking thing? No. Well I present you with http://rubylinks.net .

This is not a search engine though, all you can do is, if you find a great link about Ruby and its allied technology, you can post it here. If soe one likes it, they can jewel it. You are presented with your own page here all the links posted and jeweled by you are listed, so that there is no need for you to scratch your head and say, “where did I see that?”

Ruby Links is a free software, hosted here https://github.com/codetribe/ruby_links , please post bugs and suggestions there, ad if possible contribute for the benefit of Ruby community.

, , ,

Leave a comment

Learning Postgre is Quiet Essential

When its in PHP, people always proffered LAMP, that is PHP running on Apache server,  data stored in MySQL and all this runs on Linux server. Now Rails is slowly bt surely chipping into PHP’s territory. ore people like to start their project with Rails than with PHP (at least the people I know). Or should  I say Sinatra as its very easy to learn.

Now there is a change here. MySQL was popular with Rails, but its no more now. Not because its technically inferior to Postgre, but because its owned by Oracle. Oracle is a big company. Its just interested in making profit unlike the free software community which is interested  in delivering software to people so that they can benefit out of it. This corporate interest has made MySQL stall. The initial creator of MySQL, Monty Widenus has even started another project called MariaDB, a drop in replacement to MySQL.

But the mood in Rails community is clear. Most Rails apps as far as I know run with PostgreSQL. So learn Postgre. If your app receives lot of hits, possibly tou might dig deep into raw sql to improve its performance. Postgre also has a thing called Geographic Information System in which you can store geographic data, and ask queries like ‘which is the bakery thats nearest to my home?’ and so on.

So if you are interested really and are sure that your app will be popular, use and dig into PostgreSQL.

, , , , ,

Leave a comment

Upgrading to Ruby 2.0

http://vimeo.com/herokuwaza/matz2013

If you are using the rvm for managing Ruby versions and are in Ruby 1.9.X version and want to upgrade to Ruby 2, this blog will help.  So hoping that you have installed rvm on your system this is how you upgrade to Ruby 2.0

First in your bash / terminal you need to tell rvm to check for latest stable release of Ruby. For that type this command (of course without the $)


$ rvm get stable

This will update rvm  with latest stable releases. Now you can get the list of known by typing this command


$ rvm list known

This will list some stuff like this


# MRI Rubies
[ruby-]1.8.6[-p420]
[ruby-]1.8.7[-p371]
[ruby-]1.9.1[-p431]
[ruby-]1.9.2[-p320]
[ruby-]1.9.3-p125
[ruby-]1.9.3-p194
[ruby-]1.9.3-p286
[ruby-]1.9.3-p327
[ruby-]1.9.3-p362
[ruby-]1.9.3-p374
[ruby-]1.9.3-p385
[ruby-]1.9.3-[p392]
[ruby-]1.9.3-head
[ruby-]2.0.0-rc1
[ruby-]2.0.0-rc2
[ruby-]2.0.0[-p0]
ruby-head

Notice that you have [ruby-]2.0.0[-p0] which is nothing but but Ruby 2.0,to install it type this


$ rvm install 2.0.0

Once installed to use Ruby 2.0 just type this


$ rvm use 2.0.0

Now how to switch to other versions of Ruby, well just type


$ rvm list

This will list the versions of ruby available in your system, the following is the out put in my system


rvm rubies

=* ruby-1.9.3-p362 [ x86_64 ]
ruby-2.0.0-p0 [ x86_64 ]

# => - current
# =* - current && default
#  * - default

This shows I have Ruby 2.0 and Ruby 1.9.3-p362. To switch to  Ruby 1.9.3-p362 (in my case) type


$ rvm use 1.9.3-p362

and you would have switched to that version of Ruby!!!

, , ,

Leave a comment

Best bits of Ruby 2.0

Best bits of Ruby 2.0

,

Leave a comment

Ruby Style Guidelines Being Developed

Ruby style guidelines are being developed. Please checkout https://github.com/bbatsov/ruby-style-guide

, , , , ,

Leave a comment

Debugging Ruby Apps Step by Step

There is always the time in a programmers life, you are stuck with a app where you really don’t know what went wrong. Fortunately there is a way to execute your app step by step and see what’s going on. To do this install the debugger gem. In your terminal type the following


$ gem install debugger

And it gets installed.

Usage

Take a look at the program


require 'debugger'

def sum a, b
  debugger # place this line where breakpoint is needed
  c = a + b
end

puts "Sum of 3 and 5 is #{sum 3,5}"

Notice that I have placed a debugger point in line 4 , the program will stop at that point. You can type disp a to display the value of variable a in function sum. To goto the next step press n or next. To continue after the debug point type c or continue . If at all you want to get help, run the program and type help to see quiet good bit of help built into it. Enjoy debugging!

, ,

Leave a comment

rvm Gemsets

Lets say that you have two different Rails app. Now these apps would require certain types of gems, and some times these gem requirements could clash with each other. If that happens its better to use a thing called gem sets.

To know about gem sets take a look at this picture.

rvm_gemset

At the bottom you see the mighty rvm upon which can sit many Ruby installations, these installations can be switched using the rvm use <Ruby_version_number> , but lets say that you have two Ruby applications and for some strange reason you want to use one with older version of gems with one and another needs to use newer set of gems. You may want to  use different set of gems for an application, how to do that?

Well rvm has a thing called gemset with which you can group a set of gems under a name under a particular version of Ruby. This means as shown in the diagram above, note the green  boxes above Ruby 1.8 and 1.9 , you can have nnumber of gems ranginging from g1 to gn. You can name these gemsets any name you wish so that its quiet user friendly to change.

in the future if you think your Ruby / Rails / Sinatra or any other application is faltering due to  wrong gems installed, create a new gem set for it, switch it using rvm gemset commands and hope all things will go right. I am not going to dive deep into it as the rvm gemset has a good documentation here.

, , , , ,

Leave a comment

Another developer chooses Rails

Another developer chooses Rails

Just another Rails success story.

, , , , ,

Leave a comment