Friday, 28 December 2012

play2 deploy and config on cloudbees

I did some work recently to update a few web apps from play 1.2.3 to play 2. Some of them are running on heroku and others are on cloudbees.
One of the things I like about heroku is the Procfile that allows you to overwrite the play application.conf properties. But hold on, you can do the same on cloudbees!

Install the bees sdk and try running the following command:

bees config:list [accountname]/[appname]

you should see a list of all the configuration options for your application. Now, lets tweak them a little.
Let's set the runtime db info :

bees config:set -a myaccount/myapp db.default.driver=com.mysql.jdbc.Driver \
db.default.user=mydbuser \
db.default.password=mydbuserpass \
db.default.url=jdbc:mysql://mydbhost:3306/mydbname

Now you can leave your local machine settings in the application.conf file and still pick up the right db at runtime when deployed on cloudbees, isn't that great?

Another thing you might want to change is the smtp settings for your production environment... not problem
bees config:set -a myaccount/myapp smtp.mock=false

This will tell your play2 app to use the other smtp configuration (host, user/pass)
Also if you want to change some of the runtime options (like the java version) use the -R prefix

bees config:set -a myaccount/myapp -Rjava_version=1.7


Now combine that with the play2 sbt plugin for deploying your app and you have a complete suite of tools to get you going!

Friday, 7 December 2012

Escape String literals in eclipse

If you've been using xml literals in your (hopefully only testing) code then you've gone through the pain of escaping the double quotes of all the attributes.

Scala has a great way to handle it using triple - double quotes. In scala this would work fine

val xml = """ <user type="simple"/> """

but if you are stuck with java, then eclipse can escape the string for you..

Go to Window>Preference>Java>Editor>Typing and check the “Escape text when pasting into a string literal

Check this article for some nice screenshots
http://www.vasanth.in/2009/03/10/eclipse-tip-escape-text-when-pasting/


Wednesday, 5 December 2012

back in town

It's been a long time since my last post, but I have a good excuse! I got married to a beautiful woman and I've been off for some time. I managed to see some foreign countries and enjoy a bit of time off.

Also I moved to London!

I enjoy living here, so far so good. There is so much going on. I'm attending as many tech meetups as I possibly can, making the most out of it. The scala group here is great, I went to a few meetups and coding dojos. I also seem to end up in skillsmatter quite often, they have great talks.

So, that being said I am recharged and ready to get back to work!
I'm planning to write some posts about software quality, concurrency and performance on the JVM.

So, don't miss out, stay tuned and follow me on twitter to get the latest updates!



Tuesday, 14 February 2012

eclipse regular expressions find replace

Using regular expressions in eclipse to search and replace text in a file, is straight forward and very handy!
All you need to know is that the matched text is going to be available in the replace textbox using the '$' dollar sign.
So to access the first matched element use $1, for the second $2 and so on.

I had an old method with hundreds of lines doing calling a getAttribute("X") and casting the result to a string.

(String)object1.getAttribute("X")
(String)object2.getAttribute("Y")
(String)objectN.getAttribute("Z")

I had to change them all to use a new method that checks if the attribute is null. So the new line would be

getSafeStringAttribute(object1,"X")
getSafeStringAttribute(object2,"Y")
getSafeStringAttribute(objectN,"Z")

With this simple regEx you can do a replace all!

find : \(String\)(.+)\.getAttribute\("(.+)"\)
replace: getSafeStringAttribute($1,"$2")

The first (.+) will match the objectX part while the second will match the attribute name.

The best thing is that when you select some text and type CTRL + F (if the Regular Expressions checkbox is ticked) you string in the find will be already escaped from characters like '(', ')' etc!




Thursday, 26 January 2012

using play dependencies behind a proxy

It took me some googling and some time to find this


play dependencies --sync --verbose -Dhttp.proxyHost=<your proxy host> -Dhttp.proxyPort=<your proxy port>
and if you get an error like this

Traceback (most recent call last):
  File "C:\programs\play\play-1.2.3\play", line 153, in 
    status = cmdloader.commands[play_command].execute(command=play_command, app=play_app, args=remaining_args, env=play_env, cmdloader=cmdloader)
  File "C:\programs\play\play-1.2.3\framework\pym\play\commands\modulesrepo.py", line 58, in execute
    install(app, args, env)
  File "C:\programs\play\play-1.2.3\framework\pym\play\commands\modulesrepo.py", line 378, in install
    Downloader().retrieve(fetch, archive)
  File "C:\programs\play\play-1.2.3\framework\pym\play\commands\modulesrepo.py", line 88, in retrieve
    try: urllib.urlretrieve(url, destination, self.progress)
  File "C:\programs\play\play-1.2.3\python\lib\urllib.py", line 94, in urlretrieve
    return _urlopener.retrieve(url, filename, reporthook, data)
  File "C:\programs\play\play-1.2.3\python\lib\urllib.py", line 235, in retrieve
    fp = self.open(url, data)
  File "C:\programs\play\play-1.2.3\python\lib\urllib.py", line 198, in open
    return self.open_unknown_proxy(proxy, fullurl, data)
  File "C:\programs\play\play-1.2.3\python\lib\urllib.py", line 217, in open_unknown_proxy
    raise IOError, ('url error', 'invalid proxy for %s' % type, proxy)
IOError: [Errno url error] invalid proxy for http: '<your proxy>:<your port>'
Then try ( in windows )

set http_proxy=http://<your proxy>:<your port>
it seems to want the "http://" prefix...

 Hope this helps!

how to configure your git diff or merge tool

I recently wanted to change the diff setting for git to use diff merge in windows.
So I went googling around and I found a couple of very usefull Q/A on StackOverflow web site.

http://stackoverflow.com/questions/780425/how-do-i-setup-diffmerge-with-msysgit-gitk/783667#783667
In ~/.gitconfig:

[merge]
  tool = diffmerge
[mergetool "diffmerge"]
  cmd = \"C:/Program Files/git/cmd/git-diffmerge-merge.sh\" \"$BASE\" \"$LOCAL\" \"$REMOTE\" \"$MERGED\"
  trustExitCode = false

if you also want to have the diff command using diffmerge then add the following two lines
[diff]
  tool=diffmerge
[difftool "diffmerge"]
  cmd = \"C:/Program Files/SourceGear/Common/DiffMerge/sgdm.exe\"  \"$LOCAL\" \"$REMOTE\"

and use it like this
git difftool <file>
I know it might sound strange to have a .sh extension in windows but, it is not a typo. It's correct.



Created the file C:\Program Files\Git\cmd\git-diffmerge-merge.sh:
#!/bin/sh

localPath="$2"
basePath="$1"
remotePath="$3"
resultPath="$4"

if [ ! -f $basePath ]
then
    basePath="~/diffmerge-empty"
fi

"C:/Program Files/SourceGear/Common/DiffMerge/sgdm.exe" --merge --result="$resultPath" "$localPath" "$basePath" "$remotePath" --title1="Mine" --title2="Merged: $4" --title3="Theirs"

and you're done!