Posts

Clojure and maven

Image
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 s...

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 ima...

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);

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 MyProvid...

Service mix error compiling SA - "does not have a dependency which is packaged as a jbi-component or a project property 'componentName'"

This error used to come especially when you have two or more service units that is dependent on the same component (ex a file sender and a file poller , both being dependent on servicemix-file component) Googling found me that this was an error - https://issues.apache.org/activemq/browse/SM-694 but putting the componentName property was not working. In the end updated the verison of the jbi-maven-plugin to verison 4.0 in the pom.xml of the Service Assembly - SA org.apache.servicemix.tooling jbi-maven-plugin 4.0 true service-assembly (Note this error was comming only when you compile the SA and the individual compilation of the SU was going fine; Also this can come if you have for example not put the depedencies, or say the correct verison of the dependencies in the pom.xml of the SU)

Tomcat and servlets

Sevlet Package Strucutre package proto.inmc.fm.servlet; Web Xml Structure    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"    version="2.5">          inmcservlet      proto.inmc.fm.servlet.inmcservlet            inmcservlet      /servlet/inmcservlet2      Deploy dir in Tomcat D:\Program Files\Apache Group\apache-tomcat-6.0.16\apache-tomcat-6.0.16\webapps\inmc\WEB-INF\classes\proto\inmc\fm\servlet Html depl0y place in Tomcat D:\Program Files\Apache Group\apache-tomcat-6.0.16\apache-tomcat-6.0.16\webapps\docs\inmc.html Html invocation of servlet form name="myForm" method="GET" action="../inmc/servlet/inmcjnlp" input type="submit" value="Get Logged in User"  form Paths  http://localhost:8090/docs/inmc.html  http://localhost:8090/docs/inmcjnlp.html http://localhost:8090...

Jacorb Publish a Corba Servant on well know port without Naming Service

Thanks to the posts from - [jacorb-developer] ' Publish a Servant on well know port ' I was able to do the same. Below are the server and client snippet. This is using Jacorb ORB. Server code String[] args3=  { "-DOAPort=4013" };         java.util.Properties argProps = ObjectUtil.argsToProps( args3 );                         Properties props = System.getProperties();         props.put("org.omg.CORBA.ORBClass", "org.jacorb.orb.ORB");//JACORB         props.put("org.omg.CORBA.ORBSingletonClass", "org.jacorb.orb.ORBSingleton");         props.put("org.omg.PortableInterceptor.ORBInitializerClass.bidir_init",           "org.jacorb.orb.giop.BiDirConnectionInitializer");         props.put("jacorb.implname","StandardImplName");         props.putAll( argProps );         System.setProperties(props); orb = org.omg.CORBA.ORB.init(args, props); root_poa = org.omg.PortableServer.POAHelper.narrow( ...

Configuring PHP in Apache 2 in Windows

1. Install php and crate a dir in c:\php and copy the unzipped file there Copy all the dll's under php to c:\windows\system32 reanme php.ini-dist to php.ini and put it in path c:\windows for example Also in php.ini add support to mysql "As with enabling any PHP extension (such as php_mysql.dll), the PHP directive extension_dir should be set to the directory where the PHP extensions are located. See also the Manual Windows Installation Instructions. An example extension_dir value for PHP 5 is c:\php\ext" 2. In the Apache httpd.conf After #ExtendedStatus On Add LoadModule rewrite_module modules/mod_rewrite.so LoadModule php5_module "c:/php/php5apache2.dll" AddType application/x-httpd-php .php AddType application/x-httpd-php .php3 AddType application/x-httpd-php .php4 Then set permission to # # This should be changed to whatever you set DocumentRoot to. # Options Indexes Includes FollowSymLinks MultiViews ExecCGI AllowOverride All Note - check the security risk...

Periodic refresh with AJAX

Hint use - timerID = window.setInterval("ajaxFunction()",5000); Below is the AJAX script And in the HTML body

Deploying under tomcat

Deploying under tomcat 1 Class inmcservlet.class is under the package proto.inmc.fm.servlet. 2 Directory strcture of tomcat depolyment D:\Program Files\Apache Group\apache-tomcat-6.0.16\apache-tomcat-6.0.16\webapps\inmc\WEB-INF\classes\proto\inmc\fm\servlet Under servlet inmcservlet.class 3. The web Xml Web.xml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5"> inmcservlet proto.inmc.fm.servlet.inmcservlet inmcservlet /servlet/inmcservlet2 4 . The url string http://localhost:8080/inmc/servlet/inmcservlet2

Java Log4j

Code snippet log4j.properties ### direct log messages to stdout ### #log4j.appender.stdout=org.apache.log4j.ConsoleAppender #log4j.appender.stdout.Target=System.out #log4j.appender.stdout.layout=org.apache.log4j.PatternLayout #log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n #log4j.rootLogger=debug, stdout ### direct log messages to a file ### log4j.appender.file=org.apache.log4j.FileAppender log4j.appender.file.File = mylog.txt log4j.appender.file.layout=org.apache.log4j.PatternLayout log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n log4j.rootLogger=debug,file

Checking Memory Corruption using Gflags and NTSD debugger

>gflags /p /enable mmladc.exe path: SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options mmladc.exe: page heap enabled >gflags /p path: SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options mmladc.exe: page heap enabled with flags (traces ) >ntsd -g -x -pn mmladc.exe If there is a heap corruption you will see something like this =========================================================== VERIFIER STOP 00000006: pid 0x3634: corrupted heap pointer or using wrong heap 01421000 : Heap used in the call 0152C100 : Heap block 00000000 : Block size 70F0F0F0 : Heap owning the block =========================================================== >.lines Line number information will be loaded >kb

Porting fron VC6 to VC7 compiler errors

------------------------------------------------------------------------ Code which compiles in VC6 typedef priority_queue *,//value type deque *>,//container type Command ::Compare > REQUESTQUEUE; //comapritor typedef map ::iterator REQUESTQUEUEITR; std::map RequestQueue; std::map ::iterator CurrentItr; Changes to be done to compile in VC7 ------------------------------------------------------------------------ typedef priority_queue *,//value type deque *>,//container type typename Command ::Compare > REQUESTQUEUE; //comapritor typedef typename map ::iterator REQUESTQUEUEITR; //todo make this a priority queue - priority_queue std::map RequestQueue; typename std::map ::iterator CurrentItr; ------------------------------------------------------------------------ tags vc7 nested class template cannot access private class declared in class vc7 dependent name is not a type

A little Perl goes a long way

I have found Perl as very powerful language , a must in the toolkit for any programmer Here are some Perl code snippets. It is always better to start your perl code with use strict; use warnings; With this you have to declare variable before you use them like my $SearchStep=0; my $line; Also if you want to use special Perl modules like for example working with ini files , you include it use IniFiles; Everything is pretty simple in Perl, only thing is that the syntax can become unreadable; so put in a lot of comments # This is a comment Okay let us jump in -- here is the code to open a file my $FilePath = "system1.txt"; my $opened =open (FH, $FilePath) ; if( !$opened) { print "Cannot open file\n"; die; } and to read line by line from the file my $line; while ( $line = ) { chomp ($line); : Now to test if a line matches a perl pattern if($line = ~ m/ $SearchPattern/ i ) /i stands for case insensitive search. Okay a few other matche examples ( b...

Java JVM high memory usage problems

Though I have some three four years experience in C++ ,I did not have that much oppurtunity to work in Java. Currenly I was doing some analysis for a very simple CLI and was surprised to come with a memory restriction. I found that if I use Java for developing the CLI application I will be exhausting the memory of our Application Server (AS). Just to mention the architecture ,users (telecom operators) use a metaframe server client ( =something like remote desktop) to login to the AS and then open a GUI to work on it. With Java I can service only about 15 clients with the available memory . I just checked the reason for this resource crunch and found that already many Java based GUI's are served by the AS and each is taking some 25 MB or more. The first thing I thought is that adding more RAM will solve this ( though this is not an easy option) . Then I understood that a 32 bit system can have just about 3 gb ram for applciations and our AS had already 4 GB with 1.5 GB VM also co...

Windebug and Adplus for debugging process hang

