Tuesday, May 31, 2011

eclipse comments short cut

Ctrl+/Toggle CommentAdd/remove line comments (//…) from the current line. The position of the cursor can beanywhere on the line. Works with multiple selected lines as well.
Ctrl+Shift+/Add Block CommentWrap the selected lines in a block comment (/*… */).
Ctrl+Shift+\Remove Block CommentRemove a block comment (/*… */) surrounding the selected lines.
Alt+Shift+JAdd Javadoc CommentAdd a Javadoc comment to the active field/method/class. See the notes below for more details on where to position the cursor.

Friday, May 27, 2011

Cool stuff in .NET 4.0: System.Threading.Tasks.TaskScheduler

private void Save()
    System.Threading.Tasks.TaskScheduler uiScheduler = System.Threading.Tasks.TaskScheduler.FromCurrentSynchronizationContext();
    System.Threading.Tasks.Task<ErrorEnum>.Factory.StartNew(() =>
        ErrorEnum callResult = ErrorEnum.OK;
            IsIdle = false;
            callResult = (ErrorEnum)DataContext.DomainRepository.SaveDomain(_domain);
            if (callResult != ErrorEnum.OK)
                // If remote saving fails, rollback all the changes
                // If remote saving succeeds, save changes to local db
            return callResult;
        catch (Exception ex)
            LogManager.AddCMEventLog("DomainSettingsViewModel.Save", ex);
            // If anything goes wrong, rollback all the changes
            return ErrorEnum.LocalFatalAnonymousError;
            IsIdle = true;
    }).ContinueWith(task => ShowResult(task.Result), uiScheduler);

This running tasks in background thread, then call UI thread to execute the ShowResult() function, Just like UIDispatcher

Monday, May 23, 2011

perl send email cgi

Lots of tutorials about sending email with perl depend on some uncommon libs.
There is a common way to do so:

use Net::SMTP::SSL;

sub send_mail {
    my $to      = $_[0];
    my $subject = $_[1];
    my $body    = $_[2];

perl session cgi


$session = CGI::Session->load() or die CGI::Session->errstr;
if ( $session->is_expired ) {
    die "Your session expired. Please refresh your browser to re-start your session";
if ( $session->is_empty ) {
    $session = $session->new();

print $session->header();

#save into session

#read from session
$variable = $session->param('username');

Tuesday, May 10, 2011

Java sort list -- Collections.sort sample

public static void Sort(List<Movies> items) {
Collections.sort(items, SENIORITY_ORDER);
static final Comparator<Movies> SENIORITY_ORDER =
        new Comparator<Movies>() {
public int compare(Movies e1, Movies e2) {
if (e1.getReleaseDate().after(e2.getReleaseDate()))
return 1;
return -1;