shitou's blog 

  • Home
  • About
  • Feed
  • 十人族
  • MIX BOY
  • 塌客

Tags "gems"

23
Jul

[转载]5个有用的ruby gems

Check out the top 5 most useful ruby gems that you may not have heard of!

Mailfactory

Mailfactory is a ruby library designed to allow the simple creation of emails.  It offers the following features:

  • Plain text and HTML body parts
  • Simple attachments
  • MIME-type guessing for attachments
  • Attachments from arbitrary IO objects
  • Custom headers
  • RFC valid email generation
  • Simple API

To Install:

gem install mailfactory

Example:

  1. require 'rubygems'  
  2. require 'net/smtp'  
  3. require 'mailfactory'  
  4.   
  5. #Connect to SMTP Server  
  6. smtp = Net::SMTP.new('mail.host.com', 25)  
  7. smtp.start('mydomain.com')  
  8.   
  9. #Construct Mail Message   
  10. mail = MailFactory.new()  
  11. mail.to = 'foo@monkey.com'  
  12. mail.from = 'jason@dzone.com'  
  13. mail.subject = 'An email from Ruby'  
  14. mail.add_attachment('/path/to/file')  
  15. mail.html = "

    Hello From Ruby!

    Mailfactory is nice

    "
      
  16.   
  17. #Construct SMTP Message  
  18. smtp.send_message mail.construct, 'foo@monkey.com', 'jason@dzone.com'  
  19.   
  20. #Send this (and all other) message  
  21. smtp.finish()      
require 'rubygems'
require 'net/smtp'
require 'mailfactory'

#Connect to SMTP Server
smtp = Net::SMTP.new('mail.host.com', 25)
smtp.start('mydomain.com')

#Construct Mail Message  
mail = MailFactory.new()
mail.to = 'foo@monkey.com'
mail.from = 'jason@dzone.com'
mail.subject = 'An email from Ruby'
mail.add_attachment('/path/to/file')
mail.html = "

Hello From Ruby!

Mailfactory is nice

"

#Construct SMTP Message
smtp.send_message mail.construct, 'foo@monkey.com', 'jason@dzone.com'

#Send this (and all other) message
smtp.finish()  

    

Feed-Normalizer

Feed-Normalizer normalizes all RSS Feed formats into a generic class. This allows you to access the same properties from any RSS Feed it parses without worrying about the underlying format of the RSS source.

To Install:
gem install feed-normalizer

Example:

  1. require 'rubygems'  
  2. require 'feed-normalizer'  
  3.   
  4. #Define URL and Parse Feed  
  5. feed_url = 'http://rss.slashdot.org/Slashdot/slashdot'  
  6. rss = FeedNormalizer::FeedNormalizer.parse open(feed_url)  
  7.   
  8. #Quit if no articles  
  9. exit unless rss.entries.length > 0  
  10.   
  11. #Read entries  
  12. rss.entries.each do |entry|  
  13.     title = entry.title  
  14.     body = entry.content  
  15.     authors = entry.authors.join(', ') rescue ''  
  16.     entry_url = entry.urls.first  
  17.   
  18.     #Your Logic Here  
  19. end 

 

 

FasterCSV

FasterCSV is significantly faster than CSV and arguably has an improved CSV interface.

To Install
gem install fastercsv

Example:


  1. require 'rubygems'  
  2. require 'fastercsv'  
  3.   
  4. #Read a CSV File  
  5. FasterCSV.foreach('/path/to/file') do |row|  
  6.     element1 = row[0]  
  7.     element2 = row[2]  
  8.     element3 = row[3]  
  9. end  
  10.   
  11. #Write a CSV File  
  12. FasterCSV.open('/path/to/file') do |csv|  
  13.     csv << ["an", "array", "of", "data"]  
  14. end  
require 'rubygems'
require 'fastercsv'

#Read a CSV File
FasterCSV.foreach('/path/to/file') do |row|
  element1 = row[0]
  element2 = row[2]
  element3 = row[3]
end

#Write a CSV File
FasterCSV.open('/path/to/file') do |csv|
  csv << ["an", "array", "of", "data"]
end

    

Bishop

Bishop is a Bayesian classifier library for Ruby. With Bishop you can effectively train your program to recognize any number of things.

To Install:
gem install bishop

Example:

  1. require 'rubygems'  
  2. require 'bishop'  
  3.       
  4. #Initialize the classifier  
  5. classifier = Bishop::Bayes.new  
  6. classifier.load('spam_or_no_spam.yml') if File.file?('spam_or_no_spam.yml')  
  7.   
  8. #Train the classifier to recognize spam email  
  9. classifier.train('spam', 'Amazing results in a few weeks!')  
  10. classifier.train('spam', 'Get your free viagra!')  
  11. classifier.train('spam', 'A credit card offer!')  
  12.   
  13. #Train the classifier to recognize legit email  
  14. classifier.train('not spam', 'Your payment update')  
  15. classifier.train('not spam', 'Scheduled Maintenance Reminder')  
  16. classifier.train('not spam', 'Can you pick the kids up today?')  
  17.   
  18. #Save classication file so your program can learn  
  19. classifier.save('spam_or_no_spam.yml')  
  20.   
  21. #Guess if an email is spam or not  
  22. guess = classifier.guess('How would you like a free sample of viagra?')  
