Wednesday, September 07, 2011

Clojure and maven

I had started about learning clojure and though the REPL interpreter seems to be the standard way of starting learning, I wanted to do it in a more Test driven method using maven. So I created a source and test directory and went about writing a simple learn.clj and a simple testlearn.clj. Took some time to figure things out and make the tests work Here is the directory structure


 (Learn.clj dir structure \NetBeans2\ClojureLearn2\src\main\clojure\my\clojure\learn.clj)


(ns my.clojure.learn
 (:gen-class))


(defn main  [args]
  (println  "A red apple tree" )
   (println (def x(str "Hello " args "!")) )
   x
 )


(defn add [x y]
    (+ x y)
)


( defn workingwithlist []
  (println "In the function workingwithlist")
  (def listx (list 1 (add 1 1) 3 4  ))
   (doseq [item listx]
   (println item))
     listx
  )

 (TestLern.clj dir structure \NetBeans2\ClojureLearn2\src\test\clojure\my\clojure\Testlearn.clj)



(ns my.clojure.Testlearn
(:use my.clojure.learn)
(:use clojure.test)
      (:gen-class)
 )
(deftest test-add
  ; equals is easy what about not equal to
  (is(not= 5 (add 1 2)))
  )
(deftest test-add2
  ; equals is easy what about not equal to
  (is(= 3 (add 1 2)))
  )


(deftest test-helloworld
  
  (is(= "Hello World!"(main "World")))
 )


(deftest test-lists
  (list? (workingwithlist))
  )

 And here is the pom.xml dir ( \ClojureLearn2\pom.xml) 

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<properties>
    <clojure.version>1.1.0</clojure.version>
</properties>
<modelVersion>4.0.0</modelVersion>
<groupId>org.enclojure</groupId>
<artifactId>sample</artifactId>
<version>0.0.1</version>
<name>ClojureLearn2</name>
<description>ClojureLearn2</description>
<build>
    <sourceDirectory>src/main/clojure</sourceDirectory>
    <testSourceDirectory>src/test/clojure</testSourceDirectory>
    <resources>
        <resource>
            <directory>src/main/clojure</directory>
        </resource>
        <resource>
            <directory>src/main/resources</directory>
        </resource>
    </resources>
    <testResources>
        <testResource>
            <directory>src/test/clojure</directory>
        </testResource>
    </testResources>
    <plugins>
        <plugin>
            <groupId>com.theoryinpractise</groupId>
            <artifactId>clojure-maven-plugin</artifactId>
            <version>1.3.2</version>
            <configuration>
                <sourceDirectories>
                    <sourceDirectory>src/main/clojure</sourceDirectory>
                </sourceDirectories>
                <clojureOptions>-Xmx1G</clojureOptions>
            </configuration>
            <executions>
                <execution>
                    <id>compile-clojure</id>
                    <phase>compile</phase>
                    <goals>
                        <goal>compile</goal>
                    </goals>
                </execution>
                <execution>
                    <id>test-clojure</id>
                    <phase>test</phase>
                    <goals>
                        <goal>test</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.5</source>
                <target>1.5</target>
            </configuration>
        </plugin>
    </plugins>
</build>
<repositories>
    <repository>
        <id>central</id>
        <url>http://repo1.maven.org/maven2</url>
    </repository>
    <repository>
        <id>clojure-releases</id>
        <url>http://build.clojure.org/releases</url>
    </repository>
    <repository>
        <id>incanter</id>
        <url>http://repo.incanter.org</url>
    </repository>
    <repository>
        <id>clojure-snapshots</id>
        <url>http://build.clojure.org/snapshots</url>
    </repository>
    <repository>
        <id>clojars</id>
        <url>http://clojars.org/repo/</url>
    </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId>org.clojure</groupId>
        <artifactId>clojure</artifactId>
        <version>${clojure.version}</version>
    </dependency>
    <dependency>
        <groupId>org.clojure</groupId>
        <artifactId>clojure-contrib</artifactId>
        <version>${clojure.version}</version>
    </dependency>
    <dependency>
        <groupId>swank-clojure</groupId>
        <artifactId>swank-clojure</artifactId>
        <version>1.1.0-SNAPSHOT</version>
        <exclusions>
            <exclusion>
                <groupId>org.clojure</groupId>
                <artifactId>clojure</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.clojure</groupId>
                <artifactId>clojure-contrib</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
</dependencies>
</project>

Thursday, June 16, 2011

Booting OS/Ubuntu from an external Hard disk uisng Virtual Box virtual harddrive feature

First you need to boot from the hard drive

For that put the harddrive in an hardrive enclosure and connect it via usb to your host OS

Then follow the steps in the Virtual box help guide

