Skip to content

Simple Ruby code send mails

require ‘net/smtp’

message = <<MESSAGE_END
From: Your mail id <>
To: There mail id <>
This is a test mail to check ruby code is working for sending mails ?


Net::SMTP.start(‘localhost’) do |smtp|
smtp.send_message message, ’’,
puts “mail sent”

Fetch ipaddress and get location using ruby

require ‘rubygems’
require ‘geocoder’
require ‘socket’
    def local_ip
  orig, Socket.do_not_reverse_lookup = Socket.do_not_reverse_lookup, true  # turn off reverse DNS resolution temporarily do |s|
    s.connect ‘’, 1
  Socket.do_not_reverse_lookup = orig

ip_add =  local_ip

puts “your ip :” +ip_add
location =“#{ip_add}”)

location.each do |lc|
if == “”
puts “this ip is reserved not able to fetch details “

Get IPaddress using ruby

Install socket gem and require it in you code

require ‘socket’

// local_ip is custom method to fetch ip address of the system u connected to global through //internet
    def local_ip
     orig, Socket.do_not_reverse_lookup = Socket.do_not_reverse_lookup, true  # turn off    reverse DNS resolution temporarily do |s|
    s.connect ‘’, 1
  Socket.do_not_reverse_lookup = orig

ip_add =  local_ip

puts “your ip :” +ip_add

Mongoid in Ruby on Rails

Mongoid  is an Object-Document-Mapper (ODM) for MongoDB written in Ruby which works similar to ORM to other database in rails application.
Ruby developers who have been using Active Record or Data Mapper, while leveraging the power of MongoDB’s schemaless,performant document-based design, dynamic queries.

class Project
include Mongoid::Document
field :name, type: String
embeds_many :developers

class Developer
include Mongoid::Document
field :name, type: String
embedded_in :project

While using mondoDB in Rails application we need to include mongoid:Document in every model in our applications.

filed is the field name and the datatype we are specifying

embeds_many is nothing but has_many relationship In this way we can use mongoid in our rails application this is the simple exaplination about mongoid usage.

Country name using ip address

We can get the country name base on ip address

Using ‘ip2country’ gem we can do this but this gem can be possible to use in ruby 1.8.7 only(not sure )

require ‘rubygems’
require ‘ip2country’

ip2c =
ip   = ‘’

if country = ip2c.lookup(ip)
puts “#{ip} belongs is located in: #{} (#{})”
puts “The region for #{ip} could not be determined.”

More repeated characters in a string

puts “Enter a string”
string = gets
puts string.scan(/((.)\2*)/).group_by{|s, c| s.length}{|s, c| c}

MongoDB introduction

MongoDB is an open source document-oriented database management system which comes under NoSQL family databases.Mongodb stores the data in JSON format instead of storing as a traditional database style in tables which relational database do.And also contains dynamic schema which helps to integrate it in applications and makes that application runs faster.

Any field in a MongoDB document can be indexed is the key feature .

Install MongoDB in Ubuntu.
Run the following command to import the 10gen public GPG Key in your terminal

sudo apt-key adv –keyserver –recv 7F0CEB10

Create a /etc/apt/sources.list.d/10gen.list file using the following command.

echo ‘deb dist 10gen’ | sudo tee /etc/apt/sources.list.d/10gen.list


sudo apt-get update

Install Packages

sudo apt-get install mongodb-10gen

you have successfully installed MongoDB!

Now you can start MongoDb as a service by the following command

sudo service mongodb start

To stop the service

sudo service mongodb stop

To restart the service

sudo service mongodb restart

After starting the service you can use mongodb client using mongo command

Run “mongo” command in the terminal

Now here is the important commands to use mongodb

To see all the databases

show dbs

To use the database

use database_name

To list out all the collections nothing but tables in general words

show collections

To insert data

Example syntax


To find the record(s)


also you can do

var result = db.table_name.find()


For example you have normal query like

select * from emp where name=”ram”;

is looks like


select * from emp where salary > 10000;

is looks like

db.emp.find({salary: {$gt: 10000}})

