Wednesday, April 28, 2010

Small Lump Under Dog's Tail

A first look at Groovy

currently worldwide or agile dynamic languages \u200b\u200bhave achieved great popularity in both the companies and developers (though in general in Chile and Latin America, yet enterprise-level are not highly valued.)


Groovy has attracted my attention because it is a language born with a mission to get along with Java, the virtual machine live in and support the standard data types and dynamic but adding syntactic features present in languages \u200b\u200blike Python , Smalltalk or Ruby .

Groovy source code compiles to Java bytecodes like (generating. Class files that can run directly from the virtual machine), allowing instantiate Java objects and vice versa from Groovy.

Groovy's syntax is quite similar to Java, so the learning curve is very high for developers who are familiar with it.

Most things we do with Java can be done in Groovy, eg
  • Definition Definition
  • packages of classes (but not internal) and methods
  • control structures, except the loop for (;;)
  • Control Exception
  • Operators, expressions and assignments
  • Literals with some variations
  • Instantiation, reference and de-reference of objects, method calls
And some syntactic improvements including Groovy: Groovy
  • In all is an object
  • Ease in handling objects, through new expressions
  • and syntax for declaring literal Various forms
  • advanced flow control through new structures
  • New data types and operations specific expressions
  • Brevity, Groovy code is much shorter than that of Java

Y as usual and to finish this entry, see how the code would be the typical "Hello World" Groovy:

 / / Hello World in Groovy 
def world = "World"
println "Hello $ world!"
/ / End

At first glance we see that:
  • script can be written where there are no classes (in fact there but we need not declare it)
  • No ',' at the end of each line. In Groovy is optional
  • The keyword def to declare variables of type dynamic. You can also create static type variables (eg Integer)
  • The comments are as in Java (/ / or /**/)
  • print and println are equivalent to System.out.print and System . out.println
  • parameter function println not enclosed in parentheses is optional

Friday, April 16, 2010

Komputer Rowerowy Shark-instrukcja Obsługi




Neither had more than ten years. One had blond hair, very short, and brown eyes rather small, the other by the contraro, had curly brunette hair and fairly long, and green eyes, a little blue.
The two sat on a fallen log, a bit dry and forgotten, in the middle of an unknown forest, without wishing to be known, and entirely uninhabited. For years, they only attended every Thursday the remote forest, very remote from the city ... the city ... the daughter of fear ...
They sat and passed the time ... sometimes, not even uttered a word ... just waiting for something, waiting for life.
_Dicen happens fast ... you have to rush when you see it and catch flying with both hands to escape ... Always
initiating the talks was the blonde. The dark hair, however, was more shy and needed to hear words of others before his own state.
_Dicen many things ... some even say that there ...
The blond laughed.
_ Who says? _No
skeptics know ... ...
_ Who?
_Esos ... do not believe in anything ...
relaunched The blond laughed. The blonde had long lived in the city ... it was hard much more than the other to change their assumptions.
_Uy, look, look! Go flying!
The morocho stood up and pointed to the sky with the index finger of his right hand. _
see it! Is it yours or mine? _No
know, try both, quickly, before it happens.
The two began to jump, with hands stretched above it, pinched at the sky and filling their little hands with clean air in a forest wilderness.
_ Can you?
_Creo which is yours _decía morocho while jumping.
And then ceased morocho your jump. His friend, every time I supported his feet on the ground, aged a few years. Blonde hair began to turn white. His beardless face was full of hair and graying. The wrinkle began playing on his face, almost like dolls. And in a moment, the blond fell, with the thin skin and hurt by the passage of time has not passed, much higher than when I started to jump, without any teeth in your mouth, with a few hairs on their head ... her eyes were closed and no longer breathing.
_Ey ... _le morocho_ said. Do you grabbed?
reached down and supported two fingers on the wrist of her friend, who was then a much older, lying on the floor. He felt one or maybe two palpitations. Then he looked at the sky. He saw his friend's life was flying very fast until in a moment was lost in the clouds and could not return to foreign exchange. Then, the palpitations stopped. His friend had died. _No
take hold ... Then you had, right ... life goes flying, it is fast Agarrala ... I'm skeptical ... do not know, you have to tell them, look if they spend their lives as well ...



Text by Poyo Skalari

Friday, April 2, 2010

Funny Birthday Invitation Wording Ideas

JavaMail, send mail with attachments and HTML through Google Apps or you

