Wednesday, March 26, 2014

Interview on Hoodie Blog

Lena Reinhard from Hoodie interviewed me for their blog to discuss Hoodie and Offline First. I'm very pleased the interview.

"Offline is a fact of phone apps. In a rural area or in a big city, a phone is going to lose connectivity."
"He wrote a great tutorial on how to get started with Hoodie."

Wednesday, March 19, 2014

The Washington Post Gains 10m Members

By offering free digital access to subscribers to other newspapers, The Washington Post just picked up 10m members. Paywalls change the business model of newspapers from subscribing readers to adding members. When Jeff Bezos bought The Washington Post he purchased $175 million in membership. Having the credit card number of each digital reader (i.e., member) is of great value.

Nieman Journalism Lab and others wrote about The Washington Post offering free digital access to other newspapers. There is no such thing as a free lunch. So what does The Post gain by offering free digital access to local newspapers around the United States? Members in Texas, Honolulu, Ohio, Minnesota, Wisconsin and Pennsylvania. According to The Financial Times, 10m members. This expands the audience for offers to members with credit cards on file. Steve Hills, president of The Washington Post suggested that it could be expanded to “any company that sells premium subscriptions.” This is the new membership business model.
dddd
As a membership business, The Post will next follow the lead of associations, loyalty programs, unions and others. These organization make substantial money from the “member benefit” offerings. There is a whole industry that sells to these organizations and I’m certain they are calling on newspapers everyday. Expect to see The Post offer more than just a wine club. Credit cards, travel deals, insurance and more. And add staff to support this. “It pays to read The Post."

Thursday, March 13, 2014

Getting Started with Hood.ie


As a fanboy of couchdb, I’ve kept an eye on the hoodie project. Hoodie is an architecture that helps with offline operation and handles login/registration. So I wanted to write a step-by-step tutorial on Getting Started with Hoodie. This tutorial will modify the demo todo app.


Step One - Installing Hoodie
The hood.ie website walks you the installation. The steps should be pretty familiar to most developers. For Mac, it uses home-brew and npm
http://hood.ie/#installation



Step Two - Create Hoodie Project
You’ll need a folder for your project. Hoodie command line interface does this and populates it with the required files and folders.

In my case, in my dalyapps folder I typed:
hoodie new hoodietut

You’ll be prompted for an admin password.


Step Three - Start Your App and Test It
From the command line type
hoodie start
and it opened up a browser tab at
 http://127.0.0.1: 6004
You should see a hoodie app in your browser with a subtitle of ‘hoodie playground’. This ‘test’ shows that hoodie is working.

The command line output also shows you this information which you’ll use later:
CouchDB started: http://127.0.0.1:6006
Admin: http://127.0.0.1:6005



Step Four - Play with the App
The demo todo app shows off what you can do with hoodie. You will probably notice that it looks like a bootstrap app. Though the app uses bootstrap, hoodie has no dependency on bootstrap and any CSS framework can be used.

In the upper right, there is a drop down for Sign Up. Click on it and created an account with username and password. Now you should login because only then will data be saved.

Type in a few todos like “learn hoodie” and “steps 5, 6, 7 and 8”. You should see your todos displayed.

Nice to see a hoodie demo after just three steps!


Step Five - Tabs for CouchDB and Admin
The hood.ie demo app is already opened in your browser. Start two more tabs for CouchDB and admin. For CouchDB I wanted to see the Futon app, so these where the two urls I used:
http://127.0.0.1:6006/_utils
http://127.0.0.1:6005
While I did not use the admin (:6005) yet, it was good to know it was there. You don’t need Couchdb except for monitoring the hoodie magic.


Part Two: Make Hoodie Your Own: Go Nuts

In the next several steps the todo app will be modified to give todos a priority of 1, 2 or 3. The list of todos will be sorted on priority.


Step Six - Open your text editor
At this point the hood.ie site tells you to “go nuts”.  There are a few more steps you need to take before you can write your own hoodie app.

