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.
Cheers

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

// GETTING ATTIRIBUTE NAME AND VALUES IN KSOAP2
        for (int i = 0; i < yourSoapObject.getAttributeCount(); i++)
        {
            AttributeInfo attInfo = new AttributeInfo();
            yourSoapObject.getAttributeInfo(i, attInfo);
            String attributeName = attInfo.name;
            String attributeValue = yourSoapObject.getAttribute(i).toString();
          }

 // GETTING PROPERTY NAME AND VALUES IN KSOAP2
            for (int i = 0; i < yourSoapObject.getPropertyCount(); i++)
            {

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

Cheers
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

   
INSERT IGNORE INTO `candidates`
   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('\\');
}
if(Character.isWhitespace(c))
{
sb.append(" \\ ");
}
sb.append(c);
}
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 :
URIUtil.encodeQuery(String)

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 org.springframework.web.servlet.support.WebContentGenerator 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 />
<mvc:interceptors>
<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">
<props>
<prop key="/**/*.html">2000</prop>
<prop key="/**/*.css">500000</prop>
<prop key="/**/*.js">2592000</prop>
</props>
</property>
</bean>
</mvc:interceptors>

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"
connectionTimeout="20000"
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"
compression="on"
compressionMinSize="2048"
noCompressionUserAgents="gozilla, traviata"
compressableMimeType="text/html,text/xml,application/json">


Make sure you add the MIME Type which you want to add compression as follows
compressableMimeType="text/html,text/xml,application/json"

# 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:

@Override
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);
generator.flush();

if (prefixJson)
{
generator.writeRaw(");");
generator.flush();
}
}

and make sure you put entry in your servlet.xml file
<property name="defaultViews">
<list>
<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 https://github.com/robertpenner/as3-signals/wiki/

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);
//later:
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