Hi all, many developers we indispensable to implement a module for sending mail in the systems we develop. Depending on what language is the complexity or simplicity of the encoding of this and as many know, Java is not always a precursor of simplicity.

is why I want to publish and provide to all Mail.java class that allows you to send mail through Google Apps and through a mail server commonplace.

The code works by implementing the JavaMail API SUN (so download the JAR with the API but can never send messages) and provides 2 methods. One called 'enviaGoogleApp' that allows you to send mail through a Google Apps account and another called 'send' to send mail through a mail server defined.

The code of both methods is identical, only changes the way you authenticate to the server.

The Mail class methods only require the following information:
1) Issuer of the message.
2) Subject of the mail.
3) Recipient (s) of mail.
4) mail message (in HTML or ASCII)
5) Attachments.

With a slight modification and adding 2 parameters can be added:
1) Recipients who are copying the mail.
2) Recipients who are blind copy.

The code is as follows and can be downloaded from Google Group getgeek :

 util.mail package; 

import java.io.File;
import java.util.ArrayList;
import java.util . List;
import java.util.Properties;
javax.activation.DataHandler
import, import
javax.activation.DataSource;
javax.activation.FileDataSource import, import
javax.mail.Authenticator;
javax.mail import. Message;
javax.mail.Multipart import, import
javax.mail.PasswordAuthentication;
javax.mail.Session import, import
javax.mail.Transport;
javax.mail.internet.InternetAddress import, import
javax.mail. internet.MimeBodyPart;
javax.mail.internet.MimeMessage import, import
javax.mail.internet.MimeMultipart;

