preload
Dez 02

How to send an email with telnet via smtp for testing purposes? Here is an example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
telnet  smtp.me.com 25
220 smtp.web.de ESMTP Web.de V4.91#2 Sun, 24 Nov 2009  16:51:20 +0100
 
helo yourcomputername
250 smtp.web.de Hello yourcomputername [219.99.999.999]
 
mail  from: account@web.de
250 account@web.de is syntactically  correct
 
rcpt  to: empfaenger@provider.tld
250 empfaenger@provider.tld verified
 
data
354 Enter message,  ending with . on  a line by itself
To: anton@tirol.at;
From: hugo@schlaumeier.de
Subject: Jodelei 
 
Servus!
 
Greetz,
Peterli
.
250 OK  id=18Z6Uc-0001wm-00
 
Quit
221 smtp.web.de closing connection

To send mail with auth:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
telnet  smtp.me.com 25
220 smtp.web.de ESMTP Web.de V4.91#2 Sun, 24 Nov 2009  16:51:20 +0100
 
helo yourcomputername
250 smtp.web.de Hello yourcomputername [219.99.999.999]
 
auth login
334 VXNlcm5hbWU6
 
<base64 encoded username>
<repeated base64 encoded username>
<base64 encoded password>
<repeated base64 encoded password>
 
235 Authentication successful
 
mail  from: account@web.de
250 account@web.de is syntactically  correct
 
rcpt  to: empfaenger@provider.tld
250 empfaenger@provider.tld verified
 
data
354 Enter message,  ending with . on  a line by itself
 
Subject: Jodelei 
 
Servus!
 
Greetz,
Peterli
.
250 OK  id=18Z6Uc-0001wm-00
 
Quit
221 smtp.web.de closing connection

To base64 encode your username or pass, use another linux terminal and type:

1
2
printf username | base64
printf password | base64

If you don’t have base64 on your system try mimencode instead.

Tagged with:
Dez 02

To scroll in screen-mode of linux type the following:
Strg+a then AltGr+8

Now you can scroll up and down. This is called the copy-mode.

Source: http://blog.pregos.info/2009/02/26/scrollen-im-screen/

Tagged with:
Dez 01

Imagine you have java code like the following:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
   if (o.isShipped) //order is shipped --> archive
                {
                    //archived 21 days after delivery
                    Calendar cal = new GregorianCalendar();
                    cal.add(Calendar.DAY_OF_MONTH,DAYS_TO_ARCHIVE_AFTER_SHIPPING);
                    try {
                       ...
                        }
                    } catch (Exception ex) {
                        ...
                    }
                } else if (o.isCancelled == true || o.isClosed == true) {
                    //cancelled more than 7 days ago
                    ...
                                } else {
                                   ...
                                }
                            }
                        }
                    } catch (Exception ex) {
                        ...
                    }
                    try {
                        if (o.isClosedAt.getTimeInMillis() <= cal.getTimeInMillis()) {
 
                           ...
 
                                } else {
                                    ...
                                }
                            }
                        }
                    } catch (Exception ex) {
                        ...
                    }
                } else if (o.isReadyForShipping && o.isDispatched) {
                 ...
                }

Isn’t it extreme hard to read and to understand? Martin Fowlers Book “Refactoring” shows how to handle that. Replace all these nested if…else with if-guards. It could lool like this:

1
2
3
4
if (order.isShipped && !isCancelled && !isClosed) archiveOrder();
if (!order.isShipped && order.isCancelled && order.isCancelledAt.getTimeInMillis() <= cal.getTimeInMillis()) moveReservationOnCancel();
if (!order.isShipped && order.isClosed && order.isClosedAt.getTimeInMillis() <= cal.getTimeInMillis()) moveReservationOnClosing(); 
...

What did we do here? We renamed the order object o into order, and put the actions into separate methods. To improve readability a bit more we can create a method for the boolean checks. See the next example:

1
2
3
4
5
6
7
8
9
10
11
12
13
if (isOrderShipped(order)) archiveOrder();
if (isOrderCanceled(order)) moveReservationOnCancel();
if (isOrderClosed(order)) moveReservationOnClosing(); 
...
private boolean isOrderShipped(OrderDetails order) {
        return order.isShipped && !order.isCancelled && !order.isClosed;
}
private boolean isOrderCancelled(OrderDetails order) {
        return !order.isShipped && order.isCancelled && order.isCancelledAt.getTimeInMillis() <= cal.getTimeInMillis();
}
private boolean isOrderClosed(OrderDetails order) {
        return !order.isShipped && order.isClosed && order.isClosedAt.getTimeInMillis() <= cal.getTimeInMillis();
}

Pretty readable isn’t it? You just need a few seconds to understand what is going on here. You have the main flow right in sight. When it is needed to go deeper into the code you can pick any method you like to inspect.

Tagged with: