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

Saturday, November 05, 2011

Automount NTFS drives on Ubuntu

Well, here's for the lazy ones out there. I came across this simple tweak to fix the problem of manually mounting disks (either external/NTFS) on Linux.

If you have frequently accessed files placed on several drives or partitions that are external to Linux, you need to manually mount these partitions manually from Nautilus or terminal prior to accessing files/directories in them. To avoid this, you can change the contents etc/fstab file in such a way that they are auto mounted on startup.

Prior to editing the fstab content, you need to know the partition label of your drive. Partition labeling (alphabets followed by a number) is quite different in Linux when compared to Windows. Your NTFS partition might look something like sda2 or sda3.

For the geek

Step 1: Running the

fdisk -l

command will give you details of all the partitions like the one shown above.

Step 2: If you fail to decipher anything out of the above output, Just run the below command against the device names whose System column of the above output contains NTFS in it.

fdisk -s /dev/sda6

Running the above command will give you the size of the partition sda6 in bytes which gives you a better chance of identifying the drive (presuming that you might at least know the approx size of the NTFS drive you want to mount).

Step 3: Run the below command below 

sudo mkdir /media/Windows
sudo echo "/dev/sda6 /media/Name_of_Your_Partition ntfs-3g defaults,locale=utf8 0 0" >> /etc/fstab
sudo mount -a

which will add up the details of your partition to etc/fstab.

For the noob

1) Install mount manager via Ubuntu software center, open the app and identify the partition label of the drive to be mounted based on the disk size and partition details shown in it.

2) Hit Alt+F2 and type in
    gksudo nautilus

3) Open the file named fstab under etc folder of file system.

4) Add the below line to the file and save. 

/dev/sda6 /media/Name_of_Your_Partition ntfs-3g defaults,locale=utf8 0 0

Note: Replace sda6 by your partition label and Name_of_Your_Partition should be the name of your NTFS drive. 

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)