Code:

def rando
letter=(“a”..”z”).to_a
return @name=
letter[rand(letter.length)]+”#{rand(9)}”+letter[rand(letter.length)]+
letter[rand(letter.length)]+letter[rand(letter.length)]+”#{rand(9)}”+letter[rand(letter.length)]+
letter[rand(letter.length)]+”#{rand(9)}”+letter[rand(letter.length)]+letter[rand(letter.length)]+
letter[rand(letter.length)]+letter[rand(letter.length)]+”#{rand(9)}”
end

dir = “../setup/videos”
$files = Dir.entries(dir)
puts “Before rename”
puts $files
$files.each do |f|
next if f == “.” or f == “..”
oldFile = dir + “\\” + f
newFile = dir + “\\#{rando;@name}” + “.”+f.split(“.”)[1]
File.rename(oldFile, newFile)
@file_path=File.expand_path(newFile)
@file_path=@file_path.gsub(“/”,”\\”)
end
puts “After Renamed”
$files = Dir.entries(dir)
puts $files

OUTPUT:

Before rename
.
..
four.flv
one.flv
three.flv
two.flv
After Renamed
.
..
f5vdc7zw3vplz8.flv
h5yyy5xj1jmbg8.flv
m6roa8sp5lqbq1.flv
q4rtq5ui0zdvx0.flv

Random names in Ruby

August 1, 2009

Code:

def rando
letter=(“a”..”z”).to_a
return @name=
letter[rand(letter.length)]+”#{rand(9)}”+letter[rand(letter.length)]+
letter[rand(letter.length)]+letter[rand(letter.length)]+”#          {rand(9)}”+letter[rand(letter.length)]+
letter[rand(letter.length)]+”#    {rand(9)}”+letter[rand(letter.length)]+letter[rand(letter.length)]+
letter[rand(letter.length)]+letter[rand(letter.length)]+”#{rand(9)}”
end

rando
puts @name

Output:

o1epp7yn0clbk4

Examples

Basic usage:

  ask("Company?  ") { |q| q.default = "none" }

Validation:

  ask("Age?  ", Integer) { |q| q.in = 0..105 }
  ask("Name?  (last, first)  ")
 { |q| q.validate = /\A\w+, ?\w+\Z/ }

Type conversion for answers:

  ask("Birthday?  ", Date)
  ask("Interests?  (comma sep list)  ",
lambda { |str| str.split(/,\s*/) })

Reading passwords:

  ask("Enter your password:  ") { |q| q.echo = false }
  ask("Enter your password:  ") { |q| q.echo = "x" }

ERb based output (with HighLine‘s ANSI color tools):

  say("This should be <%= color('bold', BOLD) %>!")

Menus:

  choose do |menu|
    menu.prompt = "Please choose your favorite
programming language?  "

    menu.choice(:ruby) { say("Good choice!") }
    menu.choices(:python, :perl)
{ say("Not from around here, are you?") }
  end

Reference --> http://highline.rubyforge.org/doc/

Accessing Excel in Ruby

CODE:

require ‘win32ole’
excel = WIN32OLE.new(‘excel.application’)
excel.visible = true
work=excel.workbooks.open(“C:\\Documents and Settings\\raveendran\\Desktop\\output.xls”)
excel.range(“A1″).value = “name”
excel.range(“B1″).value = “address”
excel.range(“C1″).value = “city “
excel.range(“D1″).value = “state “
excel.range(“E1″).value = “zip”
work.save

OUPUT:

Excel

Ruby – Big Decimal

June 29, 2009

Code:

require ‘bigdecimal’
x = BigDecimal(“123.6″) – BigDecimal(“123″)
puts x.to_f
puts  f=123.6 – 123

require ‘bigdecimal’

x = BigDecimal(“123.6″) – BigDecimal(“123″)

puts x.to_f

puts  f=123.6 – 123

OUTPUT:

0.6

0.599999999999994

Ruby - convert number to english word

CODE :

class Fixnum
 def english_word
  @h = {0=>"zero", 1=>"One", 2=>"Two", 3=>"Three",
 4=>"Four", 5=>"Five",6=>"six", 7=>"seven", 8=>"Eight",
9=>"Nine",10=>"Ten",11=>"Eleven",12=>"Twelve",
13=>"Thirteen",14=>"Fourteen",15=>"Fifteen",
16=>"Sixteen",17=>"Seventeen",18=>"Eighteen",
19=>"Nineteen",20=>"Twenty",30=>"Thirty",
40=>"Fourty",50=>"Fifty",60=>"Sixty",70=>"Seventy",
80=>"Eighty",90=>"Ninty"}
  @i=0
  @array=[]
  @result=""a
  if self > 99
    str_num=self.to_s #@num.to_s
    str_num_len=str_num.length
    str_full_num=str_num.insert(0,"0"*(11-str_num_len))
    str_full_num=str_num.insert(8,"0")
    str_full_num.scan(/../) { |x|  @array<<x }
    6.times do
    self.def_calc
    @i+=1
    end
  else
     if self > 9
        puts