Note : to use greater than or equal to use ‘$gte’ and similarly less than or equal to ‘$lte’ .

It is also having maximum 4mb of document size.

Animation basic

Animation is the nothing but a sequence of display the images rapidly which makes an illusion of movement.the general way of making an animation is a picture motion this type of presentation done by a camera or a projector or a computer viewing screen which can rapidly cycle through images in a sequence. It is possible to make an illusion of pictures which are made with either hand rendered art, computer generated imagery, or three-dimensional objects. The position of each object in any particular image relates to the position of that object in the previous and following images so that the objects each appear to fluidly move independently of one another. The viewing device displays these images in rapid succession, usually 24, 25, or 30 frames per second.

Most important basic principles of animation is
walk cycles
these all are familiar hallmarks of animation, and should be mastered no matter how you prefer to animate.

Basically the unit of speech is known as a “phoneme”. The lip reading and facial expressions that correspond to phonemes are known as “visemes”. Animators generally refer to phonemes and visemes interchangeably, even though they are technically different concepts.To create the illusion of speech on an animated character, the SmartMouth Flash extension includes a sample set of those shapes.

Squash and Stretch
Generally used in 2D animation It can give your object some realistic  into it. The amount of squash and stretch depends on how much flexibility you give your object.

Example: A bouncing ball

Walk Cycles:
The walk cycle is one of the most important concepts in animation it is also acceptable as an basic animator it is diffucult.
There are many types of walk cycles, and you can vary the motion to match your character  mood;

DataMapper in Ruby

It is a Ruby Object/Relational Mapper like other ORM to rails application.

DataMapper is a bit better and faster than other Ruby ORMs. It allows us to write a query in simple way which means allows raw query . It provides more helpers conditions based syntax to write your own SQL queries.

Generally we use Acive record in Rails application and let us assume the scenario for finder option in the Datamapper.

Just write User.all(:name => ‘Ram’) and DataMapper will look for users with the name of ‘Ram’.

We can do very simplly instead of writing User.find(:all, :conditions => {:name => “Ram”}) or  User.find_by_name(‘Ram’) by increasing the size of query and parameters

Lets have a look what Datamapper makes us to write query very simple and excutes the result faster than other ORMs

User.first(:name => ‘Sri’)

If we need any results like age greater than some constant value we can do
User.all( => 18)

Here ‘gt’ means greater-than. ‘lt’ is less-than.

We can use ‘gte’ and ‘lte’ also which means ‘greater than or equal to’ and ‘less than or equal to’ repectively

User.all(:name.not => ‘Sree’)

To avoid some names we can use ‘not’

# If the value of a pair is an Array, we do an IN-clause for you.
User.all( => ‘R%’, :id => [ 1, 2, 3, 4, 5 ])

Another important feature which Datamapper provides is
One row in the database should equal one object reference.  If you run the following code in ActiveRecord you’ll see all false results. Do the same in DataMapper and it’s true all the way down.

@user = User.first(:conditions => { :name => ‘Ravi’ })

@user.comments.each do |comment|
  puts @user.object_id == child.parent.object_id

By comparision of these with other ORMs we can say that DataMapper is faster to get things done.


My discoveries....

Sridhar: Web Unplugged!!!!

Thank god. It Isnt a Brain Surgery, Its a Web App!!!

AVAS Technology

Creating Innovation in SMB Technology

Suman Srinivasan's Code Blog

Code samples and tutorials during my work/school

Wei's world of Linux/Ubuntu+KDE

Better Life Experience with Linux

Official Selenium Blog

Just another weblog

Simple API

Enlarge your skills

SutoCom Solutions

Success & Satisfaction with the Cloud


Just another blog for Selenium


Ruby on Rails runway....................


Teach me how to fish


Software Development Bits\'n\'Bobs

Talent Flush Blog

Good Sense


Gobán Saor

A country datasmith.


Just another blog for RoR Beginners


breaking into the unknown...

Talking Experience

Life is a journey where choices are made every moment

Glenn's Thoughts

Web Development In My Perspective

%d bloggers like this: