Wednesday, December 31, 2008

Auto create tables JPA

< property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"> < property name="hibernate.hbm2ddl.auto" value="create-drop"> < property name="hibernate.show_sql" value="true"> < property name="hibernate.cache.provider_class" value="org.hibernate.cache.HashtableCacheProvider"> < /property>

Tuesday, December 2, 2008

Recusively deleting a folder in MS DOS

for /f %D in ('dir/s/b/ad ^| find/i ".svn" ') do if exist "%D" rd/s/q "%D"
replace %D with %%D for batch job

Thursday, November 13, 2008

Where not to put presistance.xml

Where to put persistence.xml in web app? In all cases, persistence.xml always resides in {root-of-persistence-unit}/META-INF/ directory. For example,

foo.war: WEB-INF/classes/META-INF/persistence.xml //good WEB-INF/classes/com/foo123/jpa/Project.class WEB-INF/web.xml index.jsp You may also package entity classes and persistence.xml inside a library jar, which is packaged inside the war: WEB-INF/lib foo.war: WEB-INF/lib/my-entities.jar WEB-INF/web.xml index.jsp my-entities.jar: META-INF/persistence.xml //good com/foo123/jpa/Project.class For comparison, some invalid configurations are: foo.war: WEB-INF/persistence.xml //invalid WEB-INF/web.xml WEB-INF/classes/com/foo123/jpa/Project. index.jsp ----------------------------------------------- foo.war: META-INF/persistence.xml //invalid WEB-INF/classes/com/foo123/jpa/Project.class WEB-INF/web.xml index.jsp ----------------------------------------------- foo.war: persistence.xml //invalid WEB-INF/classes/com/foo123/jpa/Project.class WEB-INF/web.xml index.jsp ----------------------------------------------- foo.war: META-INF/persistence.xml //invalid com/foo123/jpa/Project.class WEB-INF/web.xml index.jsp
In all these invalid configurations, EntityManager lookup will fail with javax.naming.NameNotFoundException, or @PersistenceContext injection will be silently skipped and the em variable is always null, and hence NullPointerException when referenced.

Wednesday, July 30, 2008

SCP between two remote hosts