(self.proc_double_dig((self/10)*10))+
(self.proc_single_dig(self%10))
     else
       if self > 0
       puts self.proc_single_dig(self)
       else
        return "AMOUNT NOT KNOWN or NILL"
       end
     end
  end
  end

  def def_calc
    case @i
      when 0
        str=self.proc_unit(@array[@i])
        if (str.scan(/\w+/)).length!=0
             then str=str+ "hundred & "
              @result=@result+str
        end
      when 1
        str=self.proc_unit(@array[@i])
        if (str.scan(/\w+/)).length!=0
             then str=str+ " Crore, "
             @result=@result+str
        end
      when 2
        str=self.proc_unit(@array[@i])
        if (str.scan(/\w+/)).length!=0
             then str=str+ " Lakh, "
             @result=@result+str
        end
      when 3
        str=self.proc_unit(@array[@i])
        if (str.scan(/\w+/)).length!=0
             then str=str+ " Thousand, "
             @result=@result+str
        end
      when 4
        str=self.proc_unit(@array[@i])
        if (str.scan(/\w+/)).length!=0
             then str=str+ " Hundred, "
             @result=@result+str
        end
      when 5
        str=self.proc_unit(@array[@i])
        if (str.scan(/\w+/)).length!=0
             then str=str+ ". "
             @result=@result+str
        end
        print @result.sub(/..$/,"")
    else
   end
  end

  def proc_unit(x)
    if x.to_i>0
      if x.to_i<=10
        return self.proc_single_dig(x.to_i)
      else
        if x.to_i<=20
        return self.proc_double_dig(x.to_i)
        else
        return
(self.proc_double_dig((x.to_i/10)*10))+
(self.proc_single_dig(x.to_i%10))
        end
     end
    end
  return ""
  end

  def proc_double_dig(z)
    if z==0
      return ""
    else
      return @h[z]
    end
 end

  def proc_single_dig(y)
    if y==0
      return ""
    else
      return @h[y]
    end
  end
protected :def_calc, :proc_unit, :proc_double_dig,
  :proc_single_dig

end

puts 453645445.english_word

#FourtyFive Crore, Thirtysix Lakh, FourtyFive Thousand,
Four Hundred,FourtyFive

Note:
The above code works only up to billions.

jazzez 1.1.1 released

April 14, 2009

Home page –> http://rubyforge.org/projects/jazzez/

Installation:

>gem install jazzez

Documentation for Jazzez Version 1.1.1 gem:

1. Get the links from URL

Ex.

require ‘jazzez’
output= Jazzez.new
puts output.links(“google.com\”)

Output:

http://images.google.com/imghp?hl=en&tab=wi
http://maps.google.com/maps?hl=en&tab=wl
http://news.google.com/nwshp?hl=en&tab=wn
http://video.google.com/?hl=en&tab=wv
http://mail.google.com/mail/?hl=en&tab=wm
http://www.google.com/intl/en/options/
https://www.google.com/accounts/Login?continue=http://66.249.89.44/&hl=en
http://google.com/advanced_search?hl=en
http://google.com/preferences?hl=en
http://google.com/language_tools?hl=en
http://google.com/intl/en/ads/
http://google.com/services/
http://google.com/intl/en/about.html
http://www.google.com/ncr
http://google.com/intl/en/privacy.html

Usage:

1. Get the URL from User.
2. Make sure to check whether it is valid or not.
3. If it is valid, then get the source code for that page with the help of Mechanize gem.
4. Get all the <a> tags & collect only HREF Values in that page with the help of Mechanize gem
5. If the href values not having the domains then add a URL(homepage) + Href value.
6. return the results to User as an array

2. Get the Second level links

Ex.

require ‘jazzez’
output= Jazzez.new
puts output.links_level2(“google.com\”)

Output:

It gives the Second level outputs.

