Blogging platform for hackers - Octopress vs Docpad vs Poole

In this post I will walk through my journey of discovering right blogging platform for my site, share my experiences and findings along the way.

When I decided to blog, I researched on next generation blogging platforms for hackers. Mainstream blogging platforms like wordpress, blogger, tumblr are designed for naive users and aren’t best for developers. Because those platforms doesn’t support features programmers would want like code syntax highlighting, theming using frond end frameworks, Markdown language support, integration with source control repositories, etc.

Static site generators:


Continue reading...

How Children Succeed?

This post is about my reflections on the book How Children Succeed which I recently read.

What matters most in a child’s development for them to succeed in life?

We mostly think that intelligent and smart people succeed, i.e success comes to those who score highest in school, college or competitive exams like SAT, GMAT etc. But in How Children Succeed, Paul Tough argues that the qualities that matter more for success are have to do with the character.

In a child’s development, what matters most is not how much information we can stuff into his/her brain in the first few years. But, instead is whether we are able to help him/her develop a very different set of qualities like persistence, self-control, curiosity, conscientiousness, grit, and self-confidence. Infact, possessing these qualities helps a child to get high scores in exams consistently than intelligence alone.

Economists refer to these as noncognitive skills, psychologists call them personality traits, and the rest of us sometimes think of them as character.


Continue reading...

Log4j - Separating log lines to multiple log files.

It’s generally good practise to partition the log lines of your java application into different log files based on functionality/module etc.

For eg. In a web application, we would want application log lines to be logged in to server.log, whereas information about remote user who made the requests to be logged into request.log.

This can be done by defining two appenders in log4j properties and configuring them to output to two different log files.

Here is the example log4j properties.

log4j.rootLogger=INFO,fileAppender

log4j.logger.requestLogger=INFO, requestAppender

##Don't propogate things logged to requestLogger to other appenders
log4j.additivity.requestLogger=false

log4j.appender.fileAppender=org.apache.log4j.RollingFileAppender
log4j.appender.fileAppender.MaxFileSize=500MB
log4j.appender.fileAppender.MaxBackupIndex=10
log4j.appender.fileAppender.Append=true
log4j.appender.fileAppender.File=server.log
log4j.appender.fileAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.fileAppender.layout.ConversionPattern=%d [%t] %-5p (%c %M:%L) %x - %m%n

log4j.appender.requestAppender=org.apache.log4j.RollingFileAppender
log4j.appender.requestAppender.MaxFileSize=1024MB
log4j.appender.requestAppender.MaxBackupIndex=10
log4j.appender.requestAppender.Append=true
log4j.appender.requestAppender.File=requests.log
log4j.appender.requestAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.requestAppender.layout.ConversionPattern=%d [%t] %-5p (%C %M:%L) %x - %m%n

We have defined two appenders, fileAppender to output to server.log and requestAppender to output to requests.log. Only fileAppender is added to rootLogger, so any Logger instances created by passing java class will be logged to server.log.

Example code snippets showing how to log to server.log.

public class RequestProcessor {

    private static final Logger logger = Logger.getLogger(RequestProcessor.class);
    
    private void handleRequest(HttpServletRequest request){
        //This message will be logged to server.log
        logger.info("Processing Request");
    }
}

To log to requests.log the Logger instance should be created passing requestLogger as logger name.

Example code snippets showing how to log to request.log.

public class RequestInterceptor {

    private static final Logger logger = Logger.getLogger("requestLogger"); //Should match name of logger 
    
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //This will be logged to requests.log
        logger.info("Received request from user: " + request.getRemoteUser());
        return true;
    }
}

Continue reading...

Generating Key, CSR and Certificates for SSL

If you want to run your application in HTTPS mode, you will need to get SSL certificates from a valid CA (Certificate Authority) like Verisign.

In this post I will provide steps for generating private key, CSR (Certificate Signing Request) and importing signed certificate back to private key store using java keytool utility


Continue reading...

Spring - Reading values from file and injecting to bean property using SPEL

Sometimes you would need to inject value for spring bean property by reading values from a file. Good use case for this would be injecting passwords into bean property by reading value from a file rather than hard coding password into application context xml.

This can be done by creating property file with values we want to inject and use spring util properties to read values into application context as properties. Then, this property value can be injected using Spring SpEL.

To demonstrate this, lets pick example of initializing Jetty SslContextFactory with keystore file and key store password.


Continue reading...