Ubuntu insights, Programming in groovy, java, et als!

Sunday, October 30, 2011

Ubuntu 11.10 - First Thing's First


 What I did after Ubuntu 11.10 installation, the journey so far!
  1. Installed Oneiric Ocelot (64 bit) with partitions spaces 50GB for Ubuntu root / and 150 GB for /home .

  2. Ubuntu restricted areas for audio and video codecs. (Can be installed either from Ubuntu software center or from the terminal using the
    sudo apt-get install ….

  3. Downloaded Launchy, an opensource keystroke launcher, my all time favorite system utility to easy index files. (Comes as a deb package by default, one can open the deb package with Ubuntu Software Center to proceed for installation or from the terminal using..
    cd .. //to the downloaded directory location
    dpkg -i packagename.deb
  4. Cairo Cock : Another personal favorite of mine for easy access. Cairo dock overrides few things that unity lack in terms with ease of access. Well, for everything else, you've the terminal. Nevertheless, I find Unity a lot more complete than what it was in Ubuntu 11.04. I personally like Unity, it is just a matter of breaking conventionality to realize the potential of what something new and innovative could offer.
  5. Chromium, a much better and faster web browser than Firefox.
  6. Rhythmbox, to manage audio. I am not a big fan of the music players suggested in the Linux world, although I haven't tried out all of them. The newer Winamp like interface is what I personally love. Have been looking around for such but again, Rhythmbox seems to be the better among the bad lot. (And nothing can beat itunes for managing music on my ipod. One reasons why I also have windows as a dual boot. All other ipod sync plugins provided by any of the Linux players suck.)
  7. VLC player for videos.
  8. Was also looking at installing Tweetdeck but still need to look through this as Tweetdeck requires Adobe AIR and sadly AIR has stopped its support for Linux compatibility. May be version 2.6 will do, but then, even Tweetdeck appears to have some installation errors on Ubuntu offlate.

Other stuff
Programming in Ubuntu has always been heaven, cannot really give you reasons why but I just love it on Linux!
  1. Installed Oneiric Ocelot (64 bit) with partitions spaces 50GB for Ubuntu root /, 150 GB for /home .
  2. Java and groovy for Linux.
  3. Eclipse Galileo with groovy plug ins.
  4. SCITE and scintilla, an open source text editor that I've been recently introduced to, highly powerful and capable of supporting many languages like C, C++, python, ruby, perl, et al. Highly customizable for a programmer and lot more powerful than the standard gedit of Ubuntu.
  5. Changed etc/xdg/autostart to startup apps like Launchy on Ubuntu login, so that I don't have to do it manually each time.
  6. I am also looking at auto mount of external disks that share space between Windows and Ubuntu to escape the manual labor each time at startup. A simple bash script or etc/fstab may be? Need to look through..

Well, That's it for a brief start of a long journey with Oneiric Ocelot.

Launch Applications on Ubuntu Startup

You can always add programs/applications to linux startup without having to launch them maunally, meaning, the application you wish for will launch itself automatically as soon as you boot into ubuntu after logging in.

For instance, let us say you are looking at adding firefox web browser to your start up list, all that is needed to be done is, to copy the firefox.dekstop file from user/share/applications folder to the etc/xdg/autostart folder.


Via Terminal :

  1. Ctr+Alt+T to open terminal
  2. Type in the following command and hit eneter
    sudo cp /usr/share/applications/firefox.desktop /etc/xdg/autostart

Via GUI :

  1. Hit Alt+F2, type in
    gksudo nautilus

    //This will ensure deliberate copy of the desktop file albeit the file permission issues if any.

  2. Browse through Filesystem -> usr -> share -> applications
  3. Copy the desired .desktop file (firefox.desktop in this case)
  4. Browse through Filesystem -> etc -> xdb -> autostart and paste it in the folder.
This will start firefox on ubuntu startup. Similar approach can be adapted for any other application installed.

Wednesday, September 21, 2011

Groovy Based RSS Reader - Intro


A desktop application with the help of which a user can keep track of his favorite blogs or the frequently visited websites.
Pre-requisite to be able to work with:
The website/blog should necessarily have an option for RSS feed subscription.
Rough Ideas/Steps involved :
1) Fetch the URL of the website/blog from the user as input.
2) Search the metatags of the page for existence of an rss feed.
3) If an rss feed for the website/blog exists, fetch the rss content from the feed URL, parse it and perform the display logic.
4) On exit, save state of UI i.e of all the blogs subscribed. On reopen, update feeds.
Genuinely started with the aim to target bloggers i.e users of blogspot/wordpress and other famous blog hosting sites. Should be in a position to extend the functionality to all websites that provide for an RSS subscription.

Monday, September 19, 2011

Serializing objects in Groovy

Never came across a more sexier way to serialize objects. Thanks to groovy goodness.


def map1 = ['1':'one']
def map2 = ['2':'two']

def file = new File("C:/serializedObjects.txt")