require 'rubygems'
require 'bishop'
  
#Initialize the classifier
classifier = Bishop::Bayes.new
classifier.load('spam_or_no_spam.yml') if File.file?('spam_or_no_spam.yml')

#Train the classifier to recognize spam email
classifier.train('spam', 'Amazing results in a few weeks!')
classifier.train('spam', 'Get your free viagra!')
classifier.train('spam', 'A credit card offer!')

#Train the classifier to recognize legit email
classifier.train('not spam', 'Your payment update')
classifier.train('not spam', 'Scheduled Maintenance Reminder')
classifier.train('not spam', 'Can you pick the kids up today?')

#Save classication file so your program can learn
classifier.save('spam_or_no_spam.yml')

#Guess if an email is spam or not
guess = classifier.guess('How would you like a free sample of viagra?')

  

Linguistics

Linguistics is a generic, language-neutral framework for extending Ruby objects with linguistic methods. This is easily one of the coolest gems. There is simply so much you can do with the Linguistics module.

To Install:
gem install linguistics

Example:

  1. require 'rubygems'  
  2. require 'linguistics'  
  3.   
  4. "book".en.a  
  5. # => "a book"  
  6.   
  7. "runs".en.present_participle  
  8. # => "running"  
  9.   
  10. 5.en.ordinal  
  11. # => "5th"  
  12.   
  13. 2004.en.numwords  
  14. # => "two thousand and four"  
  15.   
  16. animals = %w{dog cow ox chicken goose goat cow dog rooster llama  
  17. pig goat dog cat cat dog cow goat goose goose ox alpaca}  
  18. puts "The farm has: " + animals.en.conjunction  
  19.   
  20. # => The farm has: four dogs, three cows, three geese, three goats,  
  21. two oxen, two cats, a chicken, a rooster, a llama, a pig,  
  22. and an alpaca 
Tags: ruby,gems

2008-07-23 19:49:32, 11375 reviews, comment

send to mailbox

Your email:

Tags

json Impactjs Canvas fun gen_server superfly PS3 Webgame HTML5 jquery SSH tenerer MooseFS gearman-ruby Gearman MongoDB MochiChat TCP U-ka saegusa IN db command Mai Kuraki Norah Jones log iPhoneException ACG Mac Safari objective-c CouchDB LVS AJAX debian 推荐 AMQP google mail bug gettext Erlang 北京 iptables 架构 tips mysql backup function 我看 postfix 监控 SEO cache Etag memcache thread 进程 线程 无锡 yield file column mixboy xml rss gems ruby shitou shell lighttpd 安全 csrf 公司 nginx linux 模块 apache webserver 朋友 大学 生活 尼古拉斯凯奇 movie 文件同步 笑笑 歌词 auto complete plugin rails music ubuntu blog

Category

  • HTML5[3]
  • iPhone[17]
  • Erlang[11]
  • google[13]
  • 生活[45]
  • 音乐[13]
  • 电影[11]
  • linux[29]
  • web server[6]
  • mail server[3]
  • cluster[1]
  • system manage[9]
  • ruby[20]
  • ruby on rails[28]
  • 开源[4]

Episode

  • MongoDB
  • MochiChat
  • iPhoneException
  • shell
  • thread
  • memcache


Popular Posts

  • 准备开始学习Erlang了(恶狼, 二郎..)
  • Ruby遍历MemCached的key
  • 服务器监控小脚本
  • MySQL Innodb备份
  • [转载]5个有用的ruby gems

Recommended Posts

  • Tri-survive - HTML5 Game
  • Cut the rope - HTML5版
  • json_formatter
  • 在gen_server中spawn新的进程
  • Superfly - Wildflowers
  • 继续凸墙 for Mac OS
  • MongoDB Beijing 2011
  • MongoDB删除map_reduce生成的tmp collection
  • Mai Kuraki - Future Kiss
  • Erlang OOP
  • 用SSH tunnel凸墙
  • Google的语法高亮工具包
  • 大量数据的批量操作
  • 再次被和谐-_-
  • 十人族: 上线了

Friends' blogs

  • levy
  • sphance
  • andreas
  • yangkunlun
  • {:dev=>:wxianfeng}
  • bheye
  • joeydarko

Login

   注册

留言 查看留言

留言

   取消

留言 查看留言


Statistics

  • 访问次数: 316271
  • 今天访问: 66
  • 日志: 213
  • 评论: 4967
  • 音乐: 9
  • 用户: 1759


少女,不点下广告吗!

 

all by shitou

blog comments powered by Disqus

close