Sunday, September 14, 2014

Command line java/c/c++ code formatting

One can use eclipse to format java code on command line. Following is the syntax:
eclipse.exe -application org.eclipse.jdt.core.JavaCodeFormatter -verbose  -config

All the files in all subfolders below specified source folder will be formatted.

for example:
eclipse.exe -application org.eclipse.jdt.core.JavaCodeFormatter -verbose  -config .settings/org.eclipse.jdt.core.prefs .\src

I don't remember where I picked it from but I guess it was from
http://blogs.operationaldynamics.com/andrew/software/java-gnome/eclipse-code-format-from-command-line

Also apparently there is a way to format C/C++ code also using eclipse, although I have not tried it.
https://github.com/x8o1Y/EclipseCCodeFormatter

Wednesday, August 13, 2014

How to add ssl certificate from StartCom in Grails

StartCom provide free SSL/TLS certificate for you website that is valid for a year. This certificate is good enough to get going with SSL without warning etc.

Part1) get the certificate from StartCom
How to get a free certificate from StartCom?
1) visit https://www.startssl.com/?app=12
2) Click on express lane.
3) Supply the info to get your email address verified
4) Verify the email address, it will install a certificate in your browser.
5) Now visit https://www.startssl.com/?app=12 again and go to authneticate
6) Now go to Certificate Wizard and follow the instructions for getting Web Server SSL/TLS Certificate.
7) I opted for generating the the private key file from StartCom to make my life easier. It created a private key text that I saved as file mydomain.key and then they generated certificate for my domain  that I saved as mydomain.crt. Be careful about saving the private key text since I don't think you can retrieve that later. The certificate you can retrieve later also.

Part2) Create java key store file
1) create a pkcs12 file: You need to create a pkcs12 file using the private key and certificate. You can use the following command:
 openssl pkcs12 -export -inkey mydomain.key -in mydomain.crt -name mydomain_name -out mydomain.p12
It will ask for password, supply your favorite password. For simplicity I used the same password everywhere. StartCom also provides a tool to create this pkcs12 file under tools sections.

 2) Create a java keystore file: You can use keytool or you cal use kse (http://keystore-explorer.sourceforge.net/) GUI. Open the pk12 file in kse and change the type (Tools/Change Type/JKS). Then right click on the only entery you have and set password to your favorite password as above. The save this file as one with jks extension.

Part 3) To install this file in grails, 
add these two entries in conf/BuildConfig.groovy
grails.tomcat.keystorePath = "full file path of .jks file"
grails.tomcat.keystorePassword = "your password"

Saturday, June 28, 2014

Grails: How to provide tcp connection from outside to an embedded H2 database?

Step 1) Create web.xml configuration by executing:
grails create-web-xml-config
Step 2) Make this change in WebXmlConfig.groovy
listener.add = true
Step 3) Add a listener in WebXmlConfig.groovy:
listener.classNames = ["org.h2.server.web.DbStarter"]
Step 4) Add following line in WebXmlConfig.groovy:
contextparams = ["db.tcpServer": '-tcpAllowOthers']

Restart grails app now. H2 db should be accessible at port 9092.

Wednesday, April 9, 2014

How to use IR remote control with Camera

If your camera has IR remote control reception feature built in then you can use an IR remote control to take pictures. The advantage is that you won't touch the camera and it won't vibrate. Thus it might give better oicture
First it to find out how to activate IR remote control in the camera. Typically there is a setting along with timer. In my Nikon D5300, there is a button on left hand side just below the lens release button. Pressing it few times activates remote control feature.There are two setting for remote control, one enables instant shot and other enables shoot with 2 sec delay.

Also the remote is most likely to work from in front of the camera. After activating the remote control just go in front of the camera and press the key on your remote control. That's it.

Don't forget to say cheese.

Monday, February 24, 2014

How to get media files from whatsapp?

Recently a friend send a video recording to me through whatsapp on IPhone 5s. I wanted to take that file out and put on my dlna server but could not find an easy way to get these files out of whatsapp without paying for some app.

After doing some research I decided to jailbreak the phone and install ssh server on the phone. I found that the its fairly easy to get the files once I have shell access :)

Steps:
Go into this folder:
/private/var/mobile/Applications/

Execute the following command:
find . -name ChatStorage.sqlite

This will give the location of ChatStorage.sqlite . In my case it is at :
/private/var/mobile/Applications/78493F8B-6A56-4CBD-9B03-7855B216A33B/Documents/
Whatsapp media files are stored under Library folder in application's folder identified by a large GUID sepcific to each application. Each peer's media files are in a separate folder (identified by his account id for whatsapp) as shown below:
/private/var/mobile/Applications/78493F8B-6A56-4CBD-9B03-7855B216A33B/Library/Media/14045551234@s.whatsapp.net
You there are many folder under this folder. You can list them using:
find   .            #the dot is important
One you know where the file is you can scp it. You can even scp the whole library on your PC and then figure out which is which.