http://64.233.183.18
http://adwords.google.com/select/Login?http://adwords.google.com/select/Login?sourceid=awo&subid=us-en-et-bizsol-0-biz1-all&medium=link&hl=en_US
http://adwords.google.com/select/Login?sourceid=awo&subid=us-en-et-bizsol-0-biz1-all&medium=link&hl=en_US
http://books.google.com/
http://checkout.google.com/sell?promo=sbs&utm_medium=et&utm_source=us-en-et-bizsol-0-biz1-all&utm_campaign=en
http://code.google.com/appengine/privacy.html
http://desktop.google.com/privacypolicy.html
http://gmail.google.com/gmail/help/privacy.html
http://google.com../
http://google.com/
http://google.com/a/help/intl/en/users/privacy.html
http://google.com/about.html
http://google.com/accounts/TOS
http://google.com/advanced_search?hl=en
http://google.com/bsd
http://google.com/chrome/intl/en/privacy.html
http://google.com/codesearch?hl=en
http://google.com/goog411/privacy.html
http://google.com/google-d-s/privacy.html
http://google.com/googlecalendar/privacy_policy.html
http://google.com/help/customize.html#searchlang
http://google.com/help/privacy_fusionph.html
http://google.com/ig/usgov
http://google.com/intl/en-US/health/about/privacy.html
http://google.com/intl/en/about.html
http://google.com/intl/en/ads/
http://google.com/intl/en/help/customize.html
http://google.com/intl/en/help/customize.html#safe
http://google.com/intl/en/privacy.html
http://google.com/intl/en/sketchup/3dwh/privacy.html
http://google.com/language_tools?hl=en
http://google.com/linux
http://google.com/mac
http://google.com/mail/help/tasks/privacy.html
http://google.com/microsoft
http://google.com/mobile/android/privacy.html
http://google.com/options/universities.html
http://google.com/preferences?hl=en
http://google.com/searchhistory/privacy.html
http://google.com/services/
http://google.com/support/bin/request.py?form_type=user&stage=fm&user_type=user&contact_type=privacy&hl=en
http://google.com/support/toolbar/?quick=privacy
http://google.com/support?hl=en
http://google.com/talk/privacy.html
http://google.com/tools/firefox/extensions_privacy.html
http://google.comabout.html
http://google.comads/
http://google.comcontact/
http://google.comcookies.html
http://google.comcorporate/
http://google.comhelp/features.html
http://google.comhelp/refinesearch.html
http://google.comjobs/
http://google.comoptions/
http://google.compress/
http://google.comprivacy.html
http://google.comprivacy_ads.html
http://google.comprivacy_blogs.html
http://google.comprivacy_faq.html
http://google.comprivacy_glossary.html
http://google.comprivacy_highlights.html
http://google.comprivacy_moderator.html
http://google.comprivacy_terms.html
http://google.comprivacypolicy.html
http://google.comservices/
http://google.comstickers.html
http://google.comsubmit_content.html
http://google.comwebmasters/
http://googleblog.blogspot.com
http://groups-beta.google.com/googlegroups/privacy.html
http://images.google.com/imghp?hl=en&tab=wi
http://investor.google.com
http://labs.google.com/
http://mail.google.com/mail/?hl=en&tab=wm
http://maps.google.com/help/privacy_maps.html
http://maps.google.com/maps?hl=en&tab=wl
http://mobile.google.com/privacy.html
http://news.google.com/archivesearch
http://news.google.com/nwshp?hl=en&tab=wn
http://picasa.google.com/web/privacy.html
http://scholar.google.com/
http://services.google.com/ads_inquiry/en
http://services.google.com/tcbin/tc.py
http://video.google.com/?hl=en&tab=wv
http://webaccelerator.google.com/privacy.html
http://www.blogger.com/privacy
http://www.google.ad
http://www.google.ae
http://www.google.am
http://www.google.as
http://www.google.at
http://www.google.az
http://www.google.ba
http://www.google.be
http://www.google.bg
http://www.google.bi
http://www.google.bs
http://www.google.ca
http://www.google.cd
http://www.google.cg
http://www.google.ch
http://www.google.ci
http://www.google.cl
http://www.google.cn
http://www.google.co.bw
http://www.google.co.ck
http://www.google.co.cr
http://www.google.co.id
http://www.google.co.il
http://www.google.co.in
http://www.google.co.jp
http://www.google.co.ke
http://www.google.co.kr
http://www.google.co.ls
http://www.google.co.ma
http://www.google.co.mz
http://www.google.co.nz
http://www.google.co.th
http://www.google.co.tz
http://www.google.co.ug
http://www.google.co.uk
http://www.google.co.uk/help/merchantsearchbeta/privacy.html
http://www.google.co.uz
http://www.google.co.ve
http://www.google.co.vi
http://www.google.co.za
http://www.google.co.zm
http://www.google.co.zw
http://www.google.com
http://www.google.com.af
http://www.google.com.ag
http://www.google.com.ai
http://www.google.com.ar
http://www.google.com.au
http://www.google.com.bd
http://www.google.com.bh
http://www.google.com.bn
http://www.google.com.bo
http://www.google.com.br
http://www.google.com.by
http://www.google.com.bz
http://www.google.com.co
http://www.google.com.cu
http://www.google.com.do
http://www.google.com.ec
http://www.google.com.eg
http://www.google.com.et
http://www.google.com.fj
http://www.google.com.gh
http://www.google.com.gi
http://www.google.com.gt
http://www.google.com.hk
http://www.google.com.jm
http://www.google.com.kh
http://www.google.com.kw
http://www.google.com.lb
http://www.google.com.ly
http://www.google.com.mt
http://www.google.com.mx
http://www.google.com.my
http://www.google.com.na
http://www.google.com.nf
http://www.google.com.ng
http://www.google.com.ni
http://www.google.com.np
http://www.google.com.om
http://www.google.com.pa
http://www.google.com.pe
http://www.google.com.ph
http://www.google.com.pk
http://www.google.com.pr
http://www.google.com.py
http://www.google.com.qa
http://www.google.com.sa
http://www.google.com.sb
http://www.google.com.sg
http://www.google.com.sl
http://www.google.com.sv
http://www.google.com.tj
http://www.google.com.tr
http://www.google.com.tw
http://www.google.com.ua
http://www.google.com.uy
http://www.google.com.vc
http://www.google.com.vn
http://www.google.com/a/?utm_medium=et&utm_source=us-en-et-bizsol-0-biz1-all&utm_campaign=en
http://www.google.com/admanager?utm_source=bizsol_us&utm_medium=et&utm_campaign=bizsol
http://www.google.com/adsense/?hl=en_US&sourceid=aso&subid=ww-en-et-ads-0-adsC-all&hl=en_us
http://www.google.com/adserving/index.html#utm_source=ads&utm_medium=et&utm_campaign=ads-en-us
http://www.google.com/analytics#utm_medium=et&utm_source=us-en-et-bizsol-0-biz1_top_img&utm_campaign=en
http://www.google.com/analytics#utm_medium=et&utm_source=us-en-et-bizsol-0-biz1_top_link&utm_campaign=en
http://www.google.com/analytics/#utm_medium=et&utm_source=us-en-et-bizsol-0-biz1-all&utm_campaign=en
http://www.google.com/base/?utm_medium=et&utm_source=us-en-et-bizsol-0-biz1-all&utm_campaign=en
http://www.google.com/chrome/index.html?brand=CHMH&utm_source=ww-et-abt&utm_medium=abt&utm_campaign=en
http://www.google.com/enterprise/geospatial.html#utm_medium=et&utm_source=us-en-et-bizsol-0-biz1-all&utm_campaign=en
http://www.google.com/enterprise/public_search.html#utm_medium=et&utm_source=us-en-et-bizsol-0-biz1-all&utm_campaign=en
http://www.google.com/friendconnect/?utm_medium=et&utm_campaign=en&utm_source=en-et-na-us-bizsol
http://www.google.com/intl/af/
http://www.google.com/intl/am/
http://www.google.com/intl/ar/
http://www.google.com/intl/az/
http://www.google.com/intl/be/
http://www.google.com/intl/bg/
http://www.google.com/intl/bh/
http://www.google.com/intl/bn/
http://www.google.com/intl/br/
http://www.google.com/intl/bs/
http://www.google.com/intl/ca/
http://www.google.com/intl/co/
http://www.google.com/intl/cs/
http://www.google.com/intl/cy/
http://www.google.com/intl/da/
http://www.google.com/intl/de/
http://www.google.com/intl/el/
http://www.google.com/intl/en/
http://www.google.com/intl/en/about.html
http://www.google.com/intl/en/options/
http://www.google.com/intl/eo/
http://www.google.com/intl/es/
http://www.google.com/intl/et/
http://www.google.com/intl/eu/
http://www.google.com/intl/fa/
http://www.google.com/intl/fi/
http://www.google.com/intl/fo/
http://www.google.com/intl/fr/
http://www.google.com/intl/fy/
http://www.google.com/intl/ga/
http://www.google.com/intl/gd/
http://www.google.com/intl/gl/
http://www.google.com/intl/gn/
http://www.google.com/intl/gu/
http://www.google.com/intl/ha/
http://www.google.com/intl/hi/
http://www.google.com/intl/hr/
http://www.google.com/intl/hu/
http://www.google.com/intl/hy/
http://www.google.com/intl/ia/
http://www.google.com/intl/id/
http://www.google.com/intl/is/
http://www.google.com/intl/it/
http://www.google.com/intl/iw/
http://www.google.com/intl/ja/
http://www.google.com/intl/jw/
http://www.google.com/intl/ka/
http://www.google.com/intl/kk/
http://www.google.com/intl/km/
http://www.google.com/intl/kn/
http://www.google.com/intl/ko/
http://www.google.com/intl/ku/
http://www.google.com/intl/ky/
http://www.google.com/intl/la/
http://www.google.com/intl/ln/
http://www.google.com/intl/lo/
http://www.google.com/intl/lt/
http://www.google.com/intl/lv/
http://www.google.com/intl/mg/
http://www.google.com/intl/mi/
http://www.google.com/intl/mk/
http://www.google.com/intl/ml/
http://www.google.com/intl/mn/
http://www.google.com/intl/mo/
http://www.google.com/intl/mr/
http://www.google.com/intl/ms/
http://www.google.com/intl/mt/
http://www.google.com/intl/ne/
http://www.google.com/intl/nl/
http://www.google.com/intl/nn/
http://www.google.com/intl/no/
http://www.google.com/intl/oc/
http://www.google.com/intl/om/
http://www.google.com/intl/or/
http://www.google.com/intl/pa/
http://www.google.com/intl/pl/
http://www.google.com/intl/ps/
http://www.google.com/intl/pt-BR/
http://www.google.com/intl/pt-PT/
http://www.google.com/intl/qu/
http://www.google.com/intl/rm/
http://www.google.com/intl/rn/
http://www.google.com/intl/ro/
http://www.google.com/intl/ru/
http://www.google.com/intl/rw/
http://www.google.com/intl/sd/
http://www.google.com/intl/sh/
http://www.google.com/intl/si/
http://www.google.com/intl/sk/
http://www.google.com/intl/sl/
http://www.google.com/intl/sn/
http://www.google.com/intl/so/
http://www.google.com/intl/sq/
http://www.google.com/intl/sr-ME/
http://www.google.com/intl/sr/
http://www.google.com/intl/st/
http://www.google.com/intl/su/
http://www.google.com/intl/sv/
http://www.google.com/intl/sw/
http://www.google.com/intl/ta/
http://www.google.com/intl/te/
http://www.google.com/intl/tg/
http://www.google.com/intl/th/
http://www.google.com/intl/ti/
http://www.google.com/intl/tk/
http://www.google.com/intl/tl/
http://www.google.com/intl/to/
http://www.google.com/intl/tr/
http://www.google.com/intl/tt/
http://www.google.com/intl/tw/
http://www.google.com/intl/ug/
http://www.google.com/intl/uk/
http://www.google.com/intl/ur/
http://www.google.com/intl/uz/
http://www.google.com/intl/vi/
http://www.google.com/intl/xh/
http://www.google.com/intl/xx-bork/
http://www.google.com/intl/xx-elmer/
http://www.google.com/intl/xx-hacker/
http://www.google.com/intl/xx-klingon/
http://www.google.com/intl/xx-pirate/
http://www.google.com/intl/yi/
http://www.google.com/intl/yo/
http://www.google.com/intl/zh-CN/
http://www.google.com/intl/zh-TW/
http://www.google.com/intl/zu/
http://www.google.com/local/add/login?utm_medium=et&utm_source=us-en-et-bizsol-0-biz1-all&utm_campaign=en&hl=en_US&gl=US
http://www.google.com/ncr
http://www.google.com/postini/index.html#utm_medium=et&utm_source=us-en-et-bizsol-0-biz1-all&utm_campaign=en
http://www.google.com/sites/help/intl/en/privacy_policy.html
http://www.google.com/sitesearch#utm_medium=et&utm_source=us-en-et-bizsol-0-biz1-all&utm_campaign=en
http://www.google.com/support/bin/answer.py?answer=29508
http://www.google.com/tools/firefox/toolbar/FT3/intl/en/index.html?utm_source=ww-en-et-about&utm_medium=et&utm_campaign=en
http://www.google.com/transconsole
http://www.google.com/webhp?hl=en
http://www.google.com/webmasters/#utm_medium=et&utm_source=us-en-et-bizsol-0-biz1-all&utm_campaign=en
http://www.google.cz
http://www.google.de
http://www.google.dj
http://www.google.dk
http://www.google.dm
http://www.google.dz
http://www.google.ee
http://www.google.es
http://www.google.fi
http://www.google.fm
http://www.google.fr
http://www.google.ge
http://www.google.gg
http://www.google.gl
http://www.google.gm
http://www.google.gp
http://www.google.gr
http://www.google.gy
http://www.google.hn
http://www.google.hr
http://www.google.ht
http://www.google.hu
http://www.google.ie
http://www.google.im
http://www.google.is
http://www.google.it
http://www.google.it.ao
http://www.google.je
http://www.google.jo
http://www.google.kg
http://www.google.ki
http://www.google.kz
http://www.google.la
http://www.google.li
http://www.google.lk
http://www.google.lt
http://www.google.lu
http://www.google.lv
http://www.google.md
http://www.google.me
http://www.google.mg
http://www.google.mn
http://www.google.ms
http://www.google.mu
http://www.google.mv
http://www.google.mw
http://www.google.nl
http://www.google.no
http://www.google.nr
http://www.google.nu
http://www.google.pl
http://www.google.pn
http://www.google.pt
http://www.google.ro
http://www.google.rs
http://www.google.ru
http://www.google.rw
http://www.google.sc
http://www.google.se
http://www.google.sh
http://www.google.si
http://www.google.sk
http://www.google.sm
http://www.google.sn
http://www.google.st
http://www.google.tk
http://www.google.tl
http://www.google.tm
http://www.google.to
http://www.google.tt
http://www.google.vg
http://www.google.vu
http://www.google.ws
http://www.googlestore.com
http://www.googlestore.com/privacy.asp
http://www.orkut.com/privacy.aspx
http://www.postini.com/legal/privacy.php
http://www.youtube.com/t/privacy
https://adwords.google.com/select/Login?sourceid=awo&subid=us-en-et-bizsol-0-biz1-all&medium=link&hl=en_US
https://adwords.google.com/select/Login?sourceid=awo&subid=ww-en-et-about_page&medium=link
https://adwords.google.com/select/Login?sourceid=awo&subid=ww-en-et-ads-0-adsC-all&hl=en_us
https://adwords.google.com/select/StartNewAccount?sourceid=awo&subid=us-en-et-bizsol-0-biz1-all&medium=link&hl=en_US
https://adwords.google.com/select/starter/signup/ForkAuth?sourceid=awo&subid=ww-en-et-ads-0-adsC-all&hl=en_us
https://checkout.google.com/files/privacy.html
https://knol.google.com/k/knol-help/-/si57lahl1w25/15#view
https://www.google.com/accounts/Login?continue=http://64.233.183.18/language_tools%3Fhl%3Den&hl=en
https://www.google.com/accounts/Login?continue=http://64.233.183.81/preferences%3Fhl%3Den&hl=en
https://www.google.com/accounts/Login?continue=http://72.14.203.102/advanced_search%3Fhl%3Den&hl=en
https://www.google.com/accounts/Login?continue=http://72.14.235.83/&hl=en
https://www.google.com/accounts/ServiceLogin?continue=http://64.233.183.81/preferences%3Fhl%3Den
https://www.google.com/accounts/ServiceLogin?service=websiteoptimizer&hl=en&continue=https%3A%2F%2Fwww.google.com%2Fanalytics%2Fsiteopt%2F%3Fet%3Dreset%26hl%3Den&utm_medium=et&utm_source=us-en-et-bizsol-0-biz1-all&utm_campaign=en
https://www.google.com/adsense/?sourceid=aso&subid=us-en-et-bizsol-0-biz1-all&medium=link&hl=en_US
https://www.google.com/adsense/?sourceid=aso&subid=ww-en-et-bizsol-biz1_top_img&hl=en_us
https://www.google.com/adsense/?sourceid=aso&subid=ww-en-et-bizsol-biz1_top_link&hl=en_us
https://www.google.com/adsense/g-app-single-1?hl=en_US&sourceid=aso&subid=ww-en-et-ads-0-adsC-all&hl=en_us
https://www.google.com/voice/help/privacy