scp emartine@localhost:/var/eone/batch/production/data/exports/*.csv emartine@192.168.100.5:/home/emartine Now it will ask for. emartine@localhost's password: emartine@192.168.100.5's password:

Monday, July 14, 2008

MYSQL Error29

mysqldump: Got error: 29: File './databasename/tablename.MYD' not found (Errcode: 24) when using LOCK TABLES The best way to get to the bottom of the error is to find out what it means: $ perror 24 OS error code 24: Too many open files
There’s two ways to fix the problem. First, if you find that you only hit the limit during mysqldumps and never during normal database operation, just add
--single-transaction to your mysqldump command line options. ex: mysqldump -h localhost --single-transaction
This will cause mysql to keep only one table open at a time. However, if this happens while backups aren’t running, you may want to increase the open_files_limit in your MySQL configuration file. By default, the variable is set to 1,024 open files.

Saturday, May 17, 2008

FireGPG on Linux

How GPG works for the email.

Scenario 1: Sam creates public and private key Sam Publishes Sam's public Key to Key server. Bob Creates his public and private key Bob publishes Bob's public Key to Key Server.
Scenario 2:
No Sam and Bob need to engage a secured email communication. Sam pulls Bob's public key from key server and imports that public key into his trusted keyring using seahorse or gpg command line. Sam use Bob's Public Key to sign the message and send to Bob. Bob use his Private Key to decrypt and verify Sam's Message which was signed and encrypted using Bob's Public key.
Tools Needed
FireGPG GPG seahorse
Generate Key Pairs.
gpg --key-gen now the keys are generated and stored to keystore. Use the Seahorse to manual edit the keys and export keys. gpg normally get installed in usr/bin if you install with apt-get. Now install FireGPG plugin to FireFox.
Run the FireFox as ROOT. Here is the catch all the key genereration and keystore are acessible only for the root user. Firefox launch itself as firefox user, so when you launch the FireGPG it wont able to find the KEY's. It took me a while what was going wrong. If you launch the firefox as ROOT user or install the KEY's as universal user this issue can be fixed. Once you are in gmail and type the subject you should be able to see the encrypt and decrypt button and when you click the encrypt it should prompt for the public keys. If you are not a privilaged user to access the KEY store you wont see the KEYS.

Friday, May 9, 2008

NYI - Not Yet Implemented error

If you are getting this error

Exception in thread "main" java.lang.RuntimeException: NYI at cryptix.jce.provider.elgamal.ElGamalCipher.engineGetParameters(ElGamalCipher.java:120) at javax.crypto.Cipher.a(DashoA12275)
Reason is the suns default policy doesn't have the strength to encrypt/decrypt with higher strength keys. Got to SUN downloads and install/replace it in you JRE/lib/security Other Downloads Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files 6

Wednesday, May 7, 2008

Formating Currencies and Dates in Struts 2

Create a Global message property so that the formating can be applied to all the pages name it globalMessages.properties

item.listprice = {0,number,$##0.00}
Now add the property to struts.properties
struts.custom.i18n.resources=globalMessages
Now how to Call the formating string in JSP where listprice comes from the stack and the formating string from the global resource we set earlier.
<s:text name="%{getText('item.listprice')}"> <s:param name="value" value="listprice"/> </s:text>
And now the Output
$12.20
Make sure to put the property files in the correct folder of your project.

Monday, April 21, 2008

Another Session Iteration

<s:if test="#session.cartitems.size > 0"> <table> <s:iterator value="#session.cartitems"> <tr id="row_<s:property value="itemid"/>"> <td> <s:property value="itemName" /> </td> <td> <s:property value="listprice" /> </td> <td> <s:url id="removeUrl" action="removeItemFromCart"> <s:param name="itemid" value="itemid" /> </s:url> <s:a href="%{removeUrl}" theme="ajax" targets="basket">Remove</s:a> <s:a id="a_%{id}" theme="ajax" notifyTopics="/edit">Edit</s:a> </td> </tr> </s:iterator> </table> </s:if>

Tuesday, April 1, 2008

Iterating a List Value Struts2

<s:if test=""> 0"> <s:iterator value="#session.categorys"> <li><a href="<s:url action="itemlisthome.action"><s:param name="catalogid" value="#session.catalogs[catalogid-1].id"> <s:param name="categoryid" value="#session.categorys[id-1].id"> </s:url>"> <s:property value="#session.categorys[id-1].name"> </a> </li> </s:iterator> </s:if><s:if test=""> </s:if>

Struts 2 Tips and Tricks

OGNL treats a character in single-quotes as an actual character, not a String. So this statement will not return your desired result.

<s:if test="%{state=='N'}"> This will work. <s:if test="%{state=='NE'}"> </s:if>

Monday, March 24, 2008

File Count in a Folder

Recently I found a command that displays the Number of files in a ls command listing: Code: ls -l | wc -l Above will find the number of files in a directory, and it will send o/p as pipe to the wc -l, which outputs the number of lines in its input. To display all file including hidden and dot files, try Code: ls -lA | wc -l

Friday, March 14, 2008

Stripping white space

s = s.replaceAll(" +", ""); Here is the String BFI NS-16 after the replace BFINS-16

Thursday, February 21, 2008

cat and grep to omit some unwanted pattern on log file

The app I am debugging is toiled by some crappy domain redirecting output. I was looking for a way clear the catalina out file with some decent message. There is nice tutorial logTail Tutorial tailing the log. For there is a part where pattern omition is there,which worked quite well for me.

cat /usr/local/tomcat/logs/catalina.out | grep -v testing | grep -v url | grep -v
Redirecting This will omit the lines starting with testing Redirecting and url

Monday, February 11, 2008

Trendnet WiFI fiasco

When I moved my home I want to setup the wireless hookup in the new home. I was trying to get into the admin console with admin ip 192.168.1.10. For my surprise i am no way able to get in. After searching for while I found out Linksys router my neighbor have the same ip for its router console. I enabled my wifi connection alone and gone to admin console and renamed the router name. after setting up my wep and all I am still not able to get the wireless traffic comming to my computers. Again fiddling around the admin console I found some reason I am not able to release old DHCP address. This is how i released the DHCP. Swithched off the wireless router unplugged the Ethernet. Switched off the cable modem even the power, waited for 10 min. Plugged in the Cable modem powered the modem,waited for all the lights to come in, after three minutes plugged in the Router and powered in the router. At this point connected my router profile on the computer. Aha.. at last I am able to get the wifi. cool.