require 'date'
class Date
def self.last_day_of_the_month yyyy, mm
d = new yyyy, mm
d += 42 # warp into the next month
new(d.year, d.month) - 1 # back off one day from first of that month
end
def self.print_sundays(d1, d2)
d1 +=1 while (d1.wday != 0)
d1.step(d2, 7) do |date|
puts "#{Date::MONTHNAMES[date.mon]} #{date.day}"
end
end
end
date = Date.today
month = date.strftime("%m").to_i
year = date.strftime("%Y").to_i
last_date = Date.last_day_of_the_month(year, month)
l_date = last_date.strftime("%d").to_i
Date.print_sundays(Date::civil(year, month, 1), Date::civil(year, month, l_date))
my blog is abt wht i have learnt technically, mostly in Ruby on Rails, Javascript, node.js hope this share a little bit of info & adds a bit stuff., Thanks.
Tuesday, May 26, 2009
Wednesday, May 20, 2009
Jump to the top of a page
Jump to the top of a page
http://www.dynamicdrive.com/dynamicindex5/jumptop.htm
this will help in making a top link in each page.
http://www.dynamicdrive.com/dynamicindex5/jumptop.htm
this will help in making a top link in each page.
Monday, May 18, 2009
Connecting Db in ruby
MYSQL_HOST, MYSQL_USER, MYSQL_PASS, MYSQL_DB_NAME = 'localhost', 'root', '', 'artiklz_development'
@@dbh = Mysql.real_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASS, MYSQL_DB_NAME)
@@dbh = Mysql.real_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASS, MYSQL_DB_NAME)
Sunday, May 17, 2009
check whether an url is working or not..
1. For domains: ping "domain name"
2. For urls, use the following..
def check_valid_link(link_url)
retrycount = 0
begin
res = Net::HTTP.get_response(URI.parse(link_url))
if res.code =~ /2|3\d{2}/
return true
else
return false
end
rescue Timeout::Error
if retrycount < 4
retrycount += 1
sleep 3
retry
else
return false
end
rescue
return false
end
end
Labels:
rails,
ruby,
srikanth,
url,
url working,
valid link,
valid url
Subscribe to:
Posts (Atom)