Minimum Viable Product – a definiation

Over the past couple of weeks I’ve been lecturing at UK universities giving a practical overview of how we use the Minimum Viable Product (MVP) approach at Next Jump. I like Eric Reis’ definition but it doesn’t quite describe how the MVP process works for us in practice, so I thought I’d share how I described it:

The Minimum Viable Product is one which only allows features that are absolutely required, to be released to a population of real users from which measures of success and failure can be observed, feedback gathered and iterative improvements made.

They key concepts are:

  • The Minimum number of features, and the minimum is probably fewer that you think.
  • Measurable results, which enable you to statistically analyse and quantify performance of iterations.
  • User feedback, which gives you a true insight into how users are interacting with your product, what works and what doesn’t.
  • An Iterative Process, as without iterations your product will never move from minimum viability towards an optimal solution.

Accessing Commission Junction’s API with Java

I couldn’t find a good example of how to connect to the CJ API with Java, so here is stripped down version of how I did it:

import java.net.*;
import java.io.*;
 
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
 
import org.w3c.dom.Document;
 
...
 
public static Document getCommissionDetail(String startDate, String endDate){
    String response = "";
    String devKey = "YOUR-DEV-KEY";
    Document doc = null;
    String urlPath = "https://commission-detail.api.cj.com/v3/commissions?date-type=event&start-date=" + startDate + "&end-date=" + endDate;
 
      try {
        URL u = new URL(url);
        URLConnection uc = u.openConnection();
        HttpURLConnection connection = (HttpURLConnection) uc;
        connection.setRequestMethod("GET");
        connection.setRequestProperty("Authorization", devKey) ;
        connection.setRequestProperty("Content-Type","text/xml");
        connection.setDoInput(true);
 
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder db = dbf.newDocumentBuilder();
        doc = db.parse(connection.getInputStream());
        doc.getDocumentElement().normalize();
 
      }
      catch (IOException e) {
        //Something went wrong with the request
      }
      catch (Exception e) {
        //Something went wrong, very wrong
      }
    return doc;
}

Leave a comment if you find it useful or use it in a project!

Fast Plist Creation in PHP

When we originally designed the BeerMap API we decided to provide the data in a plist format, along with json and XML.

The plist format isn’t widely used for APIs, however iOS provides efficient inbuilt parsing of this file type and we also found this to be much easier to implement in terms of code complexity.

For example, you can just do this:

NSDictionary* dict = [NSDictionary dictionaryWithContentsOfURL:[NSURL URLWithString:@"http://www.example.com/data.plist"]];

For the past two years we’ve used the CFPropertyList library which in my opinion is the best and most functional library for reading and writing plist files in PHP.

If you find issues, please post on Github, or even better, fork and create a pull request!

However, in BeerMap we just need to create and output plists as fast as we can without any need to read or represent them in an object format. Looking at the xdebug output for the BeerMap API it became evident that the plist creation was by far the biggest bottleneck, mostly because of the XML object representation.

So, in summary I’ve created a quick class which just generates an XML string from an associative array instead of using XML objects. From my testing using ab, I was getting almost twice the number of request per second.

You can find the code at Github – https://github.com/paulbain/Bain-PHP-Library where I’ve started a library in the Zend Framework layout.

Here’s an example of how to use it:

require_once 'Plist.php';
 
//Get some data in an associative array
$data = array(
	'reviews'=>; array(
        array('title'=>;'My Review','comment'=>;'It\'s awesome','rating'=>;5)
    )
);
// Specifiy types for any non-string named keys
$types = array(
    'rating'=>;'real'
);
 
//Create the Plist
$plist = new Bain_Plist($data,null,$types);
 
//Output the plist! (Maybe you'll need an XML header)
echo $plist;

If you’re using the Zend Framework auto loader, just place the library in your path and register the namespace:

$autoloader = Zend_Loader_Autoloader::getInstance();
$autoloader->;registerNamespace('Bain_');

If you use this in a project leave a comment!

Speeding up CURL Requests in PHP

Recently I’ve been working with an extremely data intensive flight API which takes several seconds to process a response and up to 60 seconds to transfer the data.

Unfortunately there is no way to reduce the amount of content in the response which would have been the best optimisation. A good hint in cases like these is to try to get the server to compress the content. Using one simple CURL option I was able to speed up each request by around 40 seconds, extremely satisfying!

curl_setopt($curl,CURLOPT_ENCODING,'gzip');

If you’re actually creating the API using PHP, you may want to look at tweaking your php.ini settings to make sure zlib output compression is enabled.
You can also play with the output compression level, with 1 being the lowest and 9 the highest. Be careful however as a higher level of compression may result in high server load.

zlib.output_compression = On
zlib.output_compression_level = 6

EasyTube Plugin Updated

I’ve just released an update to EasyTube which is my most popular WordPress plugin that allows people to embed YouTube videos in posts and pages using a single tag.

Version 1.7 update includes:

  • Multiple bug fixes including a major problem with video sizes
  • Addition of new widescreen video formats
  • Updated embed to include the fullscreen option

For more information visit the WordPress.org.

Pay What You Want iPhone Business Model

Apple recently updated their SDK allowing developers to integrate in-app purchases into free applications opening up a whole new world of possibilities.