In my case, I started sublime text with a new project for /dalyapps/hoodietut. This was the folder created by hoodie in Step Two.

You should see folders of data, node_modules and www. Hoodie command line has set up files for both hoodie and the demo todo app.

We are going to be working in assets folder of www.


Step Seven - Edit your first hoodie files
To start creating you own App there are two files you’ll want to copy. In /hoodietut/www/ copy index.html and name the copy new.html. In /www/assets/assets/ copy main.js and rename the copy to new.js.

In sublime (your text editor) open new.html. On the last line you’ll see

<script src="“assets/main.js”"></script> 
Change that line from main.js to new.js

<script src="“assets/new.js”"></script>

Open a new tab in the browser and go to

http://127.0.0.1:6004/new.html 
This displays the file you just copied.

In the start of the body you’ll see the line “hoodie playground”. Modify that to read “my first hoodie app”. When you reload the browser you should see your first modification to a a hoodie app.


Step Eight - Button Please
The demo todo app lets you type in a new todo. It saves it when you hit the Return key. This works fine for a single input. But more because priority will be a new input, a submit button would be a more appropriate.

First, add a button to the new.html file. Look for the text input - search for “todoinput”. In the line after that add a button with an id. I used:
<button id=“addBut”>Add</button>


Second, change new.js so the addTodo is triggered when the button is clicked instead of on keypress. Replace the six lines of code after //handle creating a new task with

// handle creating a new vendor
$('#addBut').on('click', function() {
  hoodie.store.add('todo', {title: $("#todoinput").val()});
  $("#todoinput").val('');
});

The first line here looks for a click on our button. When the button is clicked second line adds a new task into hoodie using the hoodie.store.add method. This method takes two parameters: type and a data object where the task is defined. The third line clears the input.

Save these files and run your modified app at:

http://127.0.0.1:6004/new.html
Enter a new task. You should see it displayed when clicking on the “Add” button.

Step Nine - Understanding Type
Type is an important convention to understand when working with Hoodie or Couchdb. Type is a convention to deal with the lack of schemas in Couchdb.

In Couchdb the same database can contain a wide variety of different records. For example, you might have records on people and records on location. Type is used to distinguish one record from another. So the people records would have fields like fist name, last name, etc and a record called “type” with a value of “people”. The location record would have fields like street, country, etc and a record called “type” with a value of “location”

Hoodie uses type the same way. It is a way to store different ‘types’ of records in the same database. In this demo only the “todo” type is used.

So while type is not critical for this application, more complex application will have several types.


Step Ten - Adding Priority
Adding a priority requires an new input field, adding it to the display and modifying the add method we just worked with.

In new.html add a select input before the button we added above:


<select id="priorityinput" class="form-control">
  <option>1</option>
  <option selected="selected">2</option>
  <option>3</option>
</select>
<button id="addBut">Add</button>

Then in new.js modify the addBut handle to store the priority.

// handle creating a new vendor
$('#addBut').on('click', function() {
  hoodie.store.add('todo', {
  title: $("#todoinput").val(),
  priority: $("#priorityinput").val()
  });
  $("#todoinput").val('');
});
Also in new js modify the addTodo function to show the priority.

function addTodo( todo ) {
  $('#todolist').append('<li>'+todo.priority+' '+todo.title+'</li>');
}

At this point you should start seeing each task listed prefaced by a priority. Hoodie makes it pretty simple to add new fields to a store.


Step Eleven - Sort By Priority
Out todo list would look a lot nicer if they were listed by priority. So lets change the sort in new.js.


function sortByCreatedAt(a, b) {
  return a.priority > b.priority;
}

Now your number one priorities show first.


Conclusion: Give It a Try

Hoodie is very easy framework to start using. It builds on a developer’s knowledge of jQuery. It can use Bootstrap, Foundation, Enyo or any other front end framework. With very little JavaScript code you get authentication (login) and data storage. It’s offline ability is hard to beat.

Hoodie is a work in progress. There are more features to come. But don’t let that deter you from trying Hoodie. I think you’ll be please by what you find.