file.withObjectOutputStream { out ->
    out << map1
    out << map2          
}
                     
file.withObjectInputStream(getClass().classLoader){ ois ->
    ois.eachObject{
        println it                  
    }
}      

Monday, August 22, 2011

Retrieve the RSS Feed URL of a Webpage

/* A dirty code tweak that can search the meta tags
* of a webpage for its rss feed url.
* If a feed exists for the page,
* the rss feed link portion of the page source
* will be extracted using regex.
*/

def getRSSFeedURLFor(String urlStr){
def url = urlStr.toURL()
def result = []
def str
def lookForStart = '''<link rel="alternate"'''
def lookForEnd = '''>\n'''

url.eachLine {
if(it.contains("RSS"))
result << it + "\n"
}

result.each{
if(it.contains(lookForStart)) {
strtIdx = it.indexOf(lookForStart)
lastIdx = (it.indexOf(lookForEnd)+2)
str = it.substring(strtIdx,lastIdx)
}
}

str = str.replaceAll(/(.*)(href.+)"(.*)"(.*)\n/,'$3')
str = str.trim()
return str
}

def urlStr = "http://www.ashes-phoenix.blogspot.com"
def rssURL = getRSSFeedURLFor(urlStr).toURL()
println rssURL

PS: For most of the standard websites, if an RSS feed exists for the page, it will be specified in one of the metatags of the page source that looks like:

<link rel = "alternate" type=atom/application/rss+xml href=''...>

The logic lies in extracting the link within the href attribute of this tag which is actually the rss feed of the page we are trying to retrieve


Friday, August 19, 2011

Build a Binary Tree & Perform an Inorder traversal



/*
* A simple groovy implementation to create a Binary Tree
* and to perform inorder traversal
*/

class Node{

    Node left, right
    int data
   
    Node(data){
        this.data = data
        left = null
        right = null
    }
}


class BTree{

    static def insert(Node node, val){
      if(val < node.data){
          if(node.left == null){
              node.left = new Node(val)
              println "inserting $val to the left of $node.data"
          }
         
          else insert(node.left, val)
      }
     
      else if(val > node.data){
          if(node.right == null){
              node.right = new Node(val)
              println "inserting $val to the right of $node.data"
          }
         
          else insert(node.right, val)
      }
     
    }
   
    //left, root, right
    static def printInOrder(Node node){
        if(node == null) return
       
        else{
            printInOrder(node.left)
            println node.data
            printInOrder(node.right)
        }
    }
}

//Shift to main if you aren't running this as a groovy script
def root = new Node(25)
BTree.insert(root, 10)
BTree.insert(root, 30)
BTree.insert(root, 24)
BTree.insert(root, 299)
BTree.insert(root, 266)
BTree.insert(root, 121)
BTree.insert(root, 920)

//Inorder traversal of the entered elements
BTree.printInOrder(root)


Friday, July 08, 2011

Latest Trends in Google - July 2011

Off late Google has been adding so many features into its products with so much of pace like its ass is on fire. And probably this is good news for users. Firstly, the launch of +1 button took place, which was pretty much accepted by users as it could enhance the quality of keyword based web search. Although I feel that there are two serious flaws in its design. Firstly, the authenticity of +1 could not be trusted to 100%. I'd just hit a +1 button to my blog that shows up on a keyword search simply because it is MY blog. Or I could simply program a bot for this if possible. Secondly, the +1 shows up on keyword search. How can a user judge the quality of a website shown up before visiting it. Assuming that one finds the site relevant and accurate, why would one ever come back to the search page to hit the +1 button. These issues, I believe, though not showstopper flaws, certainly needs intervention.

And then comes the much hyped Google plus, perhaps which is still yet to take off. As of now, people believe that it is just old wine in new bottle. Nevertheless, it is still possible that g+ might surpass Facebook one day because of its renewed older features of social networking along with a few new features.

Google has also modified its user interface for the sidebar of Google search. It now comes with readable, glassy gray and brown fonts. On the similar lines Google also worked out a clutter free theme for Gmail named 'preview' which I believe, is so far the best theme for gmail ever. It has this elegant wider inbox list which can now be filtered to be read based on 'Important first', 'Unread first', et al.

Adding to this, Google has confirmed that it would lay emphasis on changing the look and feel of its products for a better user experience. And today, we also witness a change in UI for blogger. Login to http://draft.blogger.com with your blogspot id to check out the new interface for blogger.

Look and feel apart, Google is yet to officially rename its well known two products Picasa and Blogger. Picasa would now be renamed to Google photos and Blogger would now be renamed to Google blogs. This is Google's attempt to allow complete integration of these products into its latest revelation, Google plus. This might proabably become one of the major 'thumbs-up' for Google plus over Facebook.

Google is in a hurry now to prove its presence in everything and I guess it might just be able to prove this point to the world that it might eventually become omnipotent, omniscient and all pervading, probably a digital god. As of now all we can say is, It's cooking in Google's Kitchen.