Senior & Expert RoR Developers Discussion Forum by Nyros Technologies

HIRE Ruby on Rails Expert Developers Programmers Coders From India
Ruby on Rails PHP .Net Developers Community, Nyros Technologies, Kakinada
 
Log in  or IF not a member please REGISTER
Username:
Password:   


Keyword
Log in | Profile 

How to find google page rank using rails

 
Post new topic   Reply to topic    Senior & Expert RoR Developers Discussion Forum by Nyros Technologies Index -> Advanced programming
View previous topic :: View next topic  
Author Message
sharma I



Joined: 13 Jun 2008
Posts: 130

PostPosted: Sat May 22, 2010 7:26 am    Post subject: How to find google page rank using rails Reply with quote

Hi Friends,

Recently I have worked with social networking web application. In that, I need to implement calculate the google page rank for the given website.

For this, I took a new .rb file and placed in lib folder of my rails application.

lib/google_rank.rb

module RANK

class GooglePR

def initialize(uri)
@uri = uri
end

M=0x100000000 # modulo for unsigned int 32bit(4byte)

def m1(a,b,c,d)
(((a+(M-b)+(M-c))%M)^(d%M))%M # mix/power mod
end

def i2c(i)
[i&0xff, i>>8&0xff, i>>16&0xff, i>>24&0xff]
end

def c2i(s,k=0) ((s[k+3].to_i*0x100+s[k+2].to_i)*0x100+s[k+1].to_i)*0x100+s[k].to_i
end

def mix(a,b,c)
a = a%M; b = b%M; c = c%M
a = m1(a,b,c, c >> 13); b = m1(b,c,a, a << 8 ); c = m1(c,a,b, b >> 13)
a = m1(a,b,c, c >> 12); b = m1(b,c,a, a <<16); c = m1(c,a,b, b >> 5)
a = m1(a,b,c, c >> 3); b = m1(b,c,a, a <<10); c = m1(c,a,b, b >> 15)
[a, b, c]
end

def old_cn(iurl = 'info:' + @uri)
a = 0x9E3779B9; b = 0x9E3779B9; c = 0xE6359A60
len = iurl.size
k = 0
while (len >= k + 12) do
a += c2i(iurl,k); b += c2i(iurl,k+4); c += c2i(iurl,k+8 )
a, b, c = mix(a, b, c)
k = k + 12
end
a += c2i(iurl,k); b += c2i(iurl,k+4); c += (c2i(iurl,k+8 ) << 8 ) + len
a,b,c = mix(a,b,c)
return c
end

def cn
ch = old_cn
ch = ((ch/7) << 2) | ((ch-(ch/13).floor*13)&7)
new_url = []
20.times { i2c(ch).each { |i| new_url << i }; ch -= 9 }
('6' + old_cn(new_url).to_s).to_i
end

def request_uri
"http://toolbarqueries.google.com/search?client=navclient-auto&hl=en&ch=#{cn}&ie=UTF-8&oe=UTF-8&features=Rank&q=info:#{URI.escape(@uri, /[^-.!~*'()a-zA-Z\d]/)}"
end

def page_rank(uri = @uri)
@uri = uri if uri != @uri
open(request_uri) { |f| return $1.to_i if f.string =~ /Rank_1:\d : (\d+)/ }
nil
end

private :m1, :i2c, :c2i, :mix, :old_cn
attr_accessor :uri
end

end


After this, I include this module in my controller like this....

class ArticleController < ApplicationController

include FINDPAGERANK

def find_pagerank
rank = RANK::GooglePR.new("http://www.facebook.com").page_rank
render :text => rank and return
end

end


Thank you,
Sharma
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Senior & Expert RoR Developers Discussion Forum by Nyros Technologies Index -> Advanced programming
Page 1 of 1

 latest topics 
 Topics   Replies   Author   Views   Last Post 
No new posts How to customize Google Maps InfoWindow using ym4r_gm
0 kalyanallampalli 49 Thu Sep 02, 2010 5:34 pm
kalyanallampalli View latest post
No new posts Drag and Drop file upload
0 umamageshwari 45 Wed Sep 01, 2010 9:36 am
umamageshwari View latest post
No new posts Flex On Rails
0 Raghu 45 Wed Sep 01, 2010 3:00 am
Raghu View latest post
No new posts MongoDB
0 Raghu 44 Tue Aug 31, 2010 3:30 pm
Raghu View latest post
No new posts Problem with Dreamweaver / java error
3 Raja 36 Tue Aug 31, 2010 3:24 pm
Raghu View latest post
No new posts Generating Model
0 phani.galla 43 Tue Aug 31, 2010 2:09 pm
phani.galla View latest post
No new posts Hide Panels using JQuery
0 Anu 46 Tue Aug 31, 2010 1:50 pm
Anu View latest post
No new posts Load a text file using ajax in jquery
0 Anu 35 Tue Aug 31, 2010 1:39 pm
Anu View latest post
No new posts Generating Migrations
0 phani.galla 29 Tue Aug 31, 2010 1:38 pm
phani.galla View latest post
No new posts Generating Controllers
0 phani.galla 31 Tue Aug 31, 2010 1:22 pm
phani.galla View latest post




Hire an expert Ruby on Rails developer / coder / programmer or development team from India now!!

Other Forums : PHP   ::   .Net   |   Free unlimited HTML CSS templates download

Nyros Technologies   |   Kakinada City Portal   |   Developers Blog   |   About Ruby on Rails Experts   |   More