Extract the .gem file into a new directory. After extracting, copy that directory into /vender/gems directory of your application. add the gem into the gemfile( gem "GemName", "Version", :path => "vendor/gems/Gem Directory Name".) . after that run bundle install. Enjoy.
Sunday, July 15, 2012
Monday, July 9, 2012
Wednesday, July 4, 2012
Tuesday, May 15, 2012
Auto refresh page
"<script language="javascript" type="text/javascript">setTimeout("location.reload();",20000);</script>"
Thursday, January 19, 2012
Monday, December 19, 2011
ruby step iterator
A loop from 0 to 12 by 3 can be written as follows.
0.step(12, 3) {|x| print x, " " }
produces:
0 3 6 9 12
Wednesday, December 7, 2011
Tuesday, December 6, 2011
Custom timeout for Net::HTTP Requests in Ruby
http = Net::HTTP.new(host, port)
http.read_timeout = "timeout in milliseconds"
Saturday, December 3, 2011
Open current directory in terminal from nautilus
install nautilus-open-terminal.
1 . sudo apt-get install nautilus-open-terminal.
2 . logout and login or give "nautilus -q" in terminal.
Now in your right-click menu you can open a terminal, and it will be in what ever directory you are currently in in Nautilus
1 . sudo apt-get install nautilus-open-terminal.
2 . logout and login or give "nautilus -q" in terminal.
Now in your right-click menu you can open a terminal, and it will be in what ever directory you are currently in in Nautilus
Wednesday, November 30, 2011
Partial deploy using capistrano
Real projects are big and often have several megabytes of code. Sometimes, you need to quickly apply a ‘hotfix’ for a critical bug. Usually, a fix like that is small enough (containing only several lines of code) and affects only a part of the application. If so. it’s not necessary to restart the whole application – you need to restart only part of the running processes. In the end, you don’t need to go through the entire deployment process.
check this out http://blog.railsware.com/2011/10/25/delivery-via-patch/
check this out http://blog.railsware.com/2011/10/25/delivery-via-patch/
Thursday, September 15, 2011
Ctrl+C to exit from exception ruby
rescue SystemExit, Interrupt
raiserescue Exception => e
#...
end
you can use SystemExit, Interrupt classes to exit from script with Ctrl+CFriday, September 2, 2011
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
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')
Tuesday, August 16, 2011
mechanize examples
#00 Initialization
#01 manual get requests
#02 manual post submits
#03 form post submits
#04 link and history navigation
#05 exceptions
#06 referer
#07 request header manipulation
#08 response header
#09 content parsing
#10 "with" method examples
require 'rubygems'
require 'mechanize'
agent = WWW::Mechanize.new
agent.set_proxy('localhost', '8000')
agent.user_agent = 'Individueller User-Agent'
agent.user_agent_alias = 'Linux Mozilla'
agent.open_timeout = 3
agent.read_timeout = 4
agent.keep_alive = false
agent.max_history = 0 # reduce memory if you make lots of requests
#01 manual get requests
url = 'http://apoc.sixserv.org/requestinfo/'
page = agent.get url
# or ...
page = agent.get(url, {"name" => "value", "key" => "val"})
#02 manual post submits
url = 'http://apoc.sixserv.org/requestinfo/'
page = agent.post(url, {"name" => "value", "key" => "val"})
#03 form post submits
page = agent.get 'https://twitter.com/login'
login_form = page.form_with(:action => 'https://twitter.com/sessions')
login_form['session[username_or_email]'] = '[Username]'
login_form['session[password]'] = '[Password]'
page = agent.submit login_form
#04 link and history navigation
page = agent.get 'http://www.heise.de/'
page = agent.click(page.link_with(:text => /Telepolis/))
page = agent.click(page.link_with(:href => /artikel/))
agent.back
agent.back
puts page.body
#05 exceptions
begin
page = agent.get 'http://apoc.sixserv.org/diese/seite/gibt/es/nicht/'
rescue WWW::Mechanize::ResponseCodeError
puts "ResponseCodeError - Code: #{$!}"
end
#06 referer
page = agent.get(:url => 'http://apoc.sixserv.org/requestinfo/',
:referer => 'http://google.com/this/is/a/custom/referer')
puts page.body
#07 request header manipulation
agent.pre_connect_hooks << lambda do |params|
params[:request]['X-Requested-With'] = 'XMLHttpRequest'
end
#08 response header
page = agent.head 'http://sixserv.org'
server_version = page.header['server']
puts "Server: #{server_version}"
if page.header.key? 'x-powered-by'
php_version = page.header['x-powered-by']
puts "X-Powered-By: #{php_version}"
end
# redirection urls:
agent.redirect_ok = false
page = agent.get 'http://www.sixserv.org/'
puts page.header['location']
#09 content parsing
# X Path / CSS-Selector:
page = agent.get 'http://xkcd.com/'
img = page.search '/html/body/div/div[2]/div/div[2]/div/div/img'
puts img
# Regular Expression:
page = agent.get 'http://example.com/'
page.body.match /< h3>([^<]+)< \/h3>/
puts "Heading 3: #{$1}"
#10 "with" method examples
# *_with: form, link, base, frame or iframe
# get the first link including "foo" inside url:
page.link_with(:href => /foo/)
# all links with text 'more'
page.links_with(:text => 'more')
# get the form with the name 'foo'
page.form_with('foo') # or form_with(:name => 'foo')
Subscribe to:
Posts (Atom)