Pages

Monday 8 September 2014

Why You Need To Build Opinionated Products

Any product worth its salt was built for one of two reasons. The first reason is more evident and intuitive to understand - fulfilling a need. Picasa made online picture sharing and storage a piece of cake just when users around the world were struggling with limited email attachment size to send photographs to friends and family. The second bucket of products create the need in a bid to then make the product an indispensable part of their users' lives. Nobody had a sudden urge in the middle of the night to write about pickled lemons in 140 characters or less. Twitter created that need.

Products always start out with a vision - a plan and a purpose - yet it is fairly common to see them change course and meander off into an unintended path. And that's okay. That's okay provided the new, end-product is a derivative of your opinion, your reading of usage and your vision. Product folks often make the mistake of listening to all their users, especially ones with conflicting usage patterns, leading to pages and pages of knobs and settings. An interesting analogy can be drawn between products and rivers. As long as both power through one path, they are strong and booming. The path may deviate from the originally intended course, but if everything holds together, the river will meet the ocean at full capacity, just as the product will hit users with the same force. A product with a hundred different configurations is, however, like a river with a hundred tiny distributaries - each is weak, sluggish and in a lot of cases, may die out before meeting the ocean.

Non-opinionated products are riddled with settings and configurations. They do not define the 'golden path' that they want their users to follow but leave most of the of flexibility to its users. Users are expected to turn knobs and dials to reach a product state that they believe fits their need and then find value in the product. The problem with this approach is that no product is optimized for every permutation of its settings. The chosen permutation may be lacking in a lot of functionality and leaves the user wanting more. Satisfying this need leads to the introduction of more settings in the product to support the 'distributary'. It is indeed a vicious circle and no product person wants to be in that state - after all, every setting turned on or off makes for a different product, and maintaining all those products leads one down an endless rabbit hole.

Leave out the fluff. Kill all those settings. Build opinionated products. 

Proponents of non-opinionated software often claim that it is arrogant for product to ignore feature requests and that software should be as flexible as possible. Here's what 37Signals, now Basecamp, had to say about that in an article:
We think that's bullshit. The best software has a vision. The best software takes sides. When someone uses software, they're not just looking for features, they're looking for an approach. They're looking for a vision. Decide what your vision is and run with it.

Building opinionated software does not mean you are not listening to your users. It does not mean you disregard any feedback that comes your way or turn a blind eye to popular usage trends. It means listening to them to find out their biggest points of friction, focusing on the problems your product intended to solve all along and providing that must-have experience for users. 

Saying 'no' can be hard - especially for people who live to build products for users. It's important to remember that although a lot of users will not like it, the ones who do, will love the product, will stick around the longest and be the strongest advocates you'd ever find.

Saturday 19 November 2011

JSP and MySQL Connectivity


I remember when I first started using Tomcat, it took me a while to make my JSP script connect to MySQL using Connector/J.

1. Tomcat is a free, open-source implementation of Java Servlet and JavaServer Pages technologies developed under the Jakarta project at the Apache Software Foundation. Download and install Tomcat.

2. Install MySQL.

3. Create a database, say 'ProductSpec', and a table 'products' with three fields- id, name, brand.

CREATE DATABASE  `ProductSpec` ;

