Thursday, June 14, 2018


Eid-al-Fitr in Dakshina Kannada district on Friday

TNN | Jun 14, 2018, 20:26 IST

32
Representative image. Representative image.

MANGALURU: Muslims in Dakshina Kannada district will celebrate Eid al-Fitr on Friday.

Dakshina Kannada district khazi Alhaj Twaqa Ahmed Musliyar has made an announcement in this regard on Thursday.


He said the decision to celebrate Eid-al-Fitr on Friday was taken based on the first moon sighting of Shawwal witnessed at Kozhikode on Thursday. Special prayers will be held at all masjids in the district at 8am.

Wednesday, June 19, 2013

Prepending in a Ruby Array

Appending in Ruby array is done in the following way :

my_array = ['s','a','u','r','a'] => ["s", "a", "u", "r", "a"]
my_array << 'v' => ["s", "a", "u", "r", "a", "v"]

Now, if you want to prepend any value to an array, Ruby's unshift method can be used for this purpose.

my_array => ["s", "a", "u", "r", "a", "v"]
my_array.unshift('c') => ["c", "s", "a", "u", "r", "a", "v"]

Thats it !

Monday, June 10, 2013

Ruby's try()

I came to know about Ruby's try() method today, liked, the overall purpose of this method and so, sharing a brief note about how we can use this method while writing codes. 

Many a times, we have to write conditions for checking for nil values/objects. try() can help us to write clean codes whereby we don't have explicitly do testing for nil value. 

Have a look at the small example below 

Without try():
puts @student.school.name if @student.school
With try():

puts @student.school.try(:name)

Read this http://apidock.com/rails/Object/try link, to know about try() method more in details.


Tuesday, February 12, 2013

SQL logs in Rails console


While working on different Rails projects, I often find it useful to see behind the scenes SQL queries in the console itself. We can the view the SQL queries in the log file itself, but I find it easier to look at the SQL queries at the console itself.

For this purpose in my Ubuntu 11.10, I have created a file called .irbrc in my home directory and have pasted the below contents in that file.

1:  require 'pp'  
2:  if ENV.include?('RAILS_ENV') && !Object.const_defined?('RAILS_DEFAULT_LOGGER')  
3:       require 'logger'  
4:        RAILS_DEFAULT_LOGGER = Logger.new(STDOUT)  
5:  end  


Now after starting the console, the output for any ActiveRecord operation shows the sql query also

Here is a simple output from the console
1:  >> User.all(:limit => 1)  
2:   User Load (0.9ms)  SELECT * FROM "users" LIMIT 1  

Not, I could test this only in Rails 2.

MailCatcher gem: Testing emails in Development mode in Rails

Well, I am writing this post after a long long time. Had some personal priorities to take care of.

Few days, back I was given a task, to develop a module where I had to write code for sending notification mails to different kind of users based on different actions/events in the application. Sending mails with ActionMailer is not that tough, but in my development environment I was not available to find  out how will the contents of the mail will actually look like when it is sent to the users.  I needed some simple way to test it.

While searching in google, I came to know about the mailcatcher gem and I am glad that I found it very easily :)

It is very easy to setup and configure mailcatcher in your project. 

First, you will add the following line in your gemfile

 gem 'mailcatcher'  
bundle install
Then you have to do the following changes in config/development.rb
 config.action_mailer.delivery_method = :smtp 
config.action_mailer.smtp_settings = { address: 'localhost', port: 1025 }
Then start/restart your rails app and mailcatcher daemon from terminal just by typing mailcatcher
saurav@saurav-Vostro-1540:~/workspace/my_project$ mailcatcher 
Starting MailCatcher 
==> smtp://127.0.0.1:1025
==> http://127.0.0.1:1080  
Now on opening http://127.0.0.1:1080 in your browser and you can see a virtual inbox and if you send some mails from your application, you will be able to see the mails in the inbox created by 'mailcatcher' gem. 

The most important feature of this gem, is that it allows you to see the HTML,Plain Text and Source view of the mails.

Thats it. Now test your mails :)

Friday, August 17, 2012

How to install MongoDB on Ubuntu 11.10

MongoDB can be installed in the following way

then inside /etc/apt/sources.list, append the following line Now add the GPG key and update your package list: Now we can install mongoid db in the following way Now you can check whether mongoDB got installed in a proper way: From your browser also, you can hit the url mentioned below and check whether mongoDB got installed properly.

Sunday, July 15, 2012

Generating Excel file with 'writeexcel' gem & 'axlsx' gem

Well, here I am describing a very short example of creating excel files in ruby. For this example, I have used the gem "writeexcel" writeexcel.

Here is a very small example

Well, Now a small example for generating excel file with axlsx gem.