3. Get the Html tags

Ex.

require ‘jazzez’
output= Jazzez.new
puts output.tagdetails(“google.com\”)

Output:

1<html tag(s)
1</html> tag(s)
1<head tag(s)
1</head> tag(s)
1<body tag(s)
1</body> tag(s)
2<table tag(s)
2</table> tag(s)
3<tr tag(s)
3</tr> tag(s)
9<td tag(s)
9</td> tag(s)
0<th tag(s)
0</th> tag(s)
0<l tag(s)
0</l> tag(s)
0<link tag(s)
1<p tag(s)
1</p> tag(s)
4<div tag(s)
4</div> tag(s)
0<span tag(s)
0</span> tag(s)
4<script tag(s)
4</script> tag(s)
0<ul tag(s)
0</ul> tag(s)
0<ol tag(s)
0</ol> tag(s)
16<a tag(s)
15</a> tag(s)
0<h1 tag(s)
0</h1> tag(s)
0<h2 tag(s)
0</h2> tag(s)
0<h3 tag(s)
0</h3> tag(s)
0<h4 tag(s)
0</h4> tag(s)
0<h5 tag(s)
0</h5> tag(s)
0<h6 tag(s)
0</h6> tag(s)
4<font tag(s)
4</font> tag(s)
0<select tag(s)
0</select> tag(s)
0<option tag(s)
0</option> tag(s)