CREATE TABLE  `products` (
 `id` INT( 3 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
 `name` VARCHAR( 50 ) NOT NULL ,
 `brand` VARCHAR( 50 ) NOT NULL
) ENGINE = INNODB;

4. I populate the the database with a few values next:

INSERT INTO  `ProductSpec`.`products`
VALUES ( 1 ,  'Hard Disk',  'Seagate');

INSERT INTO  `ProductSpec`.`products`
VALUES ( 2 ,  'iPhone 3G',  'Apple');

5. Set up two environment variables as follows:
(a) Right click on Computer, go to Properties. Click on 'Advanced System Settings on the left. A dialog box appears as shown below. Go to the 'Advanced Tab' and click on 'Environment Variables'.



(b)Under User Variables, add the two new variables. The first is the path to your jre folder, the second is the path to the the Tomcat folder. For instance, if your jre folder path is D:/jdk1.6.0_12/jre, add the following-

Variable Name: JAVA_HOME, Variable Value: D:/jdk1.6.0_12/jre

Variable Name: TOMCAT_HOME, Variable Value: C:\Program Files\Apache Software Foundation\Tomcat 7.0



6. Download Connector/J at "http://dev.mysql.com/downloads/connector/j/5.1.html">http://dev.mysql.com/downloads/connector/j/5.1.html
Unzip or Untar the file, and copy the file mysql-connector-java-5.1.6-bin.jar to Tomcat/lib or Tomcat/common/lib

This completes the setup! Now for the jsp program that connects to the database and retrieves and displays values. Make sure Tomcat and wamp are running!

7. Here's db.jsp:


<%@ page import="java.sql.*" %>

<%

String connectionURL = "jdbc:mysql://localhost:3306/ProductSpec?username=root;password=";

Connection connection = null;

Statement statement = null;

ResultSet rs = null;

%>

<html><body>

<%

Class.forName("com.mysql.jdbc.Driver").newInstance();

connection = DriverManager.getConnection(connectionURL, "root", "");

statement = connection.createStatement();

rs = statement.executeQuery("SELECT * FROM products");

while (rs.next()) {

out.println(rs.getString("name")+" "+rs.getString("brand")+"<br />");

}

rs.close();

%>

</body></html>


Change your database name, username and password on line 3: (Default username for wamp is root and password is blank.

String connectionURL = "jdbc:mysql://localhost:3306/ProductSpec?username=root;password=";

8. Add db.jsp to Tomcat\webapps\ROOT folder.

9. Now go to your browser and type localhost/db.jsp
If you had set a port number for Apache during installation like I had (8088), type localhost:8088/db.jsp


Wednesday 14 September 2011

Formulae in Data Structures - Quick Revision

Most written technical tests have at least one question that goes - "How many Binary Search Trees can you form with n distinct numbers?" or "Number of internal nodes in an m-ary/k-ary tree?"
And I know for a fact, most of us draw small trees in the corner of our sheets. That
1. wastes precious time.
2. leaves out important cases.

So here's a list that is definitely not exhaustive, it'll be great if you could figure them out as you go along, helps remember. I'll keep adding more formulae as I come across them.  But for now, this should do:

1. To answer the first question above,

No of BSTs using n numbers is  2nCn / (n+1)                                                         (i)

For those of you who haven't seen this before, this gives the Catalan sequence, and the number of binary search trees can be found using the Catalan Sequence too, if you know it. For instance, if n=3, C(3) = 5 which is the number of BSTs you can form from three nodes.

2. The number of Binary Trees that can be formed, however, is given by the nth catalan number * n! The formula given above (i) calculates the nth catalan number.

No of Binary trees from n numbers is    n! * 2nC/ (n+1)


Here's a small example for the two formulae given above with n = 3 (say the nodes are 1, 2 and 3):

Binary Search Trees



6C3 / 4 = 5

1      1      2      3      3
 \      \    / \    /      /
  2      3  1   3  1      2 
   \    /           \    / 
    3  2             2  1




Binary Trees


3! * 5 = 30


  1      1      2      2       3      3      
 / \    / \    / \    / \     / \    / \    
2   3  3   2  1   3  3   1   1   2  2   1 

    1   1   1   1    1   1   1   1
   /   /    /   /     \   \   \   \         
  2   3    2   3       2   3   2   3        
 /   /      \   \     /   /     \   \              
3   2        3   2   3   2       3   2             

    2   2    2   2   2   2   2   2
   /   /    /   /     \   \   \   \         
  1   3    1   3       1   3   1   3        
 /   /      \   \     /   /     \   \              
3   1        3   1   3   1       3   1   

    3  3     3   3   3   3   3   3
   /   /    /   /     \   \   \   \         
  2   1    2   1       2   1   2   1        
 /   /      \   \     /   /     \   \              
1   2        1   2   1   2       1   2 

Saturday 25 June 2011

Enabling Query Cache for fast query execution in MySQL

1. Open the MySQL Console

2. Enter SET GLOBAL query_cache_size = 1048576;
(Size is in KBs, 1GB = 1x1024x1024=1048576)

3. Other Cache Related Settings includes
SET GLOBAL query_cache_type=1;
(To Enable Query Cache)
SET GLOBAL query_cache_limit=1024;
(Per User 1MB 1x1024)

4. Caching speeds up the fetching of queries, the size must be chosen according as the RAM size

5. To check their values, you can run command
SHOW VARIABLES LIKE 'query%';

Note: To run mysql in terminal: mysql -u root -p

Tuesday 14 June 2011

Animation Effect on your Splash/Welcome Screen on iPhone

In this tutorial, I'll give an example of how to have your own welcome image, and add the fade and zoom effect to it. When the iPhone launches your application, it looks for an image named Default.png in the resources directory. In the following example, Default.png is being replaced by a UIImageView which zooms and then fades away. (Consider abc to be your project name)

1. To abcAppDelegate.h, add the function declaration

- (void) welcomeScreen

2. To abcAppDelegate.m, add the function definition


- (void) welcomeScreen
{
//Welcome Screen
UIImageView* welcome = [[[UIImageView alloc] initWithFrame:CGRectMake(0,0,320,480)]autorelease];
welcome.image = [UIImage imageNamed:@"img.png"];
[window addSubview:welcome];
[window bringSubviewToFront:welcome];
//Animation Effects (zoom and fade)
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:2.0];
[UIView setAnimationTransition:UIViewAnimationTransitionNone forView:window cache:YES];
[UIView setAnimationDelegate:welcome];
[UIView setAnimationDidStopSelector:@selector(removeFromSuperview)];

//set transparency to 0.0
welcome.alpha = 0.0;

//zoom effect
welcome.frame = CGRectMake(-60, -60, 440, 600);
[UIView commitAnimations];

}

3. Call the method welcomeScreen

From applicationDidFinishLaunching method in abcAppDelegate.m, invoke welcomeScreen.

- (void)applicationDidFinishLaunching:(UIApplication *)application {
[window addSubview:viewController.view];
[window makeKeyAndVisible];
[NSTimer scheduledTimerWithTimeInterval:1.0/30. target:self selector:@selector(welcomeScreen) userInfo:nil repeats:NO];

}

And it's a wrap! Cheers!



Monday 6 June 2011

JDBC and MySQL

Steps to connect to a MySQL database from Java


1. Import

import java.sql.*;
import javax.sql.*;

2. Declare a Connection type in the class:

Connection conn;

3. Add a method to establish connection. Assume the name of the database is GameIF, and the username/password are the default values i.e username is root and there is no password.


private void connect()
{
String dbUrl = "jdbc:mysql://localhost/GameIF";
String dbClass = "com.mysql.jdbc.Driver";
String username="root";
String password="";

try
{
Class.forName(dbClass).newInstance();
conn = DriverManager.getConnection(dbUrl,username,password);
}
catch(Exception e)
{
System.out.println(e);
}
}



3.  Add a function that tears down the connection:


private void disconnect()
{
if (conn != null)
{
try
{
conn.close();
}
catch (Exception e) {}
}
}


4. Writing/Executing a query: A query may be of two types:

(a) One that returns a result set (e.g: SELECT query)

(b) One that returns no result set (e.g: DROP, CREATE, INSERT, UPDATE)

We'll see examples for both types:

(a) SELECT

connect( );

String uname, steps;

String query = "select * from `scores`";
try
{
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery(query);
while(rs.next())
{
uname = rs.getString("username");
steps = rs.getInt("steps");
System.out.println("Username: "+uname+"\tSteps: "+steps);
}
rs.close();
st.close();
}
catch(Exception e) {
System.out.println(e);
}


disconnect( );


(b) INSERT


connect( );


Statement s;
String query = "insert into `scores` (`game` , `username` , `steps`) values ('NUMBERJUMBLE','Tups',56)";
try
{
s = conn.createStatement( );
s.executeUpdate(query);
s.close( );
}
catch(Exception e)
{
System.out.println(e);
}


disconnect( );




And, we're done!
However, a very common exception is encountered if you are building a standalone application:

java.lang.ClassNotFoundException

To fix this:
1. Download the mysql connector jar files (A straightforward google search!)
2. Add the jar files (format mysql-connector-java-<version>-bin.jar) to the following two folders:
         <your jdk directory>/jre/lib
         <your jdk directory>/jre/lib/ext

If you are using netbeans or another IDE, copy the files and restart!

Cheers!


Saturday 4 June 2011

Add sound on Jbutton click in Java

To add a sound on JButton click event, follow three simple steps:
1. Import the following:

import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.Clip;
import javax.sound.sampled.AudioSystem;

2. Add the following function to your class:

public void playSound(String soundName)
{
try
{
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(new File(soundName).getAbsoluteFile( ));
Clip clip = AudioSystem.getClip( );
clip.open(audioInputStream);
clip.start( );
}
catch(Exception ex)
{
System.out.println("Error with playing sound.");
ex.printStackTrace( );
}
}

3. In your actionPerformed function for the JButton, just call the function with the filename as string:

public void actionPerformed(ActionEvent ae)
{

//do something
playSound("buzzer.wav");
}




About

I often came across broken or unhelpful snippets while working on projects. A small feature required by a project needed hours of surfing on the net. Just wanted to make things a tad simpler for you!