Wednesday, December 8, 2010

Pipe to clipboard in bash on ubuntu

Say you wanted the output of a command like ls to be copied directly into the clipboard for pasting into your gui windows. Use xclip:
sudo apt-get install xclip
Then
ls | xclip -selection clipboard
will copy the output of ls into the clipboard.

I use an alias in my .bashrc for it:
alias c='xclip -selection clipboard'
So the command becomes:
ls | c

Quickly changing your .bashrc file

I use aliases all the time and am always adding more shortcuts for my terminal experience to the .bashrc file. So it's only natural that I made a convenient alias for doing exactly that.

Add this line to your .bashrc file:
alias vib='vi ~/.bashrc && source ~/.bashrc'

Then type source ~/.bashrc and the change will have been made.

So whenever you want to change your .bashrc file and have it come into effect for the current terminal:
vib
which will edit .bashrc and will run source on it automatically when you finish editing.

Sunday, October 10, 2010

Maven site and multi-module broken links on site:stage

Maven 2.2.1 default site plugin does a strange job of making parent to child links for a multimodule site report. When I have the parent reporting url set to a file:// url the links are broken after doing a site:stage. There is an easy workaround though. Make the reporting url a property in the parent pom.xml, say ${site.url} and from parent directory call

mvn clean site site:deploy -Dsite.url=file://`pwd`/target/deployed-site

This will deploy the site into target/deployed-site. Note that the url must be absolute, that's why I use `pwd` to insert the current directory (not for windoze of course). Put whatever url you like in site.url if the above does not suit.

Friday, April 16, 2010

IMDB Lookup from Nautilus in Ubuntu

This is how you implement a Lookup IMDB right click menu action for a movie file visible in Nautilus. It's really easy using Nautilus Actions!

First install nautilus-actions
sudo apt-get install nautilus-actions
Now create the script to launch the browser given a filename.
sudo wget -N -P /usr/bin http://moten-util.googlecode.com/svn/ubuntu/trunk/lookup-imdb/lookup-imdb sudo chmod 755 /usr/bin/lookup-imdb
Choose System - Preferences - Nautilus Actions Configuration - Add.
Set values in Action tab as below
Label: Lookup IMDB
Path: lookup-imdb
Parameters: %b
Logout and back in again and you should be ready to go.

Note: if you find that your default browser is not being opened by the x-www-browser command then select your default browser by
sudo update-alternatives --config x-www-browser
As of 5 May 2013 this works fine in Ubuntu 12.04 with Unity.

Friday, January 29, 2010

Guice 2.0: Mixing injected and non-injected parameters

Have been using Guice for a couple of years now after a friend at Google put me on to it. Guice 2.0 is great too, one thing it makes easier is mixing injector controlled parameters and non-injector controlled parameters into a constructor (I think constructor injection is way more solid than field/method injection when you can).

The feature is called AssistedInject, here is an example:

public class PersonLocator() {
@Inject
public PersonLocator(GeneralLocator locator, @Assisted String name) {
...
}
}

To instantiate PersonLocator using the injector you need to create a PersonLocatorFactory:

public interface PersonLocatorFactory {
PersonLocator create(String name);
}

Put a binding into the injector module:

bind(PersonLocatorFactory.class).toProvider(
FactoryProvider.newFactory(PersonLocatorFactory.class, PersonLocator.class));

Then to instantiate PersonLocator use an injected PersonLocatorFactory:

public PersonHunter {
@Inject
public PersonHunter(PersonLocatorFactory personLocatorFactory, String name){
PersonLocator personLocator = personLocatorFactory.create(name);
}
}