Usage:

Easy to answer the below questions

How many tables in your code ?
How many table rows/coloums in your code ?
How Many div tags opened and how many div tags closed ?
Are you sure your html tags were properly closed ?

More functions available in next version.

Any queries just send a mail to jazzezravi@gmail.com.

HTTP Status Codes

April 14, 2009

* 200 OK: everything went awesome.

* 304 Not Modified: there was no new data to return.

* 400 Bad Request: your request is invalid, and we’ll return an error message that tells you why. This is the status code returned if you’ve exceeded the rate limit (see below).

* 401 Not Authorized: either you need to provide authentication credentials, or the credentials provided aren’t valid.

* 403 Forbidden: we understand your request, but are refusing to fulfill it. An accompanying error message should explain why.

* 404 Not Found: either you’re requesting an invalid URI or the resource in question doesn’t exist (ex: no such user).

* 500 Internal Server Error: we did something wrong. Please post to the group about it and the  team will investigate.

* 502 Bad Gateway: returned if Application is down or being upgraded.

* 503 Service Unavailable: the Applicationservers are up, but are overloaded with requests. Try again later

Hi All,

These are all some programs solution of Ruby forum asked questions by Users. i replied them and also want to share here…

Code 1 :

def run
arr=["Raveendran","jazzezravi","jazzez","ravi","jazzezravendran"]
ram(arr)
end
def ram(arr)
arra=arr
like = [" good boy", " bad boy"," nice boy"," Gentle man"]
puts arra[rand(5)] + like[rand(4)]
end

