Friday, September 2, 2011

Require vs Load ruby

Thursday, August 18, 2011

IndexError: string not matched ruby hash


irb(main):001:0> s = "string"

=> "string"

irb(main):006:0> s[ 'hi' ] = 'foo'

IndexError: string not matched

from (irb):6:in
Here you already declared 's' as string then you can't use it as hash.

Wednesday, August 17, 2011

yajl http_stream authentication

Yajl::HttpStream.get("http://username:password@www.example.com")

Net::HTTP and handling 302 Redirect


I meet two kinds of redirect: "Location" response and  tag.



Here's my solution:

================================================

require 'net/http'

require 'net/https'



http = Net::HTTP.new('www.microsoft.com', 80)

resp, data = http.get('/',nil)



#1."Location" response redirect...

if resp.response['Location']!=nil then

puts 'Direct to: ' + resp.response['Location']

redirectUrl=resp.response['Location']

end



#2. tag redirect...

redirectUrl=data.scan(//).to_s

if redirectUrl!=nil then

puts 'Direct to: ' +redirectUrl

end
http://www.ruby-forum.com/topic/142745

Mechanize and basic_auth


require 'mechanize'

agent = WWW::Mechanize.new

agent.basic_auth('username', 'password')

agent.get('www.example.com')

Tracking remote git branch

Tracking remote git branch


git branch --track feature1 origin/master