1. Set the symbol, especillay windows symbols .......26_Merged\UNCRelease;\\blrm2fsp\SCSD-Common\Sym\WinSym2K3SP1 2. Set the souce and image 3. Load the extension dll ( for !locks command ) if not already loaded .load C:\Program Files\Debugging Tools for Windows\winxp\kdexts.dll 4. Use the !ntsdexts.locks ( or !locks ) command to see a list of critical section :004> !ntsdexts.locks CritSec ntdll!LdrpLoaderLock +0 at 7C889D94 LockCount -6902 RecursionCount 1 OwningThread 2b3c EntryCount 0 ContentionCount 28f3 *** Locked CritSec +12f9b4 at 0012F9B4 LockCount 0 RecursionCount 0 OwningThread 0 *** Locked CritSec +12f70c at 0012F70C LockCount 0 RecursionCount 0 OwningThread 0 *** Locked CritSec +128202c at 0128202C LockCount -2 RecursionCount 1 OwningThread 3d9c EntryCount 0 ContentionCount 0 *** Locked ----------- A 'LockCount' other than 0 means that many threads are waitiing on t...

windbg command

Wednesday, 25 August 2004 To list all modules loaded by the process -LM (shows the loaded module address also) : WinDebug thread commands To see all threads ~ To freeze all threads ~*F to unfreeze thread 1 ~1U to set the thread ~S copying to stl list If destination is an empty list lstOfInt.push_back(1); lstOfInt.push_back(2); lstOfInt.push_back(3); copy(lstOfInt.begin(),lstOfInt.end(),lstOfIntDest.begin() ); -->WRONG copy(lstOfInt.begin(),lstOfInt.end(),back_inserter(lstOfIntDest) ); -->CORRECT

CORBA - C++ Client (ACE TAO) Java Server (JacORB) A simple example

Step 1 I downloaded the binary relaease of JacOrb Extracted the zip file to E:\Program Files\JacORB-2.2.4\ Step 2 Then also downloaded Ant Also jdk was downloaded and installed Step 3 Then created the batch file (to set the path) Set ANT_HOME=E:\Program Files\Java_Ant\apache-ant-1.6.5 Set JAVA_HOME=E:\Program Files\Java\jdk1.5.0_03 Set JACORB_HOME=E:\Program Files\JacORB-2.2.4 Set Path=%ANT_HOME%\bin;%JAVA_HOME%\bin;%JACORB_HOME%\bin;%JACORB_HOME%; Set CLASSPATH=%JAVA_HOME%\lib;%JAVA_HOME%\jre\lib;%JAVA_HOME%;%JACORB_HOME%\lib; ----now to configure JacORB - In the command promt E:\Program Files\Java_Ant\apache-ant-1.6.5>ant jaco E:\Program Files\Java_Ant\apache-ant-1.6.5>ant idlcmd okay that’s done Now write the idl --- test1.idl------ module Quoter1 { //a test interface interface Stock { double price(); //to get the quote of the stock readonly attribute string symbol; readonly attribute string fullname; }; //interface to get the stock object exception InvalidStockSymbol {}; //to...

Importance of TypeSafety -An example

class Bank { private: bool bFirstLock; bool bSecondLock; BankVault* pBankVault; public: Bank() { bFirstLock=0; bSecondLock=0; pBankVault= new BankVault ; } bool IsLocked() { if(( true == bFirstLock) && (true== bSecondLock)) { printf("Both Locks unlocked- Bank is UNLOCKED\n"); return false; } else { printf("Bank is LOCKED\n"); return true; } }; }; //----------------------------------------------------- class Robber { short ForgedKey; void* pAceesor; public: Robber() { ForgedKey=0; }; RemoveLocks() { //This method has the instruction to set the first // 2 bytes (short) of the start of the class to value //257; This in binary is 00000001 00000001;ie the first 2 bytes to 1 ; //But since we are using the pointer of the Bank object to call //this method, it sets the first 2 bytes of the object of //bank to 00000001 00000001; But in the Bank object the first 2 //bytes are occupied by two boolean varia...

Unix - Checking the virtual memory of process

ps -elf | grep In Solaris the size (SIZ) column specifies memory size