def raja(arr)
j=0
arr=["Arun","Babu","Chitra","David","Einstein"]
while j<4 do
puts arr[j]
j+=1
end
end
5.times { run; sleep(2)}

Output:

ravi good boy
ravi good boy
jazzezravi bad boy
ravi Gentle man
jazzezravi Gentle man

————————————————————————–

Code 2:

class Bird
def preen
puts “I am cleaning my feathers.”
end
def fly
puts “I am flying.”
end
end

class Penguin<Bird
def fly
fail “Sorry. I’d rather swim.”
end
end

p=Penguin.new
puts p.preen
puts p.fly

Output:

inher2method.rb:12:in `fly’: Sorry. I’d rather swim. (RuntimeError)
from inher2method.rb:18
I am cleaning my feathers.
nil

————————————————————————

Code 3:

# ansi_colors.rb
#
# Created by James Edward Gray II on 2005-05-03.
# Copyright 2005 Gray Productions. All rights reserved.

require “rubygems”
require “highline/import”

# Supported color sequences.
colors = %w{black red green yellow blue magenta cyan white}

# Using color() with symbols.
colors.each_with_index do |c, i|
say(“This should be <%= color(‘#{c}’, :#{c}) %>!”)
if i == 0
say( “This should be ” +
“<%= color(‘white on #{c}’, :white, :o n_#{c}) %>!”)
else
say( “This should be ” +
“<%= color( ‘#{colors[i - 1]} on #{c}’,
:#{colors[i - 1]}, :o n_#{c} ) %>!”)
end
end

# Using color with constants.
say(“This should be <%= color(‘bold’, BOLD) %>!”)
say(“This should be <%= color(‘underlined’, UNDERLINE) %>!”)

# Using constants only.
say(“This might even <%= BLINK %>blink<%= CLEAR %>!”)

# It even works with list wrapping.
erb_digits = %w{Zero One Two Three Four} +
["<%= color('Five', :blue) %%>"] +
%w{Six Seven Eight Nine}
say(“<%= list(#{erb_digits.inspect}, :columns_down, 3) %>”)

Output:

This should be black!
This should be white on black!
This should be red!
This should be black on red!
This should be green!
This should be red on green!
This should be yellow!
This should be green on yellow!
This should be blue!
This should be yellow on blue!
This should be magenta!
This should be blue on magenta!
This should be cyan!
This should be magenta on cyan!
This should be white!
This should be cyan on white!
This should be bold!
This should be underlined!
This might even blink!
Zero Four Eight
One Five Nine
Two Six
Three Seven

------------------------------------------------------------------------

Code 4:

require 'win32ole'
fso = WIN32OLE.new('Scripting.FileSystemObject')
folder = fso.GetFolder('C:\Documents and Settings\raveendran\My Documents\My Pictures\Trubee')
puts folder.name
puts folder.size
puts folder.path

Output:

Trubee
14948754
C:\Documents and Settings\raveendran\My Documents\My Pictures\Trubee

-----------------------------------------------------------------------------

High line Example Code 5:

require "highline/import"

zipcode = ask("Zip? ") { |zip| zip.validate = /\A\d{5}(?:-?\d{4})?\Z/ }

Output:

Zip? hiuhi8
Your answer isn't valid (must match /\A\d{5}(?:-?\d{4})?\Z/).
? ttrtrt
Your answer isn't valid (must match /\A\d{5}(?:-?\d{4})?\Z/).
? 90204

---------------------------------------------------------------------------

HighLine Example Code 6:

#!/usr/local/bin/ruby -w

require "rubygems"
require "highline/import"

# The old way, using ask() and say()...
choices = %w{ruby python perl}
say("This is the old way using ask() and say()...")
say("Please choose your favorite programming language:")
say(choices.map { |c| " #{c}\n" }.join)

case ask("? ", choices)
when "ruby"
say("Good choice!")
else
say("Not from around here, are you?")
end

# The new and improved choose()...
say("\nThis is the new mode (default)...")
choose do |menu|
menu.prompt = "Please choose your favorite programming language? "

menu.choice :ruby do say("Good choice!") end
menu.choices(:python, :perl) do say("Not from around here, are you?") end
end

say("\nThis is letter indexing...")
choose do |menu|
menu.index = :letter
menu.index_suffix = ") "

menu.prompt = "Please choose your favorite programming language? "

menu.choice :ruby do say("Good choice!") end
menu.choices(:python, :perl) do say("Not from around here, are you?") end
end

say("\nThis is with a different layout...")
choose do |menu|
menu.layout = :o ne_line

menu.header = "Languages"
menu.prompt = "Favorite? "

menu.choice :ruby do say("Good choice!") end
menu.choices(:python, :perl) do say("Not from around here, are you?") end
end

say("\nYou can even build shells...")
loop do
choose do |menu|
menu.layout = :menu_only

menu.shell = true

menu.choice(:load, "Load a file.") do |command, details|
say("Loading file with options: #{details}...")
end
menu.choice(:save, "Save a file.") do |command, details|
say("Saving file with options: #{details}...")
end
menu.choice(:quit, "Exit program.") { exit }
end
end

Output:

This is the old way using ask() and say()...
Please choose your favorite programming language:
ruby
python
perl
? ruby
You must choose one of ["ruby", "python", "perl"].
? runy
You must choose one of ["ruby", "python", "perl"].
? 1
You must choose one of ["ruby", "python", "perl"].
? perl
Not from around here, are you?

This is the new mode (default)…
1. ruby
2. python
3. perl
Please choose your favorite programming language? 1
Good choice!

This is letter indexing…
a) ruby
b) python
c) perl
Please choose your favorite programming language? ruby
You must choose one of ["a", "b", "c", :ruby, :python, :perl].
? a
Good choice!

This is with a different layout…
Languages: Favorite? (ruby, python or perl) ruby
Good choice!

You can even build shells…
load, save, quit or help? q

—————————————————————————

Transpose Code 7:

arr = ["abc", ["def1", "def2", "def3"]]
arr_final=[]
arr[0] = [arr[0]] * arr[1].size
p arr.transpose

Output:

[["abc", "def1"], ["abc", "def2"], ["abc", "def3"]]

———————————————————————–

Astrlrologicel help Code 8:

class Reservoir
def main

puts “Please Enter the name”
b=gets()

a=b.downcase
puts a
val={“a”=>1,”j”=>1,”s”=>1,
“b”=>2,”k”=>2,”t”=>2,
“c”=>3,”l”=>3,”u”=>3,
“d”=>4,”m”=>4,”v”=>4,
“e”=>5,”n”=>5,”w”=>5,
“f”=>6,”o”=>6,”x”=>6,
“g”=>7,”p”=>7,”y”=>7,
“h”=>8,”q”=>8,”z”=>8,
“i”=>9,”r”=>9}

num=[]
i=0
#puts a
while i < a.length do
num << val[a[i,1]]
i+=1
end
mind(num)
end

def mind(num)
no=[]
no=num
j=0

final=0
while j < no.length
final +=num[j].to_i
j+=1
end
output= final.to_s
if output.length !=1
output2=output.split(//)
mind(output2)
else
puts final
end
end
end

res=Reservoir.new
res.main

Output:

Please Enter the name
raveendran
3 # This number will give some astrological theories.

————————————————————————

MYSQL Code 9:

require ‘mysql’

my_array= ["google.com","yahoo.com"]

db = Mysql::new(“localhost”, “root”, “”, “new_development”)

my_array.each do |a|
puts a
b = a.collect{|x| x = “‘” + x + “‘”}
puts b
c = b.join(“,”)
puts c
sql = “INSERT INTO sites VALUES (3,#{c},0,0);”
db.query(sql)
end

——————————————————————

Big Decimal Code 10:

require ‘bigdecimal’
x = BigDecimal(“123.6″) – BigDecimal(“123″)

puts x.to_f

puts f=123.6 – 123

Output:

0.6
0.599999999999994

——————————————————————-

File Stat Code 11:

puts a= File.stat(“hi.txt”).uid
puts a= File.stat(“hi.txt”).nlink

Output:

0

1

——————————————————————

HTML Tag Helper Code 12:

source=File.open(“wordpress.txt”)

search=["<html","</html>","<head","</head>","<body","</body>","<table","</table>","<tr","</tr>","<td","</td>",
"<th","</th>","<p","</p>","<div","</div>","<span","</span>",
"<script","</script>","<ul","</ul>","<li","</li>","<ol","</ol>","<a","</a>","<h1","</h1>","<h2","</h2>",
"<h3","</h3>","<h4","</h4>","<h5","</h5>","<h6","</h6>","<font","</font>"]

tag=[]
source.each do |line|
i=0

while i < search.length do
taghelp = line.downcase.match(search[i]).to_s
tag << taghelp unless taghelp.empty?
i+=1
end

end

j=0
while j< search.length do

count= tag.grep(search[j])
puts count.length.to_s + search[j].to_s + ” tag”
j+=1

end

WordPress.txt File has –> View source code of the testing web page

Output:

1<html tag
1</html> tag
1<head tag
1</head> tag
1<body tag
1</body> tag
0<table tag
0</table> tag
0<tr tag
0</tr> tag
0<td tag
0</td> tag
0<th tag
0</th> tag
0<p tag
0</p> tag
117<div tag
117</div> tag
30<span tag
30</span> tag
14<script tag
14</script> tag
0<ul tag
0</ul> tag
2<li tag
0</li> tag
0<ol tag
0</ol> tag
17<a tag
17</a> tag
12<h1 tag
12</h1> tag
0<h2 tag
0</h2> tag
0<h3 tag
0</h3> tag
0<h4 tag
0</h4> tag
0<h5 tag
0</h5> tag
0<h6 tag
0</h6> tag
0<font tag
0</font> tag

—————————————————————-

Infinite Loop Code 13:

class X
def m; “m”; end
end

class Y < X
def self.method_added(sym)
puts sym
#return if /^__/ === sym.to_s
alias_method(“__#{sym}”, sym)
remove_method(sym)
end
def m; m; end
end

#class Y
#def m; m; end
#end

Y.new

Output:

m
__m
____m
______m
________m
__________m
____________m
______________m
________________m
__________________m

—————————————————————————

Next 30 days List Code 14:

date= Date.today
enddate=date + 30
weekday=[0,1,2,3,4,5,6]

while enddate > date
puts date.to_s+” sunday” if date.wday==0
puts date.to_s+” monday” if date.wday==1
puts date.to_s+” tuesday” if date.wday==2
puts date.to_s+” Wednesday” if date.wday==3
puts date.to_s+” thursday” if date.wday==4
puts date.to_s+” friday” if date.wday==5
puts date.to_s+” saturday” if date.wday==6
date+=1
end

Output:

2008-08-08 friday
2008-08-09 saturday
2008-08-10 sunday
2008-08-11 monday
2008-08-12 tuesday
2008-08-13 Wednesday
2008-08-14 thursday
2008-08-15 friday
2008-08-16 saturday
2008-08-17 sunday
2008-08-18 monday
2008-08-19 tuesday
2008-08-20 Wednesday
2008-08-21 thursday
2008-08-22 friday
2008-08-23 saturday
2008-08-24 sunday
2008-08-25 monday
2008-08-26 tuesday
2008-08-27 Wednesday
2008-08-28 thursday
2008-08-29 friday
2008-08-30 saturday
2008-08-31 sunday
2008-09-01 monday
2008-09-02 tuesday
2008-09-03 Wednesday
2008-09-04 thursday
2008-09-05 friday
2008-09-06 saturday

————————————————————————–

Class Variable Code 15:

class Second
puts @@a=34
def sec
puts @@a=66
end
end

class Check < Second
@@a=58
def one
@@a=34
end
end
c=Check.new()
puts c.one
puts c.sec

Output:

34
34
66
nil

————————————————————————–

Watir Cheat sheet

December 17, 2007

Watir Cheat Sheet

 

Getting Started with Watir

require ‘watir’

Load the Watir library

ie = Watir::IE.start

(‘http://localhost:8080′)

Start IE using the local timeclock server.

ie.close

Close IE.

ie = Watir::IE.attach(:title, ‘title‘)

Attach to an existing IE window, so you can drive it with Watir.

 

Manipulating Controls with Watir

ie.text_field(:name, ‘name‘).set(‘value‘)

Set the text field specified name specified value.

ie.button(:value, ‘value‘).click

Click the button with the specified value (label)

ie.button(:name, ‘name‘).click

Click the button with the specified name.

ie.checkbox(:name, ‘name‘).set

Check the check box named “name”. (Uncheck: clear)

ie.object(:attribute, ‘name‘).flash

Cause the specified control to flash.

 

A Special Testing Function For Timeclock

 

require ‘toolkit/testhook’

ensure_no_user_data ‘name

Delete any database records for the named user.

 

Accessing Page Contents with Watir

ie.contains_text(‘text‘)

Return true if the current page has the specified text somewhere on the page. Otherwise, false.

ie.title

Return the title of the current page.

ie.html

Return all the HTML in the body of the page

ie.table(:id, ‘recent_records).to_a

Return an array containing the text in the table’s rows and columns.

ie.table(:id, ‘recent_records’)[2][1].text

Return the text from the first column of the second row of the table id’d ‘recent_records.

 

Assertions

assert_equal(expected, test_method)

Test whether the expected value matches the actual value returned by the test method

assert_match(regexp, test_method)

Test whether the regular expression matches the actual value returned by the test method.

assert(expression)

Test whether the expression is true.