9.9.1. Access to entire physical hard disk
While this variant is the simplest to set up, you must be aware that this will give a guest operating system direct and full access to an entire physical disk. If your host operating system is also booted from this disk, please take special care to not access the partition from the guest at all. On the positive side, the physical disk can be repartitioned in arbitrary ways without having to recreate the image file that gives access to the raw disk.

To create an image that represents an entire physical hard disk (which will not contain any actual data, as this will all be stored on the physical disk), on a Linux host, use the command

VBoxManage internalcommands createrawvmdk -filename /path/to/file.vmdk
-rawdisk /dev/sda
This creates the image /path/to/file.vmdk (must be absolute), and all data will be read and written from /dev/sda.

On a Windows host, instead of the above device specification, use e.g. \\.\PhysicalDrive0.

Creating the image requires read/write access for the given device. Read/write access is also later needed when using the image from a virtual machine.

Just like with regular disk images, this does not automatically register the newly created image in the internal registry of hard disks. If you want this done automatically, add -register:

VBoxManage internalcommands createrawvmdk -filename /path/to/file.vmdk
-rawdisk /dev/sda -register
After registering, you can assign the newly created image to a virtual machine with

VBoxManage modifyvm WindowsXP -hda /path/to/file.vmdk
When this is done the selected virtual machine will boot from the specified physical disk.

To resize the graphics window


cd /media/cdrom1
sudo bash ./VBoxLinuxAdditions-x86.run

To create a share from which you can copy files to and fro from the host to the guest hard disk

mount -t vboxsf vbox \mnt\

Thursday, March 24, 2011

Connecting to JMX with username and password

Got the tip from http://mx4j.sourceforge.net/docs/api/mx4j/tools/remote/PasswordAuthenticator.html
-----------------------------------------
echo("\nCreate an RMI connector client and " +
"connect it to the RMI connector server");
JMXServiceURL url =
//new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:9999/jmxrmi");
new JMXServiceURL("service:jmx:rmi:///jndi/rmi://11.11.11.11:711/jmxrmi");

String[] credentials = new String[2];
// The user will travel as clear text
credentials[0] = "user"; //user name
credentials[1] = "password"; //password

Map environment = new HashMap();

environment.put(JMXConnector.CREDENTIALS, credentials);


JMXConnector jmxc = JMXConnectorFactory.connect(url, environment);

Thursday, February 10, 2011

Creating a Servicemix Binding Component and using it

Here are the steps I followed to do this

Prerequisite

- A working knowledge of maven is a must
- Some knowledge of using Xbean is good ( not a must)

Creating a BC

1. Follow steps in http://servicemix.apache.org/hello-world-bc.html

mvn archetype:create -DarchetypeGroupId=org.apache.servicemix.tooling -DarchetypeArtifactId=servicemix-binding-component -DarchetypeVersion=3.3.2 -DgroupId=com.nsn.hiq -DartifactId=hello-world-bc

2.

http://markmail.org/message/gfxipkxic73fq2rg#query:+page:1+mid:keescdr6cm6g3hhc+state:results

3.

http://servicemix.396122.n5.nabble.com/Exception-on-hello-world-BC-sample-td415697.html

4.

http://www.mail-archive.com/users@servicemix.apache.org/msg02389.html
xmlns:hellobc="http://com.nsn.hiq/1.0"

Some tips

In MyProviderEndPoint class the Xbean annnotation marks the name of the provider endpoint
(which we will need later to use this component)

/**
* @org.apache.xbean.XBean element="provider"
*/
public class MyProviderEndpoint extends ProviderEndpoint implements MyEndpointType {

Similarly for the ConsumerEndPoint

/**
* @org.apache.xbean.XBean element="consumer"
*/
public class MyConsumerEndpoint extends ConsumerEndpoint implements MyEndpointType {

And also the component name

/**
* @org.apache.xbean.XBean element="component"
*/
public class MyComponent extends DefaultComponent {

------

Okay now how to create a SU that can call this BC.

Using maven created a simple SU and put this in the xbean.xml

xmlns:inmc="http://inmc.nsn.com/9.6"
xmlns:hellobc="http://com.nsn.hiq/1.0" >
endpoint="hellobc_endpoint" />
---
Now we can use a file poller to poll a folder

endpoint="endpoint"
targetService="test:eipcustombc"
file="d:\temp\_del\pollertest">

And in the EIP wire this to the the BC end point


And the send the output from our BC to a file sender

endpoint="endpoint"
autoCreateDirectory="true"
directory="d:\temp\_del\pollerOut_aggregate">

That all .




Install/Upgrade NVIDI Driver in Ubuntu for CUDA SDK

Most linux distribution comes with the Nouveau https://nouveau.freedesktop.org/wiki/ display driver configured. If you need to use NVIDIA...