BeerMap, one of the projects I’m currently involved with is a free iPhone app which we have always intended to monetise once it reached maturity. We’ve recently started to discuss charging in iTunes however it gave us a few concerns:

  1. The application relies on user collaboration in order to generate data, charging for the application would probably reduce the uptake by new users.
  2. The application will take some time to reach maturity and is dependant on the feedback of our loyal user base.

We therefore have resisted charging for the app and instead have begun to investigate other avenues.

Last Saturday was a BeerMap development day during which we discussed the possibility of monetisation using in-app purchases and we think we may have come up with a novel solution; Pay What You Want.

Pay What You Want is not a new concept; in 2007 Radiohead allowed music lovers to download their new album and choose how much they want to pay. More recently 2D Boy used the same model when celebrating the first birthday of World of Goo, achieving a large number of sales and yielding a surprising profit.

Combining pay what you want and in-app purchase capability in BeerMap would allow users to decide whether they want to pay for the app or not! Apple provides payment tiers to which we will be limited so it won’t be 100% pay what you want, however these represent reasonable prices which users will be familiar with.

We plan to incentivise payment, potentially by giving the user access to extra features or awarding them recognition within the BeerMap community.

We hope this model will ensure we don’t scare off new users who don’t want to and will never want to pay, while providing people with the option to support the project and to show appreciation for our work.

Image credit: Alex Osterwalder

Snow Leopard, Zend Framework and MySQLi Problem

I spent a good hour banging my head against the desk this evening trying to work out why Zend Framework row objects have stopped working after upgrading to Snow Leopard and installing the new iPhone SDK.

I traced all the way though to the Zend_Db_Statement_Mysqli class which giving the following error:

Warning: Parameter 2 to mysqli_stmt::bind_param() expected to be a reference, value given in Zend/Db/Statement/Mysqli.php on line 205

I was half way installing the macports PHP package when I thought I should probably try a different adapter which worked! So if you’re having difficulties, try the PDO_MYSQL driver instead.

HowTO: Draggabe JFrame Without Decoration

I was playing with writing a quick time tracking application called Efficiency which needed to be always ontop of other windows and therefore be a subtle as possible. I therefore decided to undecorate the window, however the user is then unable to reposition the window, so I wrote a some code to quickly allow them to do this by just dragging the JFrame.

My class extends the javax.swing.JFrame class, so I’ve set a few properties in the initComponents() function and more importantly added listeners for MousePressed and MouseDragged.

    private void initComponents() {
        ...
        setAlwaysOnTop(true);
        setBackground(new java.awt.Color(0, 0, 0));
        setResizable(false);
        setUndecorated(true);
        addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                formMousePressed(evt);
            }
        });
        addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseDragged(java.awt.event.MouseEvent evt) {
                formMouseDragged(evt);
            }
        });
        ...
    }

Firing an action on mousePressed is required to get the original location of the window. This fires the following function, setting the two variables which are of type java.awt.Point:

    private void formMousePressed(java.awt.event.MouseEvent evt) {
        this.start_drag = this.getScreenLocation(evt);
        this.start_loc = this.getLocation();
    }

The mouse dragged function is as follows:

    private void formMouseDragged(java.awt.event.MouseEvent evt) {
            Point current = this.getScreenLocation(evt);
    Point offset = new Point((int) current.getX() - (int) start_drag.getX(),
        (int) current.getY() - (int) start_drag.getY());

    Point new_location = new Point(
        (int) (this.start_loc.getX() + offset.getX()), (int) (this.start_loc
            .getY() + offset.getY()));
        this.setLocation(new_location);
    }

You’ll also need the utilty funciton to convert the points to a screen location:

      Point getScreenLocation(MouseEvent e) {
        Point cursor = e.getPoint();
        Point target_location = this.getLocationOnScreen();
        return new Point((int) (target_location.getX() + cursor.getX()),
            (int) (target_location.getY() + cursor.getY()));
      }

Reference

  • Drag and Move – material from java2s.com used as a basis but using an external MoveMouseListner class

Photo Credit: dongga BS

Inserting Default Content into the WordPress Visual Editor

I’ve been working on a WordPress layout which needs two columns of user editable content per page. There are many ways you could do this with WordPress, however to make it as easy as possible for the content editors I though it would be easier if the visual editor had some default layout information inserted when creating a post.

I knew there must be an easy way to do this using the action API in WordPress and I came across this article by WPRecipies which suggests putting the following code in the functions.php of your theme:

add_filter( 'default_content', 'my_editor_content' );
function my_editor_content( $content ) {
$content = "If you enjoyed this post, make sure to subscribe to my rss feed.";
return $content;
}

I inserted a couple of divs for the columns into mine so I also wanted to add some basic styling to the editor. I know this probably isn’t the best way and I’m sure someone will correct me, but I just added the style to the end of the TinyMCE stylesheet which can be found here in /wp-includes/js/tinymce/themes/advanced/skins/wp_theme/content.css

EDIT: you can do this for custom post types too, just change the “myposttype” to be set to your type:

add_filter( 'default_content', 'my_editor_content' );
function my_editor_content( $content) {
    global $post_type;
    if($post_type=='myposttype'){
        $content .= "If you enjoyed this post, make sure to subscribe to my rss feed.";
    }
    return $content;
}