public class Mail {private class

SMTPAuthenticator extends Authenticator {private String
dEmail;
dPassword private String;
public
SMTPAuthenticator (String email, String password) {
dEmail = email;
dPassword = password;}


getPasswordAuthentication public PasswordAuthentication () {return new PasswordAuthentication
(dEmail, dPassword);}



} / ** * function & oacute
n that allows to send an electronic mail with attachments ó unique. < Br >
* The email content can be in HTML format. * @ Param issuer
Mail é qui n emits mail
* @ param subject Subject of the e-mail recipients
* @ param Post the e-mail recipients * @ param
Message of e-mail
* @ param path attachments attachments in e-mail
* @ return TRUE if the mail was sent successfully é,
FALSE otherwise * / public boolean
enviaGoogleApp (String sender, String subject, List & lt ; String > recipient, String message, String > < List attachments) {boolean
envioExitoso = true;
String emailGetCursos = &quot;cuenta.googleapps@algo.cl&quot;;
String password = &quot;password.de.cuenta.googleapps&quot;;
Properties props = new Properties();
props.put(&quot;mail.smtp.user&quot;, emisor);
props.put(&quot;mail.smtp.host&quot;, &quot;smtp.gmail.com&quot;);
props.put(&quot;mail.smtp.port&quot;, &quot;465&quot;);
props.put(&quot;mail.smtp.starttls.enable&quot;, &quot;true&quot;);
props.put(&quot;mail.smtp.auth&quot;, &quot;true&quot;);
props.put(&quot;mail.smtp.socketFactory.port&quot;, &quot;465&quot;);
props.put(&quot;mail.smtp.socketFactory.class&quot;, &quot;javax.net.ssl.SSLSocketFactory&quot;);
props.put(&quot;mail.smtp.socketFactory.fallback&quot;, &quot;false&quot;);

try{

Authenticator auth = new SMTPAuthenticator(emailGetCursos, password);
Session session = Session.getInstance(props, auth);

MimeMessage message = new MimeMessage(session);
InternetAddress[] dest = new InternetAddress[receptores.size()];
for (int i = 0; i < dest.length; i + +) {
dest [i] = new InternetAddress (receptores.get (i));}


/ / Define é qui n is the e-mail sender
message.setFrom (new InternetAddress (sender));
InternetAddress [] = new InternetAddress replyTo [1];
replyTo [0] = new InternetAddress (sender);
message.setReplyTo (replyTo)
/ / Define the intended
message.addRecipients (Message.RecipientType.TO, dest);
/ / message.addRecipients (Message.RecipientType.CC, dest);
/ / message.addRecipients (Message.RecipientType.BCC , dest);


/ / To set the subject of the e-mail
message.setSubject (issue);

/ / It sets the e-mail message
MimeBodyPart MimeBodyPart messageBodyPart = new ();
messageBodyPart.setContent ( message, "text / html");

MimeMultipart Multipart multipart = new ();
multipart.addBodyPart (messageBodyPart)

/ / files are attached to e
if (adjuntos! adjuntos.size = null & & () > 0) {
for (String rutaAdjunto: attachments) {
MimeBodyPart messageBodyPart = new ();
File f = new File (rutaAdjunto)
if (f.exists ()) {source = new DataSource
FileDataSource (rutaAdjunto)
messageBodyPart.setDataHandler (new DataHandler (source));
messageBodyPart.setFileName (f.getName ( ));
multipart.addBodyPart (messageBodyPart)

}}}


/ / message and is coupled
message.setContent attachments (multipart);

/ / env is on e-í Transport.send
mail (message);

} catch (Exception e) {
envioExitoso = false;}


finally {/ / is deleted from the server
attachments if (adjuntos! = null & & adjuntos.size () > 0) {
for (String rutaAdjunto: Attachments)

{try {File arch = new File (rutaAdjunto)
arch.delete ();

} catch (Exception e) {}}


}} return
envioExitoso;


} / ** *
n ó function that lets you send an electronic mail with attachments ó unique. < Br >
* The contents of Mail can be in HTML format. * @ Param issuer
Mail é qui n emits mail
* @ param subject Subject of the e-mail recipients
* @ param Post the e-mail recipients * @ param
Message of e-mail
* @ param path attachments attachments in e-mail
* @ return TRUE if the mail was sent successfully é,
FALSE otherwise * / public boolean
send (String sender, String subject, List & lt ; String > recipient, String message, String > < List attachments) {boolean
envioExitoso = true;

try {Properties props = System.getProperties ();

/ / Define
mail server props.put ("mail.smtp.host", "ip.servidor.de.correos");
props.put ("mail . smtp.port "," puerto.servidor.de.correo (default 25) ");

/ / SESI ó n is obtained from the mail server
Session.getInstance Session session = (props, null);
session.setDebug (true);

MimeMessage message = new MimeMessage (session);
InternetAddress [] dest = new InternetAddress [receptores.size ()];
for (int i = 0; i < dest.length; i + +) {
dest [i] = new InternetAddress (receptores.get (i));}


/ / Define é qui n e is the emitter message.setFrom
-mail (new InternetAddress (sender));
InternetAddress [] = new InternetAddress replyTo [1];
replyTo [0] = new InternetAddress (sender);
message.setReplyTo (replyTo)
/ / It define the intended
message.addRecipients (Message.RecipientType.TO, dest);
/ / message.addRecipients (Message.RecipientType.CC, dest);
/ / message.addRecipients (Message.RecipientType.BCC, dest) ;

/ / To set the subject of the e-mail
message.setSubject (issue);

/ / It sets the e-mail message
MimeBodyPart MimeBodyPart messageBodyPart = new ();
messageBodyPart.setContent (message, "text / html ");

MimeMultipart Multipart multipart = new ();
multipart.addBodyPart (messageBodyPart)

/ / files are attached to e
if (adjuntos! = null & & adjuntos.size ()> 0) {
for (String rutaAdjunto: attachments) {
MimeBodyPart messageBodyPart = new ();
File f = new File (rutaAdjunto)
if (f.exists ()) {source = new DataSource
FileDataSource (rutaAdjunto)
messageBodyPart.setDataHandler (new DataHandler (source));
messageBodyPart.setFileName (f.getName ());
multipart.addBodyPart (messageBodyPart )

}}}


/ / message and is coupled
message.setContent attachments (multipart);

/ / env is í to the e-mail
Transport.send (message);

} catch (Exception e) {
envioExitoso = false;}


finally {/ / is deleted from the server
attachments if (adjuntos! = null & & adjuntos.size () > 0) {
for (String rutaAdjunto: attachments) {try {

arch File = new File (rutaAdjunto)
arch.delete ();

} catch (Exception e) {}}


}} return
envioExitoso;


} public static void main (String [] args) {
String > < List recipients = new String > < ArrayList ();
receptores.add (mail.de.alguien @ gmail.com ");
String issuer = "test@test.cl"
String subject = "Test Mail";
String message = "This is an email from < font color = 'red' > & ; lt; b > < TEST / b > < / font > "String > <
List files = new String > < ArrayList () ;
Mail m = new Mail ();
/ / m.envia (sender, subject, recipient, message, null);
m.enviaGoogleApp (sender, subject, recipient, message, file);


}}