using a combination of JSCH and Apache VFS Commons to SFTP with a private key

December 16, 2011 Leave a comment


package test.sftp;

import java.io.File;

import org.apache.commons.vfs.AllFileSelector;
import org.apache.commons.vfs.FileObject;
import org.apache.commons.vfs.FileSystemException;
import org.apache.commons.vfs.FileSystemManager;
import org.apache.commons.vfs.FileSystemOptions;
import org.apache.commons.vfs.VFS;
import org.apache.commons.vfs.provider.sftp.SftpFileSystemConfigBuilder;

import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.SftpException;

public class SFTPTest {

public static void main(String[] args) throws JSchException, SftpException,
FileSystemException {

FileSystemOptions options = new FileSystemOptions();
SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(options, "no");
File keyFile = new File("path/to/the/private/key.ppk");
SftpFileSystemConfigBuilder.getInstance().setIdentities(options, new File[] { keyFile });
SftpFileSystemConfigBuilder.getInstance().setKnownHosts(options, new File("path/to/known_hosts")); // usually ~/.ssh/known_hosts
SftpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(options, true);

FileSystemManager fsManager = VFS.getManager();
String uri = "sftp://username:password@hostname:22";

FileObject from = fsManager.resolveFile(uri, options);
FileObject to = fsManager.resolveFile("/tmp", options);
to.copyFrom(from, new AllFileSelector());
}
}

Categories: Java Tags: , , , , , , , , ,

Convert org.w3c.dom.Document to org.dom4j.Document

December 16, 2011 Leave a comment

Because I like the xpath support of dom4j


org.w3c.dom.Document w3cDoc;
org.dom4j.io.DOMReader reader = new DOMReader();
org.dom4j.Document document = reader.read(w3cDoc);

Categories: Java Tags: , , , ,

reset forgotten mysql password

November 11, 2011 Leave a comment

To reset a forgotten mysql password, log in as root then find and kill the mysqld process

ps -e mysqld | grep mysqld

sudo kill -9 <mysqld-process-id>

now create a file in your home folder, “mysql-reset.txt” for example, and put these two lines in it

UPDATE mysql.user SET Password=PASSWORD(‘the-new-password’) WHERE User=’root’;
FLUSH PRIVILEGES;

then go back to the prompt and run

mysqld_safe –init-file=/path/to/the/file/mysql-reset.txt &

Categories: Linux

Selenium RC: count rows in a table

October 5, 2011 Leave a comment

While running Selenium tests, if some part of your logic requires you to count the number of rows in a table, we can do this in Java:

getXpathCount(“//xpath/to/the/particular/table/tbody/tr”)

eg:

int numRows = selenium.getXpathCount(“//table/tbody[2]/tr”).intValue();

Categories: Java, Selenium

enable assertions in eclipse

December 24, 2010 Leave a comment
  • Window -> Preferences -> Java -> Compiler

  • Run -> Run Configurations and enter -ea or -enableassertion as argument

Categories: Java

kitchen measures

July 18, 2009 Leave a comment
This is planned to be my one stop for all food related measures. Look out for updates.
Liquid measures:
1 teaspoon is 5 ml
1 tablespoon is 15 ml
1 cup is 240 ml
3 teaspoons is 1 tablespoon
16 tablespoons is 1 cup
8 ounces is 1 cup
2 cups is 1 pint
2 pints is 1 quart
4 quarts is 1 gallon
Hope that saves me some searching the next time.

Liquid measures:

1 teaspoon is 5 ml

1 tablespoon is 15 ml

1 cup is 240 ml

3 teaspoons is 1 tablespoon

16 tablespoons is 1 cup

8 ounces is 1 cup

2 cups is 1 pint

2 pints is 1 quart

4 quarts is 1 gallon

Hope that saves me some searching the next time.

Categories: Misc

best poirot

February 10, 2009 Leave a comment

Whose could be considered the best portrayal of Hercule Poirot in the media?

David Suchet is very impressive in the BBC television series but Albert Finney in Murder on the Orient Express is better by far though initially a little hard to accept. However my favourite would be John Moffatt as Poirot in the BBC radio dramas, he’s is everything that ever leapt to your imagination when you first read the books!

Categories: Devil's Workshop, Misc

To have Eclipse use a particular Java VM

February 10, 2009 Leave a comment

To have Eclipse use a particular Java VM :

Edit the eclipse.ini file and add the vm argument below the line org.eclipse.platform

-vm /absolute/path/to/your/java/executable

I’ve found this particularly useful on Windows when I’ve installed and removed various versions of JDK and eclipse appears completely lost and confused.

Categories: Java, Linux

mandriva installation on acer 5050 laptop

April 20, 2008 4 comments

Kubuntu left a lot to be desired on my machine so I looked around for another good KDE distro and found Mandriva!

What works out of the box:

  • External Speakers! Hallelujah! Finally!!
  • Desktop effects run right off the live CD

What doesn´t:

  • Webcam still doesn´t work but that´s really low on priority
  • Power management is still a pain (I´m looking into this, expect a post soon)
  • Bluetooth needs a lot of tweaking go get to work

Repository Setup :

Setting up repositories in Mandriva is not quite as easy as Ubuntu´s sources.list way. However, no need to fret. Head over here and follow the instructions. Voila!

Also, you´ll find that the repository locks every now and again with a ¨”URPMI DATABASE LOCKED”¨. This post is what you´ll need.

Very easy and intuitive , Mandriva is the Ubuntu for the KDE fan!

Categories: Linux Tags: , , , ,

tora – a toad alternative for linux

January 25, 2008 2 comments

With my recent conversion to Linux one of the first things I missed was a familiar DB client.

I’d been working with Toad on Windows for quite a bit now and had grown rather used to the interface. I needed a similar replacement on Linux. A search for “Toad + Linux” threw up a lot of TOra.

TOra has all the same features as Toad with very similar interface, including schema browser, syntax highlighting and support for common databases.

Trouble is, by default TOra comes packaged with only the PostgreSQL “Connection Provider” .

So if you want to get it to work with MySQL the following Qt dependencies need to be installed as well:

sudo apt-get install tora libqt3-mt-odbc libqt3-mt-mysql
Categories: Linux
Follow

Get every new post delivered to your Inbox.