Pages

Reading RSS Feed in Groovy

The more I explore, the more I love groovy. Last week while I was demonstrating a few colleagues of mine, that how simple things are really dead-simple in groovy, I wrote this small code that fetches the rss feed and prints the headlines. Just thought of sharing with all.
// setup proxy, if any
System.properties.putAll(["http.proxyHost":"your.proxy", "http.proxyPort":"8080"])             

// define the url, change it to whatever rss url you like
def url = "http://news.google.com/news?ned=us&topic=h&output=rss"

def rss = new XmlSlurper().parse(url) 

println rss.channel.title
rss.channel.item.each {
    println "- ${it.title}"
}
That's it! You have headlines in your output. How can you not love the brevity yet expressiveness of this code:)

ASCII Art Editor in Java

I am Huge fan of README files. When looking at any new library/software, I would at least skim through a README once, if not gulp it thoroughly. So I was writing a README for my project yesterday. I wanted to have a simple diagram in the readme, but it was getting sorta complex to do that with Notepad++, Netbeans or Eclipse. I have always wondered how people make nice ASCII Art Logos (I found that 'it' is called so after some google searches) and diagrams in Text Files.

Anyways, so I found out this cool ASCII Art Editor in java called JavE. And it really helped me to create the desired diagram in the text file. Bonus: I came to know how to create ASCII Banners as well. You have to download optional FIGlet fonts (available on the same website) to create text banners like this one.
 
   _   _      _ _        __        __         _     _
  | | | | ___| | | ___   \ \      / /__  _ __| | __| |
  | |_| |/ _ \ | |/ _ \   \ \ /\ / / _ \| '__| |/ _` |
  |  _  |  __/ | | (_) |   \ V  V / (_) | |  | | (_| |
  |_| |_|\___|_|_|\___/     \_/\_/ \___/|_|  |_|\__,_|

Groovy substring

Can't imagine any terser way of doing this than

println "teststring"[4..6]

Ain't it groovy :)

Netbeans not allowing to create project on windows

At times Netbeans does not allow you to create projects in some directories (on windows). I searched a lot but could not find any reasonable explanation for why windows turns some folders as read only. Anyways, run the following commands on those directories in which Netbeans is not letting you create the project.

Go to the command prompt and, issue
>attrib -r -s c:\some\directory
>attrib -r -s c:\other\directory

This removes the read only status.

Script to enable/disable proxy


To Enable Proxy
EnablePorxy.vbs

set shell = Wscript.CreateObject("Wscript.Shell")
shell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable", 0, "REG_DWORD"


To disable Proxy
DisablePorxy.vbs

set shell = Wscript.CreateObject("Wscript.Shell")
shell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable", 1, "REG_DWORD"


Maven: multiple builds from cmd file

This is just a followup on/refinement of my previous post. This cmd/bat Script focuses on clean-build-installing multiple projects from a single script. This script halts at the first build failure. If you happen to run from window explorer by doble clicking the script, In case of error the command window stays open (Press any key to continue). If ever build was successful, the window closes automatically. In the following example, I am skipping the test execution for third project you can add/remove -DskipTests=true to any mvn calls.

REM Uncomment following if you want to clean local repo on each run
REM rmdir /S /Q "%HOMEPATH%\.m2\repository\com\mygroup\id"

call mvn -f ProjectA\pom.xml clean install
if not "%ERRORLEVEL%" == "0" goto error

call mvn -f ProjectB\pom.xml clean install
if not "%ERRORLEVEL%" == "0" goto error

call mvn -DskipTests=true -f ProjectC\pom.xml clean install
if not "%ERRORLEVEL%" == "0" goto error

exit

:error
@echo Build Failed
pause


Hope you find this helpful.

Reference:
This  question at SO helped.

Calling multiple bat files from a bat file

Earlier I had posted about closing command window that is left open after executing a bat file. This post is about calling multiple bat files from a bat file.

Today, while trying to execute multiple maven builds from a bat file, I observed that only first build one was called and once the first build was over, the execution stopped. Next builds were not called at all. I Did some search and found this. Yeah mvn command is a bat file, I knew that. What i missed was putting a call before the mvn commands:

cd ProjectA
call mvn install
cd ..

cd ProjectB
call mvn install
cd ..


The post linked above goes one level further by checking the %ERRORLEVEL% and exiting the script if any any build fails.

So lesson learnt today :
If you need to call multiple bat files from a bat file, start each bat command with a call