Eric on Java

Java, JavaFX, Groovy, Grails …

Follow me on TwitterRSS Feeds

  • Home

Remote Desktop to a Amazon EC2 CentOS 5.4 AMI

Jul 5th

Posted by Eric Warriner in Amazon EC2

No comments

Although this has been posted before by a few folks (some more comprehensive than others depending on your OS / configuration)…I thought I would add my notes to the “Internets” on creating a remote desktop connection to a Amazon EC2 CentOS 5.4 AMI.

  • Install FreeNX package on your instance
  • yum install -y freenx
  • for a KDE desktop
  • yum install -y kdebase
  • for a gnome desktop
  • yum install -y gnome-session
  • navigate to /etc/nxserver and copy the node.conf.sample to node.conf
  • cp node.conf.sample node.conf
  • Edit the node.conf file to enable “ENABLE_PASSDB_AUTHENTICATION=”1″
  • nano node.conf
  • Note that you can click on the image to make it larger.
  • on CentOS, create a user and set the password that will be logging in via remote desktop
  • adduser eric
    passwd eric
  • on nxserver, add the user that you just created and set the password (this is the user the NX client will log in with)
  • nxserver --adduser eric
    nxserver --passwd eric
  • Now that the nxserver is complete we need to configure a client.
  • Use your favorite method to transfer client.id_dsa.key (I used FileZilla SFTP) to the client machine
  • Download and install the NoMachine NX client and fonts
  • Direct the NX Client to use the client.id_dsa.key by clicking the “Configure Button”

  • Then select the “Key” where you can “Import” the client.id_dsa.key …make sure to save.

  • In this configuration menu you can also set the “Desktop” type KDE or GNOME (dependent on what you installed on the server earlier) and host, port and dimension parameters.
  • For username and password…you would obviously use the user earlier created on the server.
  • Upon clicking connect…if everything is configured correctly … a desktop should appear.

That should do it…but if you know of “Harder, Better, Faster, Stronger” ways to do this…please leave a comment.

To complete this task I mostly used the following reference: CentOS Wiki

  • Bookmark on Delicious
  • Digg this post
  • Recommend on Facebook
  • Share on Linkedin
  • Share via MySpace
  • share via Reddit
  • Share with Stumblers
  • Tumblr it
  • Tweet about it
Amazon EC2 Freenx nx Centos

Screen Scraping? Groovy GPath FTW!

Jun 23rd

Posted by Eric Warriner in Groovy

2 comments

While I may be a little late to extol all of the virtues of Groovy as so many before me have already done with great eloquence…I would like to quickly point out that Groovy GPath rocks!

Take, for instance, a requirement to screen scrap HTML pages. A couple of the ways to approach this task is to use:

  • Regular Expressions parsing (hopefully you’re a regex ninja)
  • XPath (W3C recommendation)

and my favorite

  • GPath (a Groovier XPath)

GPath is

a path expression language integrated into Groovy which allows parts of nested structured data to be identified

This applies to nested POJOs as well as XML and to boot TagSoup ‘d HTML as demonstrated a few years ago here.

So as a quick example of how easy Groovy makes scraping, let’s scrape this site for the text of the title element using a traditional Java way (keep in mind there are numerous ways to do XPath in pure Java) and then the Groovy ‘er way.

A Traditional Java XPath Approach:


import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;

import nu.xom.Builder;
import nu.xom.Document;
import nu.xom.Nodes;
import nu.xom.XPathContext;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.XMLReaderFactory;

public class Main {
    public static void main(String[] args) {
        try {

            XMLReader tagsoup = XMLReaderFactory.createXMLReader("org.ccil.cowan.tagsoup.Parser");

            Builder builder = new Builder(tagsoup);
            Document doc = builder.build(new URL("http://www.ericonjava.com").openStream());

            XPathContext context = new XPathContext("h", "http://www.w3.org/1999/xhtml");
            Nodes table = doc.query("/h:html/h:body/h:div/h:div/h:div/h:div/h:h1/h:a", context);

            System.out.println("TITLE = " + table.get(0).getValue());

        } catch (Exception ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

The Groovy GPath Approach:

def slurper = new XmlSlurper(new org.ccil.cowan.tagsoup.Parser());

def seedURL = new URL("http://www.ericonjava.com")
seedURL.withReader { seedReader ->

    def seedHTML = slurper.parse(seedReader)

        Title= seedHTML.body.div.div.div.div.h1.a
        println "Title =  ${Title}";
    }

Clearly….Groovy GPath FTW.

  • Bookmark on Delicious
  • Digg this post
  • Recommend on Facebook
  • Share on Linkedin
  • Share via MySpace
  • share via Reddit
  • Share with Stumblers
  • Tumblr it
  • Tweet about it
groovy xpath gpath
12345»...Last »
  • [FSF Associate Member]
  • Contact Me at:

    eric @ ericonjava.com
  • Find the Code On

    • Archives
    • Tags
    • Categories
    • Amazon EC2 (1)
    • Grails Groovy (2)
    • Groovy (1)
    • Java (1)
    • JavaFX (5)
    • Jersey (1)
    • ProcessingJS (1)
    acegi Amazon EC2 Freenx nx Centos api google maps grails groovy groovy xpath gpath Java JavaFX javafx perspective transform java javafx bubble breaker game JAX-RS Jersey Magic 8 ball java javafx mashup npr Processing ProcessingJS Security Annotations spring security spring security core Tomcat Vault Breaker game java javafx
    • July 2010 (1)
    • June 2010 (1)
    • May 2010 (2)
    • April 2010 (1)
    • February 2010 (1)
    • January 2010 (1)
    • December 2009 (4)
  • User Login






    • Lost your password?

RSS Feeds Top
Copyright © 2010 Eric on Java
  • follow:
  • Join my conversations
  • Tweet with me