Archive for October, 2010

HtmlUnit : GUI Java Less browser

HtmlUnit – Welcome to HtmlUnit.

HtmlUnit is a “GUI-Less browser for Java programs”. It models HTML documents and provides an API that allows you to invoke pages, fill out forms, click links, etc… just like you do in your “normal” browser.

It has fairly good JavaScript support (which is constantly improving) and is able to work even with quite complex AJAX libraries, simulating either Firefox or Internet Explorer depending on the configuration you want to use.

It is typically used for testing purposes or to retrieve information from web sites.

Vim vi how to reload a file your editing

Maiar’s Vault: Vim vi how to reload a file your editing.

5.8. How do I reload current file?

You can use the “:edit” command, without specifying a file name, to reload
the current file. If you have made modifications to the file, you can use
“:edit!” to force the reload of the current file (you will lose your modifications).

For more information, read: http://vimdoc.sourceforge.net/cgi-bin/vimfaq2html3.pl#5.8

:help :edit
:help :edit!
:help 'confirm'

Sending email with ruby – TMail

http://yakinikunotare.boo.jp/orebase/index.php?Ruby/TMail
http://tmail.rubyforge.org/rdoc/classes/TMail/Mail.html

Simple email sending:

require 'NET / SMTP'
require 'TMail'
require 'base64'
 
Mail = TMail:: Mail.new
 
Mail.to = 'you@gmail.com'
Mail.from = 'me@gmail.com'
Mail.subject = 'Test Mail '
Mail.date = Time.now
Mail.Mime_Version = '1 .0 '
Mail.Set_Content_Type 'text', 'plain', {'charset'=>'UTF-8'}
Mail.Body = 'This is Test Mail . '
 
Net:: SMTP.start("smtp.yourhost.com", 587, "smtp.yourhost.com", "username", "password") do | SMTP | SMTP.sendmail(Mail.encoded, Mail .from, Mail.to)
end

Send attachments:

require 'NET / SMTP'
require 'TMail'
require 'base64'
 
# object
Mail = TMail:: Mail.new
 
Mail.to = 'you@gmail.com'
Mail.from = 'me@gmail.com'
Mail.subject = 'Test Mail'
Mail.date = Time.now
Mail.Mime_Version = '1 .0 '
Mail.Set_Content_Type 'multipart', 'mixed', {"boundary" => "Somethingspecial"}
 
# body
Mail_Body = TMail:: Mail.new
Mail_Body.Set_Content_Type 'text', 'plain', {'charset'=>'UTF-8'}
Mail_Body.Body = 'Ge almost'
Mail.Parts.push(@ Mail_Body)
 
# Attachments
Attach = TMail:: Mail.new
Attach.Body = Base64.Encode64 File.Open('foo.jpg', "rb").read
Attach.Set_Content_Type 'image','jpg','name'=>'foo.jpg'
Attach.Set_Content_Disposition ' Attachment ','filename'=>'foo.jpg'
Attach.transfer_encoding = 'base64'
 
# attach
Mail.Parts.push(Attach)
 
# send
Net:: SMTP.start("smtp.yourhost.com", 587, " smtp.yourhost.com ", "username", "password") do | SMTP | SMTP.sendmail(Mail.encoded, Mail.from, Mail.to)
end