Sunday, January 3, 2016

Jasper Localization From Property File:Encoding Issue

Recently In a Project I used Jasper to generate PDF forms.While doing this task I encountered a problem with Localization of Jasper Fields from Property Files.

Normally we include below attribute in JRXML header to point to localization files.

Localization files will be in same folder where JRXML is placed and localization files will be in below format.
  • etc
And each file will have key value pair like Date Date

and it will be used in JRXML in below format

and Localization is passed to JRXML in below format
 parameterMap.put(JRParameter.REPORT_LOCALE, new Locale("th"));
Encoding Issue:

When I generated the PDF for Thai language the output was a bunch of junk values.

The problem is resource bundle reads the property files in ASCII encoding even though property file is encoded in UTF-8


Remove the resourcebundle attribute from JRXML and configure it in Java class with UTF-8 Encoding.

  InputStream input = this.getClass().getClassLoader().getResourceAsStream("jasperreport_"+locale.getLanguage()+ ".properties");
  Reader reader = new InputStreamReader(input, "UTF-8");
  ResourceBundle resourceBundle = new PropertyResourceBundle(reader);
 catch (IOException  e1) 
  LOG.error("Error locating localize file ",e1);

Sunday, September 27, 2015

Your own Broken Link Checker

Python Script : Crawl a website ,take screenshots and save it in word doc.

Steps to execute this script
  1. Create a folder 'link Checker' and place this script in it.
  2. Create a folder 'shots' and place it inside  'link Checker' folder.
  3. Change below variables 
    • url ="website url"
    • SaveDirectory=r ''screenshot directory"
  4. Execute the program.

 import requests  
 from BeautifulSoup import BeautifulSoup  
 import webbrowser  
 import os  
 import sys  
 import time  
 import Image  
 import ImageGrab  
 import win32com.client as win32  
 import os  
 import time  
 import glob  
 url = ""  
 response = requests.get(url)  
 # parse html  
 page = str(BeautifulSoup(response.content))  
 alllist = [];  
 httplist = [];  
 otherlist = [];  
 SaveDirectory=r'C:\Users\Giridhar\Desktop\link Checker\shots'  
 def getURL(page):  
   :param page: html of web page (here: Python home page)   
   :return: urls in that page   
   start_link = page.find("a href")  
   if start_link == -1:  
     return None, 0  
   start_quote = page.find('"', start_link)  
   end_quote = page.find('"', start_quote + 1)  
   url = page[start_quote + 1: end_quote]  
   return url, end_quote  
 while True:  
   url, n = getURL(page)  
   page = page[n:]  
   if url:  
     #print url  
 #print alllist  
 for httpurl in alllist:    
   if httpurl.find("http")!=-1:  
     if httpurl.endswith("/",0,1):  
 #print httplist  
 #print otherlist  
 new = 0  
 for browsing in httplist:  
   print browsing  
   i += 1  
   if i == 10:  
 #---------------------------------code to move images to word-------  
 allpics = []  
 wordApp = win32.gencache.EnsureDispatch('Word.Application') #create a word application object  
 wordApp.Visible = False # hide the word application  
 doc = wordApp.Documents.Add() # create a new application  
 for pic in allpics:  
   current_pic = doc.InlineShapes.AddPicture(pic)  
   current_pic.Height= 400  
   current_pic.Width= 400  

After execution of script ,it will automatically open the default browser and crawl all the pages it in and takes screenshot of all pages.

Once done with the screenshots it will create a doc file with all screenshots in it.

Wednesday, February 18, 2015

What is the quickest traffic strategy to get traffic to your blog?

Quickest strategies will only work for a short period (A day or two).
Below strategy will help you to get huge traffic in very short duration and for a very short time.
Mantra: Target on NARROW LOCAL HOT topics.

Eg: Keep an eye on local exam results like GATE/IIT/JNTU/10th etc
I will explain taking JNTU as an example. You can apply same concept to other topics as well
 Do you know how many hits a JNTU website gets during semester results?

According to Alexa, JNTU website will get 40K hits during semester results. 
 Do you know how users reach JNTU results webpage?

Yup they Google it.
Now here is the tricky part .What if Google shows your blog as the first result when user search for "jntu results". YOU WILL GET 40K visits in a single day.

Friday, October 24, 2014

Control Remote Car with Keyboard

I got bored with software projects and thought of doing something different which I never tried. I've  always been fascinated by robots and have a dream of building one.This small baby step project helped me to understand the various concepts of Electronics.

Beam Fiber Auto Login using python script


  • Login to BeamFiber without opening web GUI
  • After Successful login it will send public IP address via mail to address mentioned in 'To' attribute.

Python Code

Saturday, August 24, 2013

Resolved:unable to bind listener to any port in the range 32000 to 32999

 I got this error when i tried to install e commerce software on raspberry pi.

Error : unable to bind listener to any port in the range 32000 to 32999. (Cannot assign requested address)

Java Service Wrapper Community Edition 32-bit 3.5.20
  Copyright (C) 1999-2013 Tanuki Software, Ltd. All Rights Reserved.
 unable to bind listener to any port in the range 32000 to 32999. (Cannot assign requested address)
<-- span="" stopped="" wrapper="">

Solution :

First check whether any other application is LISTENING on the port range which you have given by using below command

sudo netstat -an|less

output :

Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0  *               LISTEN
tcp        0      0 *               LISTEN
tcp        0      0  *               LISTEN
tcp        0      0  *               LISTEN
tcp        0      0  *               LISTEN
tcp        0      0  *               LISTEN
tcp        0      0 *               LISTEN
tcp        0      0    *               LISTEN

Make sure that the no other application is listening on ports from 32000 to 32999.If any then change your application min and max port in wrapper.conf file


Still if you face same error then add below line to wrapper.config file


This configuration  allow you to avoid using sockets and use pipes instead to get around this problem.

"wrapper.backend.type=PIPE"  solved my problem

Tuesday, August 20, 2013

Raspberry Pi Quick Guide

Below are some basic commands which you need to know to PLAY with raspberry pi

How to install softwares/packages in raspberry pi ?
sudo apt-get install packagename

How to remove softwares/packages in raspberry pi ?
sudo apt-get --purge remove

How to update/upgrade raspberry pi

sudo apt-get update && sudo apt-get upgrade

How to go to GUI mode in raspberry pi ?

How to give root access to pi ?
sudo su

How to see all packages installed in raspberry pi?
dpkg -l
How to change password/memory split /time in raspberry pi?
sudo raspi-config

How to see list of devices attached to raspberry pi?
df -h

How to see all services in raspberry pi ?
service  --status-all

How to stop any service in raspberry pi ?
service mysql stop

How to Disabe unwanted services in raspberry pi? 
update-rc.d  mysql disable
How to keep raspberry pi up to date? 
    Install software needed to perform the update:
        pi@raspberrypi:~$ sudo apt-get install ca-certificates git-core binutils
    Download the script:
        pi@raspberrypi:~$ sudo wget
    Copy the script to /usr/local/bin:
        pi@raspberrypi:~$ sudo cp rpi-update /usr/local/bin/rpi-update
    Make the script executable:
        pi@raspberrypi:~$ sudo chmod +x /usr/local/bin/rpi-update
    Run the script:
        pi@raspberrypi:~$ sudo rpi-update
        In the future to check for updates, just execute this last step!

How to Change owner/Group in raspberry pi?
chown -R pi
chgrp  -R pi

How to see what all ports are bind in raspberry pi ?
sudo netstat -an|less