you are here: codestackercodes [RSS] → tag ruby [RSS]

rake tasks for gem dependencies

rake gems:install # Installs all required gems for this application

rake gems:unpack # Unpacks the specified gem into vendor/gems

yahoo! search boss sample

# first, install bossman

gem sources -a http://gems.github.com
gem install jpignata-bossman

# the sample

require 'rubygems'
require 'bossman'
include BOSSMan

BOSSMan.application_id = "Your Application ID here"

news = BOSSMan::Search.news("Mac OS", 0, 3)
news.results.each do |result|
  puts "#{result.title} [from #{result.source}]"
end

yahoo finance sample

require 'yahoo_finance'
data = YahooFinance.quotes(['petr4.sa'], [:ask, :last_trade_price, :last_trade_date])
puts data[0].symbol + " => " + data[0].ask

mac os reading twitter updates

require 'rss/1.0'
require 'rss/2.0'
require 'open-uri'

content = ''
open('http://twitter.com/statuses/user_timeline/peepcode.rss').each { |i| content << i }
RSS::Parser.parse(content).items.each { |i| system "say \"#{i.title}\"" }

test

class Teste
  def teste
    "teste"
    Constant
  end
end

new flash helper with prototype effects

create an application helper to manage your rails messages
concept by nando vieira [simplesideias.com.br]

  # paste application_helper.rb

  def flash_message 
    messages = ""
    [:notice, :info, :warning, :error].each {|type|
      if flash[type]
        messages += "<p class=\"#{type}\" id=\"alert\">#{flash[type]}</p>"
      end
    }    
    messages
  end

  ####################################


  # your layout 

  <%= flash_message %>
	
  <% content_tag :script, :type => "text/javascript" do %>
    $('alert').style.display = 'none';
    new Effect.Appear('alert', {duration: 3});
    setTimeout("new Effect.Fade('alert');", 10000);
  <% end %>

Meu código ruby

Mue código aqui estará em testes até amanhã

class Weldys < ActiveRecord

 def testes
   puts "Olá"
 end

end

Phone.rb

Class form my CRM

class Phone
  attr_reader :country_code, :area_code, :number
  
  def initialize(country_code, area_code, number)
    @country_code, @area_code, @number = country_code, area_code, number
  end
  
  def ==(value)
    @country_code == value.country_code &&
    @area_code == value.area_code &&
    @number == value.number
  end
  
  def to_s
    @number ? "+#{@country_code} #{@area_code} #{@number}" : "n/a"
  end
end

Traduz textos usando o google

Traduz palavras/frases/textos usando a API do Google, usei aqui http://github.com/rafaelss/shoes-translator

require 'rest_client'
require 'json'
require 'cgi'

word = CGI.escape("hello world")
response = RestClient.get "http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=#{word}&langpair=en%7Cpt"
json = JSON.parse(response)
status = json['responseStatus']
if status == 200
    puts json['responseData']['translatedText']
else
    puts "(#{responseStatus}) erro ao traduzir #{word}"
end
Displaying Code 61 - 69 of 69 in total