Thursday, July 12, 2012

Interactive Charts in Andriod with Crosshairs and Data ToolTip

Interactive Charts in Andriod with Crosshairs and Data ToolTip

Making interactive chart on andriod is a tricky buisness , i had to face a lots of issues in one of my recent project to show interactive charts with crosshairs and data on crosshairs.
When i started with the project i used achartengine library which had lots of inbuilt charts , but it lacked crosshairs and user interactivity.
Then i started looking a afreechart, its a andriod version of jfreechart which had crosshairs in it, but it do not have developer guide as that is paid but it supported what i needed.

Here are the screenshots of data interactive charts in my application.

I would love to help if some body get struck on the same like i did as its very annoying.

Varun Rathore

Friday, July 6, 2012

Ksoap2 Getting Values of Property or Attribute in Andriod

Hi All,

You can get the values and names of Attibutes and Properties in Ksoap2 SoapObject

        for (int i = 0; i < yourSoapObject.getAttributeCount(); i++)
            AttributeInfo attInfo = new AttributeInfo();
            yourSoapObject.getAttributeInfo(i, attInfo);
            String attributeName =;
            String attributeValue = yourSoapObject.getAttribute(i).toString();

            for (int i = 0; i < yourSoapObject.getPropertyCount(); i++)

                PropertyInfo attInfo = new PropertyInfo();
                yourSoapObject.getPropertyInfo(i, attInfo);
                String propertyName =;
                String propertyValue = yourSoapObject.getProperty(i).toString();

Varun Rathore           


Tuesday, May 8, 2012

MySql Inserting Distinct Values in Table

Way 1 -  using REPLACE

REPLACE INTO `candidates`
    SET `candidate_id` = '000000146',
    `candidate_name` = 12345,
    `candidate_rollnumber` = 12678;
If the record exists, it will be overwritten; if it does not yet exist, it will be created.

Way 2 -  using INSERT IGNORE

   SET `candidate_id` = '000000146',
    `candidate_name` = 12345,
    `candidate_rollnumber` = 12678;

Here, if the 'candidate_id' is already present in the database, it will be silently skipped (ignored).

- Varun Rathore

Sunday, April 29, 2012

Day of Month Suffix - st nd rd th

Here is a simple way to put suffix for day

String getDayOfMonthSuffix(final int n)
 checkArgument(n >= 1 && n <= 31), "illegal day of month: " + n);
 if (n >= 11 && n <= 13)
return "th";
 switch (n % 10)
 case 1: return "st";
case 2: return "nd";
 case 3: return "rd";
default: return "th";

Thursday, September 29, 2011

Escaping Special Characters And White Space in SOLR in java

Escape Special characters in SOLR before Query
here is the function to escape the culprits

public static String escapeQueryCulprits(String s)
StringBuilder sb = new StringBuilder();
for (int i = 0; i < s.length(); i++)
char c = s.charAt(i);
// These characters are part of the query syntax and must be escaped
if (c == '\\' || c == '+' || c == '-' || c == '!' || c == '(' || c == ')' || c == ':'
|| c == '^' || c == '[' || c == ']' || c == '\"' || c == '{' || c == '}' || c == '~'
|| c == '*' || c == '?' || c == '|' || c == '&' || c == ';'
sb.append(" \\ ");
return sb.toString();

Wednesday, September 21, 2011

A partial block (3 of 4 bytes) was dropped in Base64 String

When you face such a issue just use

Flex :
encodeURIComponent(String) in flex

Java :

Before posting the string in Browser as "=" and "&" in the String create issue while decoding String.

Thursday, June 30, 2011

Response Header with MVC interceptors in Spring

Response Header's in Spring can be easily set using as this is a abstract class so we use a direct known sub class for the same which is org.springframework.web.servlet.mvc.WebContentInterceptor , this Interceptor checks and prepares request and response. Checks for supported methods and a required session, and applies the specified number of cache seconds.

Here is the Example, this should be under beans tag in your server-config.xml file

<mvc:annotation-driven />
<bean id="webContentInterceptor" class="org.springframework.web.servlet.mvc.WebContentInterceptor">
<property name="cacheSeconds" value="120"/>
<property name="useExpiresHeader" value="true"/>
<property name="useCacheControlHeader" value="true"/>
<property name="requireSession" value="false"/>
<property name="useCacheControlNoStore" value="true" />
<property name="cacheMappings">
<prop key="/**/*.html">2000</prop>
<prop key="/**/*.css">500000</prop>
<prop key="/**/*.js">2592000</prop>

In CacheMapping attribute we can specify the cache time for different file types, as this increases the preformance of application.

Gzip in Apache Tomcat - Faster Responses with Compression

Today's Browser have capability to support gzip content and uncompressed the content to plain text. The data comes from server to client in a compressed form with increases the performance many times as less data get transfered on network.

Just go to Tomcat/conf/Server.xml file and replace the default node

<Connector port="8080" protocol="HTTP/1.1"
redirectPort="8443" >

with follwing

<Connector port="8080" maxHttpHeaderSize="8192"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
connectionTimeout="20000" disableUploadTimeout="true"
noCompressionUserAgents="gozilla, traviata"

Make sure you add the MIME Type which you want to add compression as follows

# Tomcat handles the compression for the supporting brorwers and do not compress response in case the browser is from monolithic age :)

- Varun Rathore

Tuesday, June 21, 2011

PJson in Spring using JacksonJson (Cross Domain Issues)

We can create pjson (json with padding) to achieve cross domain java-script call which is very important if data is coming from other domain.

Here is what i did to get pjson from object.
I created a class MappingJacksonJsonpView extended it by AbstractView, now here is the trick
I overrided a method renderMergedOutputModel as follows:

protected void renderMergedOutputModel(Map model, HttpServletRequest request, HttpServletResponse response) throws Exception
Object value = filterModel(model);
JsonGenerator generator = objectMapper.getJsonFactory().createJsonGenerator(response.getOutputStream(), encoding);
String callback = request.getParameter("jsoncallback");
prefixJson = false;
if (callback!=null)
prefixJson = true;
if (prefixJson)
generator.writeRaw(callback + "(");
objectMapper.writeValue(generator, value);

if (prefixJson)

and make sure you put entry in your servlet.xml file
<property name="defaultViews">
<bean class="com.views.utility.MappingJacksonJsonpView" />

Thursday, May 26, 2011

AS3 Signals - Faster Messages in AS3

AS3 signals are free , very fast and relaible messaging tool, i have been using them from last 6 months , below are some features of Signals which are more superior than Events

Dowload it from

Signal's Salient Features

Remove all event listeners : signal.removeAll();

Retrieve the number of listeners : signal.numListeners

Listeners can be added for a one-time call and removed automatically on dispatch:

signal.addOnce(theListener); // result: signal has one listener
signal.dispatch(theEvent); // result: theListener is called, signal now has no listeners

A Signal can be initialized with value classes that will validate value objects on dispatch (optional):

// A Signal that will dispatch a String and an integer:
progress = new Signal(String, int);
progress.dispatch(); // will throw ArgumentError
progress.dispatch('The Answer'); // will throw ArgumentError
progress.dispatch('The Answer', 42.5); // will throw ArgumentError
progress.dispatch('The Answer', 42); // will succeed

Varun Rathore

About Me