Friday, July 24, 2009

base 64 enocde/decode

require 'base64'
puts Base64.decode64("aG1hYw==").chomp => hmac
puts Base64.encode64("hmac").chomp =>
aG1hYw==

Thursday, July 9, 2009

Check Whether a test Credit Card is working.,

require 'rubygems'
require 'active_merchant'

# Use the TrustCommerce test servers
ActiveMerchant::Billing::Base.mode = :test

# ActiveMerchant accepts all amounts as Integer values in cents
# $10.00
amount = 1000

# The card verification value is also known as CVV2, CVC2, or CID
credit_card = ActiveMerchant::Billing::CreditCard.new(
:first_name => 'Bob',
:last_name => 'Bobsen',
:number => '349298720353895',
:month => '8',
:year => '2012',
:verification_value => '1234'
)

puts credit_card.valid?

Wednesday, July 1, 2009

Getting Local ip Address

require 'socket'
def local_ip
orig, Socket.do_not_reverse_lookup = Socket.do_not_reverse_lookup, true # turn off reverse DNS resolution temporarily

UDPSocket.open do |s|
s.connect '64.233.187.99', 1
s.addr.last

end
ensure
Socket.do_not_reverse_lookup = orig
end
p= local_ip
puts p