Weapons of mass creation
Getting Started with Android and CouchDB

This guide helps you setup an Android emulator on your machine as well as compile and install an Android application that launches a CouchDB service. Unlike the Android docs, this guide assumes you do not use Eclipse and walks you through the command line steps.

The official place to start with Android is http://developer.android.com/sdk/index.html. Refer to that if you get stuck here.

Install the SDK

First, download the latest Android SDK for your operating system at http://developer.android.com/sdk/index.html as of this writing I used Release 14 (R14).

Copy the zip file to a location like /Users/<username>/dev and unzip it. It will extract into a sub-folder like android-sdk-macosx. Then cd into that directory and you should see a tools/android binary.

Put that on your path:

export PATH=/Users/<username>/dev/android-sdk-macosx/tools:/Users/<username>/dev/android-sdk-macosx/platform-tools:$PATH

And launch it:

android

Then click on the latest Android checkbox, Android 4.0 as of this writing, and make sure its sub-items are checked. Then in the bottom right corner click Install 5 packages to install the SDK. This will take a while.

Create and launch Emulator

From the Android SDK manager click Tools and Manage AVDs, then New. Then for the SD Card Size put 200 and then click Start.

Tail emulator log

You can see various things that are happening on the system by tracing the Android logs:

adb logcat

Hello World

Setup directory

mkdir ~/dev/helloAndroid
cd ~/dev/helloAndroid

Create project

android create project \
 --target 1 \
 --name HelloWorld \
 --path ./HelloWorldProject \
 --activity HelloWorldActivity \
 --package com.example.helloworld
# target 1 corresponds to `android list targets`

Edit boilerplate

Edit HelloWorldProject/src/com/example/helloworld/HelloWorldActivity.java and make it look something like this:

package com.example.helloworld;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class HelloWorldActivity extends Activity
{
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        TextView tv = new TextView(this);
        tv.setText("Hello, Android.");
        setContentView(tv);
    }
}

Build debug version

If you are putting stuff on the emulator you want to compile in debug mode.

ant debug

Install onto emulator

adb install bin/HelloWorld-debug.apk

If that succeeds you can now browse for the app on the emulator and launch it. Success!

Sometimes adb does not recognize the emulator, restart adb and try again.

adb kill-server
adb start-server

Listing devices should show the emulator

$ adb devices
List of devices attached 
emulator-5554   online

Android Couchbase

Android-Couchbase and Android-EmptyApp provide enough for a hello world app bundled with CouchDB.

Clone Android EmptyApp

git clone https://github.com/couchbase/Android-EmptyApp.git

Download and unzip Android Couchbase

cd Android-EmptyApp
curl -O http://files.couchbase.com/developer-previews/mobile/android/android-couchbase-dp.zip
unzip android-couchbase-dp.zip

Build the two packages

ant -f couchbase.xml
ant debug

The second command will probably fail because it was developed on a different SDK build platform and needs an upgrade, continue below. You will also notice a symlinked couchbase-build.xml to an unknown destination, ignore that.

Upgrade project

Since we are running a different release of the SDK we have to upgrade the project’s build system to support our release. You can upgrade it with the following command:

mv build.xml build.xml.orig
android update project --target 1 -p .

Compile again and install:

ant debug
adb install bin/EmptyAppActivity-debug.apk

Now the app is installed on the emulator. Browse the apps list in your emulator and launch the EmptyApp application should display the hello world message. Success!

Forward ports

Connect to CouchDB by forwarding a local port to it:

adb forward tcp:59844 tcp:5984

Then launch http://localhost:59844 in your browser and you should see a response from your mobile CouchDB that looks something like:

{"couchdb":"Welcome","version":"1.2.0a-361a925-git"}

Mobile Futon

Another neat thing you can do is install a mobile version of futon. The following assumes you have the port forwarding setup.

Install couchapp http://couchapp.org/page/installing

Push mobilefuton to your mobile couch:

git clone https://github.com/daleharvey/mobilefuton
cd mobilefuton
couchapp push . http://localhost:59844/futon

Then launch http://localhost:5984/futon/_design/mobilefuton/index.html in the emulator’s web browser.

Thanks

Couchbase http://couchbase.com/

Dale Harvey https://github.com/daleharvey

Help?

Check out the mobile-couchbase mailing list or contact me on github.
SXSW 2011 Notes

SXSW 2011 Log

Milan Andric (Analyte Health) @mandric

This was my second time attending SXSW Interactive, the first being 2007. That was the year of Twitter, this is the year of Facebook and the Game Layer, but more about that later. The event has grown quite a bit, people complained about overcrowding, panels overflowed, twitter raged, press people had to wait in line, Mother Theresa cried a little bit. It wasn’t horrible for me personally, I missed two panels but went next door and still got something out of it. I was surprised to find that many people skip the keynotes entirely preferring to watch them online after the event. I suggest hitting the keynotes as they really speak to the broader conversation happening and clues you in. Keep in mind, this is an event to socialize, network and engage with people of all aspects of the tech industry. Innovation manifests through a cross-discipline approach and you might say “the magic” happens outside of the panels and sessions, in conversation between small groups and individuals. SXSW Interactive is easily the most invigorating and innovative tech event of the year, hit the parties, talk to folks, get on the twitter and you’re guaranteed a great SXSW experience.

Many of the events described below already have an audio archive of the talk, and some of the presenters also provided slides or other presentation materials. When possible these link are provided. Please enjoy. I have transcribed my notes for myself as much as for others, I understand it is a chore to wade through, feel free to parse it at you leisure. Also if you really like this bit of work, please link to it on your blog or website, thanks!

Here’s the permalink: http://m.andric.us/post/4151785594/sxsw-2011-notes .

SXSW Day 1

How not to design like a developer

Chrissie Brodigan (Mozilla/Firefox) @tenaciouscb

Chrissie is a soft spoken designer for Mozilla, has a background in Journalism and History and she likes open source. She started programming during the day in college to help pay the bills. Her panel was about bridging the cultural differences between open source projects and designers/creatives. She finds it is hard to contribute to open source as a designer and also believes strongly that insufficient design in an open project leads to failure. Appearance matters, open source projects need good docs and how a project presents itself builds confidence and leads to acceptance and ultimately success. She wants to promote design specific tools for developer like tasks, like bug tracking and version control. One interesting player I found in this space while perusing the expo was Designica, they build Art Management Software as a service for $30/month per designer. She also mentioned Sparkle Share which is like dropbox except with a Git backend.

Play At Work: Agile Games for Productive Teams

Christian Nelson (Carbon Five) @carbonfive

Christian is a developer who works for Carbon Five and seems to be a master of process. In this panel the audience actively went through some agile processes, namely defining the basic unit of work on an Agile team, a story. He defined a story as a promise for future conversation. Stories should be pretty small, demonstrate value to a user, describe a whole feature, not include interface detail and are easy to accept. They related the Agile process to a mock product that resembled twitter. He also talked about games as ritualized activities that we repeat, that are cooperative and have easily repeatable rules. The interface mockups he presented were created in a tool called Balsamiq, which looked pretty cool. I did a bit of research and found a similar tool, Tiggr that seems to be available for free.

OMG - My Pancreas Just Texted Me

John Pettengill (Razorfish) @JohnPettengill

This guy is an amazing experience designer in the Health 2.0 space. He is a diabetic and partnered with another designer to work on a mobile application. Right now the application only exists in mockup form, but much of the interface has been flushed out. The key problems the project defines are; patients are isolated, the current solutions are clinical, and forever is really hard. 85% of patients are looking online for information, there are several established sites where patients can participate in communities helping each other. We need to create new solutions and new tools. Chronic disease is managed all day long and tools are needed to help manage that. He believes we need to remake the tools that handle diabetes and reducing forever into steps. The current patients are isolated, find it hard to change alone and the current solutions are clinical. He notes that your doctor can’t come with you but your phone can. He wants to create an app that is focused on behavior and moving forward. 45% of the US population has chronic disease including Crohn’s, arthritis and heart disease.

SXSW Day 2

It’s Nature’s Way : Innovative Tech Design Through Biomimicry

Mobile Health Apps in Africa

  • Douglas Naegele (Infield Health)
  • Jaspal Sandhu (Gobee Group)
  • Josh Nesbit (Medic Mobile) @joshnesbit
  • Patricia Mechael (Center for Global Health and Economic Development at the Earth Institute Columbia University)

In this panel several people gave their experiences about mobile technology, namely mobile phones, that helped to influence health care in rural parts of the world where health care is not readily available. They all talked about using SMS and their experiences with a mobile platform for delivering health care.

Josh Nesbit told a story about his project in Malawi where he was able to double the amount of patients being treated using mobile technology. He used software called Frontline SMS to coordinate large amount of SMS messages and brought 100 mobile phones to the hospital and trained care workers to use them. This reduced the amount of time and money spent communicating and traveling between the hospital/doctors and care givers/patients.

Jaspal Sandu is a Lecturer of Community Health and Human Development in the School of Public Health at the University of California, Berkeley. He had an “Ahah!” moment working with migrant workers in the farms of the central valley in California. Many of the workers were using unsafe sex practices and bringing diseases like HIV back to Mexico. Nearly every worker had a mobile phone.

All the panelists seem to agree that technology has potential to create efficiencies and there is great opportunity in mobile. Yet understanding effectiveness in mobile health is hard because there is not enough evidence and there are too many pilots. Banking and business are already capitalizing on mobile and health is catching up. Data collection is a bad word and nobody likes to be studied. The environment in the US needs major sorting out, citizen centered health care and designing for patient experiences is growing, particularly underserved populations.

Keynote Opening Speaker

Seth Priebatsch (SCVNGR) @sethpriebatsch

Seth was a force to be reckoned with, his energy was borderline “on happy pills” but once you start listening to him he’s an amazing speaker. His talk is on the list of the most entertaining and energetic I have ever witnessed. He’s 22 years old, left Princeton after his first year and founded a startup now backed by Google. He’s all about building The Game Layer on top of the world.

The Game Layer is something we can use to motivate real behavior. He sees the game layer as radically changing the way we do school, which he considers “broken,” customer acquisition, location based services and how we deal with global warming.

“School is a game, just a poorly designed one.” There are two major problems, engagement and cheating. The grading system is not designed using positive progression, unlike points or levels. The disincentives for cheating are misapplied. Tests at Princeton are not proctored and this works and relies on the social fabric to prevent cheating.

In customer acquisition he talked about Groupon and how they use simple game mechanics to motivate their customers. Groupon gives the impression of a “free lunch” and addresses skepticism, incorporates communal game play by making a deal a group activity and includes a countdown to spike engagement. He exemplified American Express as a company that understands brand loyalty and status because they introduced the different level of cards (gold, black, etc…) that allow you to “level up.” Recently location based services like foursquare, scvnger and mytown have become mainstream and are using more game mechanics like rewards and quantitative easing. “Rewards work!”

He made an interesting point that, “moving something from impossible to very difficult is a big win.” He believes in the power of communal game play and demonstrated it in the keynote arena with a surprise game that everyone in the audience played. He setup some key game mechanics and limitations that relate to global warming: lack of communication, trading patterns, decentralized leadership, countdown, joint goal, epic meaning and blissful productivity that is a core part of human nature. He emphasized communal gameplay + communal discovery. The game was setup by handing out 1 of 5 large differently colored cards to everyone at the event as they entered. The goal of the game was to get every row in the arena with the same colored card where each row was separated by the aisle in the middle. The limitations were you had to remain in your seat and complete the color of the row before 90 seconds. I’m not sure how many people were in the main ballroom but they accomplished the goal in less than 60 seconds and each row held up their cards. Seth was in utter amazement it happened so quickly and donated a sum to charity. It seemed quite profound at the time! I’m not sure if the game was just too easy or that Seth’s charm had just worked on me.

Massive Health

I think Aza found his way into the schedule somewhat late because he was not in the printed schedule nor the online schedule, I still don’t see him there. I overheard some people talking in the other health panel and was able to locate his talk. For those who don’t know much about Aza Raskin he was the creative lead on the firefox team and now he has his eyes on the health industry.

Aza talked about human psychology, feedback loops, delayed gratification and human nature. He played the marshmallow video that I’m sure many people have seen where children are told to wait before eating a marshmallow. He sees the body as a design problem and in terms of interfaces. He asked questions like “Why do heart attacks and cancer come without any warning? Why does our body give us no feedback?” He thinks we could motivate people to take their entire 30 days of antibiotics if there was a blue stained circle on your hand and incrementally faded until you finished your dosage. His dad recently died of pancreatic cancer, and like many people in the health field there is a very personal story there related to his experiences with the health care industry and related products. He has a history of doing very small controlled experiments with people to validate a user experience hypothesis. He mentioned several products that are measuring our bodily functions, like number of chews and steps walked during the day. He demonstrated a live blood glucose measurement on a willing volunteer, which seemed more like a stunt than anything worth noting. But he did point out that the state of the art related to home blood glucose kits results with you a seemingly random number that is displayed. So it seems an obvious device to begin innovating. Aza has joined the “renaissance in medicine” and is working on bringing the feedback loop to healthcare.

SXSW Day 3

Future Fitness Meetup

This was an interesting setting with around 50 people opening up the floor to discuss the future of fitness. The room was filled with personal trainers, engineers, doctors, entrepreneurs, designers and business people from independents to project managers at Nike and Adidas. The discussion was focused around complaints and the challenges trainers faced in tracking data, fragmentation between devices and a loss for a standard platform to put structured data into and pull it out.

Keynote

Christopher “moot” Poole (Founder of 4chan/Canvas)

Christopher was funny and quite a different type of geek than the previous keynote speaker, Seth. He seemed quiet and a bit shy, definitely uncomfortable on stage under the hot light. He seemed a tiny bit unprepared and parched from the night before. It was funny when the poor guy had to ask for water as if the SXSW crew was torturing him by tossing him out under some artificial desert environment forcing him to entertain. Nonetheless he gave a great talk and he had a deep understanding of internet community and culture and true appreciation for it. While at SXSW he was interviewed by the NY Times.

27 (Fun!) Ways to Kill Your Online Community

Patrick O’Keefe (iFroggy Network) @iFroggy

This was a fun talk where those of you who run a website with an active community you want to keep should listen to. Here are a few things you can do to kill your community; Start religious and political discussions! (Assuming your site is not about discussion of these topics!); Change things and tell no one! Add or remove a feature and have no announcement. (People like when they are involved in changes.)

SXSW Day 4

HealthTap’s South By South Health Meet Up

Ron Gutman (HealthTap) @RonGutman

HealthTap founder, angel investor, TEDx Silicon Valley curator, white-hat health hacker, builder, serial hugger, world explorer, accelerator.

Keynote

Felicia Day (Creator of The Guild) @feliciaday

Felicia gave an interview and told her story about how The Guild was created. The Guild is a web series about online gamers that was created on donations for the first season, there was one show a month. Now it is a successful web series, moving to the big screen and sponsored by Sprint. She did most if not all of the bootstrapping herself including marketing and crowdsourcing through twitter and social media.

A Billion Columns? No problem: an Introduction to the Cassandra Database

Jonathan Ellis (Riptano, DataStax, Apache Cassandra) @spyced

Jonathan gave an excellent overview of the Cassandra database. Cassandra is a decentralized database that came out of Facebook and was heavily influenced by Google’s Bigtable and Amazon’s Data Store design documents that were published a couple years ago. It follows a CAP model (consistency, availability and partition tolerance) of reliability instead of an traditional ACID model.

SXSW Day 5

Keynote

Blake Mycoskie (Founder TOMS Shoes) @TOMSshoes

This was another inspirational keynote where Blake gave us the stories and some hints about the future of TOMS Shoes. He talked about how he got the idea for TOMS when he ventured to Argentina, he came back 5 months after getting the idea and gave 10,000 shoes away (shoe drop). His basic message was that not only does giving feel good, but giving is good for business and branding. It increases customer and employee attention. Your customers become your biggest advocates. TOMS didn’t have to focus on advertising as much as giving. TOMS also retains an amazing group of employees that desire to be a part of something important. He thinks every business should give a day off to employees to volunteer somewhere as group, to give and serve together and focus on someone else. Because of the giving he also attracted amazing partners. Ralph Lauren never collaborated with anyone for 40 years until he designed TOMS Rugby brand. AT&T did a commercial and told TOMS story for him just because he was a long time customer and had a great story.

“Who is Tom? There is no Tom. If you buy a pair of shoes today we give a pair tomorrow. Tom is an idea for a better tomorrow.” What is next for TOMS? One major goal happened in 2007 when TOMS did a 50,000 shoe drop in Africa. TOMS is now changing and becoming the 1 for 1 company and there is a mystery box to be opened on June 7th. Blake claims, “This will be the first step in meeting the needs for the rest of the world.”

Semantic Web and HTML Meetup

This was a fun meeting because you could interact. It started out small and grew into a fairly sized group about 20 minutes in. Several of the attendees took the meeting to one of the free venues and continued the conversation over drinks. Most of the time was spent chatting about RDF, Taxonomy (which some companies view as IP), Microformats, Classification, and things related to controlled vocabularies. Several experts showed up like the creator of dmoz.org (the open directory project), the lead developer of Facebook Open Graph Protocol, an engineer from Monster.com who maintains their resume ontology (which is quite valuable to them and has taken years to develop) and a woman from the Dow Jones and Reuters who manages vocabularies. We chatted about what RDF is, how to “declare” a vocabulary, which consists of publishing an RDF document. It seems the library sector has been developing some of these methodologies for years, and the experts say the place to start building your vocabulary is at the library or talking to a librarian, that experience could likely make for an amusing followup blog post. I asked some questions like, “If you wanted to start your own vocabulary where do you begin, is there a mailing list for RDF, etc?”. It seems like a very difficult subject to break ground on. The Stanford OWL group was also mentioned but I had trouble digging up much information on them.

Compiling Erlang on Snow Leopard
This assumes you have Xcode installed so you have gcc and friends in /Developer/SDKs/MacOSX10.6.sdk/usr/bin and are using sh or bash. I don’t think ARCHFLAGS does anything here, but I generally have it in my environment when I compile stuff.

Download and untar the Erlang source code from http://erlang.org/download.html. I used otp_src_R14B.tar.gz. Take a gander at the INSTALL.md file then run these commands:

export ARCHFLAGS='-arch x86_64'
export LDFLAGS="-L/Developer/SDKs/MacOSX10.6.sdk/usr/lib"
export CFLAGS="$ARCHFLAGS -I/Developer/SDKS/MacOSX10.6.sdk/usr/include $LDFLAGS"
export CXXFLAGS=$CFLAGS
export CPPFLAGS=$CFLAGS
./configure && make && sudo make install
Design is king

I used to always say content is king. Now I’m starting to say design is king. Because design gets people in the door, to look further at your product. Design takes ownership of the interface between your features/functions/content and a human being. If your interface is broken people cannot get to your content or features. If people have an unpleasant experience with your interface they will not come back. So without design your product becomes useless despite what virtues it may possess.

This thought rang clear after watching the TED Talk on the Polish designer Jacek Utko but also after spending much time with Apple products over the past 3 years or so. I noticed how the designer has a very important role and how well it works. The experience for people is great. This design focus or fundamental skill shines through from the Apple Stores, to the commercials and products. Steadfast design decision is present first and foremost. Brand is interface. And the interface is ruled by design.

This idea of interface is very abstract for me. As a web developer I interact with dozens of interfaces, not to mention just as a human. The Design of Everyday Things is on my shelf and really opened my eyes to good design. You don’t even notice it is there, until it breaks or changes, like a door knob, telephone or teapot. But even now in my current position developing web publishing systems, I see how design is everywhere. From web APIs to functions to file systems. Everything breaks down into how things interact with each another, interface. Design is hard to get right and takes alot of iteration, observation and testing … evolution. You can design to your heart’s content but the proof is in the pudding. When you see the interface go to work because someone uses it without thinking, then it works.

Also I think this distinction between designed intelligently and not design intelligently is apparent between Apple and Microsoft. Microsoft has provided us with hundreds of features buried in Microsoft Office that 90% of people will never care about. It’s bloat-ware. They have put tons of work into function and little in design. The form vs function basic rule of design seems to be ignored. Similarly for newspapers, journalists or content is #1 … design is barely present.

People like great content, but they love great products. Any great product requires a great designer. The designer takes ownership of the interface (visual/tactile/etc) between human and product. That fundamental skill or design innovation lacks with most products, and as Apple and Jacek Utko has shown us, this type of innovation makes all the difference.

Tips for a new Mac user

Over the last couple of years I’ve been mostly a Mac user, well as far as the desktop goes, it’s been Mac. On the server side its been some flavor of Unix. So I’ve come to appreciate the Mac OSX operating system quite a bit, I think it’s beautiful and love the history going way back to BSD 4.4, in proper Unix fashion. And I’ve also found some useful things that help me get around. This might help you as a newbie as well, assuming you’re coming from Windows or Linux. I know this has been done already a dozen times out there but I’m doing it anyway.

Here’s what I use nearly everyday on my Mac and could not function as well without:

Right click

Even with the one button looking Mac mouse you can still configure it to right click. If you have a really old Mac mouse that only has one button then grab any old two button USB mouse.

Apple Menu -> System Preferences -> Keyboard and Mouse -> Mouse -> Choose Secondary Button for right mouse button

Use iChat

iChat supports a couple protocols, mainly AIM, Bonjour and Jabber. This is all I need thanks god. Bonjour allows you to see anyone else running on your local network without any configuration. If you use gmail and gchat you can configure your iChat to login with your google account and provide the same functionality as gchat but integrates with your desktop better. In other words, you can sign out of gchat all to together, no annoying sounds or blinking tabs anymore.

Running your google chat in iChat still saves them in your google account because they are still going through jabber and google’s servers. I also like to save the iChat chats to my local file system as well so Spotlight and Finder are more useful. I also increase the font. You can do this stuff in preferences, iChat -> Preferences -> Messages.

Monitor you system with iStat

http://islayer.com/apps/istatmenus/

Download and install this, then configure it in Apple Menu -> System Preferences. You need to know what your computer is doing.

Finder

Use Search For

Finder gives you some very useful things in the left column that I often overlook. Namely the section labeled “Search For”. Here you can find almost any document or chat that you did today, yesterday, or this week.

You configure that sidebar in Finder -> Preferences -> Sidebar

See your filename suffixes

Most people I know are used to seeing their filename extensions, that is a preference in Finder. See Finder -> Preferences.

Keyboard shortcuts

Cmd + Tab

Cycles between applications.

Cmd + Downhill Quote (under the escape key)

Cycles between windows in an application.

Cmd + Space

Starts spotlight

Cmd + Shift + 4

Screenshot with crosshairs. You can select something with the crosshairs or you can press the space bar and it will highlight the entire application window, then click the mouse to capture it. All screenshots end up on the Desktop in png format labeled Picture [number].png.

Cmd + Shift + 3

Full screenshot. Not as useful as its older brother but still useful.

Cmd + Right/Left/Up/Down Arrow

Skips to the end/beginning/top/bottom of a line or text area.

Cmd + z

Undo

Cmd + shift + z

Redo

Remember you can undo and redo multiple times, but this doesn’t apply to mouse clicks like saved preferences but almost anywhere in an application where you are typing or moving things around.

Cmd + l (ell)

Go to the location bar in your browser. Then tab goes to the search box.

Cmd + a

Select all text. Anywhere you see a text field, could be your browser location bar or a word document, cmd+a is your friend.

Cmd + =/-

Using the = and - keys in combination with the cmd key allows you to zoom your browser window. I do this all the time because otherwise I would be squinting.

Customize your dock

The little tray of applications at the bottom of the screen is customizable. You can pull and put stuff in it by drag and drop and you can adjust the size and magnification values in Apple -> Dock -> Dock Preferences. I suggest removing stuff from the dock that you don’t use often so there is less to hunt and peck from. When you want to launch a new application that is not there use spotlight Cmd + space and type to find the app or do it the old fashioed way and launch Finder.

Change default folder for screen captures

If you’re like me, debugging apps and explaining screens and such, you are taking plenty of screenshots or screen captures. On macs these generally end up on you Desktop and can quickly lead to clutter. Luckily there is a way to specify what folder they go into. On Snow Leopard, for example, I ran these commands in Terminal after creating the directory:

defaults write com.apple.screencapture /Users/mandric/Desktop/Screenshots
killall SystemUIServer

Firefox

Tell Firefox to put stuff into your Downloads folder, not your Desktop. This helps to keep your Desktop nice and clean and when you need to take out the trash you know where to look.

Fluid + Gmail

Want to get your gmail out of the browser and make it more integrated into your desktop workflow, like a regular app? Fluid is for you.

  • Download the .app file and then move it to your Applications directory and launch it.
  • Enter http://mail.google.com/ into the homepage URL.

I had a problem with the icon, for some reason I had to set it manually in the General Preferences. I found a nice one thanks to Chris Ivarison. Scroll to the bottom for the gmail icon.

There was also one tweak I did, here’s my preference pane where I checked the box so closing the last window does not exit the application.

Related Links

30 Must-Have Tweaks For Your Mac - Smashing Magazine
Django, Python, mod_wsgi with cPanel WHM
We recently migrated all of our sites to a new machine and we also decided to run everything on cPanel, for various reasons. One problem with this setup at the time of this writing is out-of-the-box cPanel does not support python 2.5 or mod_wsgi. But it does support Apache2, so we decided to use mod_wsgi to run our sites built with Django. It’s been working pretty smoothly and the setup was not too bad. In this tutorial I assume you already have a working Django installation running (tested with runserver).

We were using mod_python in the past but the advantages to using mod_wsgi are:

  1. Smaller Python memory footprint in Apache.
  2. Can run as separate daemon process that is managed by Apache and supports threads.
  3. We can reload our application code without restarting Apache.
  4. Allows multiple WSGI applications on the same virtual host.
  5. Allows us to specifying what user our application will run as and a host of other nice configurations.
  6. Graham Dumpleton rocks.
The ingredients:
  • Python 2.5.x
  • mod_wsgi 2.x
  • Apache 2 (comes installed with cPanel)
  • Django
  • cPanel/CentOS
Not sure if this matters much to this tutorial but I will note some system information as well:
$ uname -a
Linux bubba.example.com 2.6.18-53.1.21.el5 #1 SMP Tue May 20 09:35:07 EDT 2008 x86_64 x86_64 x86_64 GNU/Linux
$ rpm -q glibc
glibc-2.5-18.el5_1.1
glibc-2.5-18.el5_1.1
What is WSGI? According to one site it is:
WSGI is a specification, laid out in PEP 333, for a standardized interface between Web servers and Python Web frameworks/applications. The goal is to provide a relatively simple yet comprehensive interface capable of supporting all (or most) interactions between a Web server and a Web framework. (Think “CGI” but programmatic rather than I/O based.)

Build Python

We decided to build and maintain our own python installation rather than using the one that comes with the cPanel install. We wanted to avoid any grief with mailman and cPanel dependencies being broken. We also preferred using the latest and greatest python for our web applications.

To get sqlite support in python 2.5 you need to get the headers to compile against. Since I already had sqlite3.3.6-2 installed I grabbed a rpm for the devel package on CentOS 5.1 to build against.

Then downloaded python 2.5 and built as such:
$ ./configure --prefix=/opt/local --with-ncurses --with-threads --enable-shared
$ make && make install
If you try to run /opt/local/bin/python and get something like “error while loading shared libraries: libpython2.5.so.1.0: cannot open shared object file: No such file or directory” then you can configure ld to find your shared libs. On the redhat system cpanel uses you can create a .conf file in /etc/ld.so.conf.d/. The .conf file just has a path in it. See man ldconfig for more information.
$ cat >> /etc/ld.so.conf.d/opt-local.conf
/opt/local/lib
^d (press ctrl-d)
$ ldconfig
Now you have python 2.5 on your system, you can configure a /usr/bin/python2.5 symlink if you like or put it anywhere on your system. I chose to just add /opt/local/bin to my $PATH or specify the path explicitly. Don’t replace the system default python 2.4 of course since mailman currently depends on that! Hopefully future releases of cPanel will ship with Python 2.5.

Build mod_wsgi

When building mod_wsgi I used a shared python library as recommended to avoid apache process bloat. If you use a shared library then mod_wsgi.so is only around 250K according to the docs. But you have to symlink the python shared library from the right directory for mod_wsgi to find it. That was clearly stated in the installation issues for mod_wsgi:
In that case you need to create a symlink in the ‘config’ directory to where the shared library is actually installed.
So we built mod_wsgi by doing:
$ cd /opt/local/lib/python2.5/config
$ ln -s ../../libpython2.5.so .
$ cd /opt/local/src/mod_wsgi-2.1/
$ ./configure --with-python=/opt/local/bin/python
$ make && make install
After running the install you will see a new apache module installed at /usr/local/apache/modules/mod_wsgi.so, mine was 171K.

Configure Apache and mod_wsgi

First tell Apache about the new module and what files it should handle. This can go in the pre-vhost conf which can be edited in WHM from Apache Setup | Include Editor.
LoadModule wsgi_module /usr/local/apache/modules/mod_wsgi.so
AddHandler wsgi-script .wsgi 
Then configure a virtual host/site to actually start using it. You should probably start reading some of the mod_wsgi documentation. One concern is whether to use embedded mode or daemon mode. Daemon mode is the most commonly used setup and the one I used sits inside a VirtualHost include file. Here’s the configuration for our Django site:
<IfModule mod_alias.c>
Alias /robots.txt /home/bob/sites/example.com/lib/myproject/media/robots.txt
Alias /media /home/bob/sites/example.com/lib/myproject/media/
Alias /admin_media /home/bob/sites/example.com/lib/django/contrib/admin/media/
</IfModule>

<IfModule mod_wsgi.c>
WSGIScriptAlias / /home/bob/public_html/myapp.wsgi
WSGIDaemonProcess myapp processes=5 threads=1 display-name=%{GROUP}
WSGIProcessGroup myapp
WSGIApplicationGroup %{GLOBAL} 
</IfModule>

According to the above config, all requests for this site will be managed by the WSGI application, except for the URLs defined with the Alias directive.

On our cPanel system this file is:
/usr/local/apache/conf/userdata/std/2/<username>/<your.site.domain>/vhost_mods.conf
Also remember when adding a configuration to your vhost config on a cPanel system you should run the following commands:
/scripts/ensure_vhost_includes --user=<username>
/scripts/verify_vhost_includes 

Hello World

Here is a minimal script you use to test. Once you have mod_wsgi.so compiled and loaded into Apache, put this in your myapp.wsgi script to check if the pipes are clean.
def application(environ, start_response):
    """Simplest possible application object"""
    output = "Hello World"
    status = '200 OK'
    response_headers = [('Content-type', 'text/plain'),
                        ('Content-Length', str(len(output)))]
    start_response(status, response_headers)
    return [output]
In searching to get the beginner scoop I came across a mailing list thread which explains it quite well. Most of the mod_wsgi documentation is technical and there is so much it is daunting. I have a feeling Graham is prepping for a book. One thing I did to learn was subscribe to the mailing list and start listening. Helps the pieces come together. Asking questions on the mailing list I was greeted with prompt and helpful answers. It is rare to see a thread go unanswered by Graham, the author, even in some cases during vacation. This level of commitment to a crucial piece of grease and cog makes me proud to be an open-sourceror.

Configure Your Application

Create a mod_wsgi python script (myapp.wsgi) to load our application.
  1. Tell python where to find your libraries
  2. Tell python where to store python eggs (this directory needs to be writable by the mod_wsgi process).
  3. Define your DJANGO_SETTINGS_MODULE so Django knows what project you want to run.
  4. Define a WSGI application, in mod_wsgi script terms that means instantiate an object named ‘application’.

Each WSGI application typically uses it’s own script. Typically this file lives in the docroot and sets up your application. You can see how I’m referencing the WSGI script from the WSGIScriptAlias Apache directive above. These are some conventions I have to store my Django project and related Django applications for the site in /home/<username>/sites/<sitename>/lib. So I insert that path as the first item in my python path.

import os, sys
sys.path.insert(0,'/home/bob/sites/example.com/lib')
os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'
os.environ['PYTHON_EGG_CACHE'] = '/home/bob/sites/example.com/.python-eggs'

import django.core.handlers.wsgi

application = django.core.handlers.wsgi.WSGIHandler()
One thing to check with your application is that you are not using the print function within it. I had a few places where I was debugging and left some print statements hanging around. That was running quietly in mod_python but mod_wsgi complains about it. This is actually a good thing since your web application should be logging this information in a log file and not printing debug information to the client. So I replaced these print statements with:
print >> sys.stderr, 'entering function'
[or]
sys.stderr.write('entering function')
sys.stderr.flush()  # if timing is a real issue

Success

If all goes well when you restart apache and look at the process list on your system you will see 5 ‘(wsgi: myapp)’ processes that were spawned and kept alive by apache. In this case the process will be owned by nobody or whoever apache is running as. Also if the modification timestamp on your myapp.wsgi file changes and you refresh your site new code is loaded.

I chose not to run a threaded process, so in my config I set threads=1. But that’s because I have some code that may not be thread safe. I should look further into that because ideally I would like to run threaded process so they scale better. I’m still not entirely sure what is thread safe, so figured I wouldn’t trudge too far into unknown territory. I’m amazed at the load we are handling with 5 of these suckers and a bit of caching. Of course we are only serving the python requests, the static file requests are skipping mod_wsgi. They are defined with the Alias directive and handled by Apache.

Related

I have to admit, even after installing a WSGI application I still have a hard time explaining what it is. The simplest explanation is WSGI is just a spec, but I think of it as CGI for Python applications. I guess CGI didn’t cut it. There is plenty of better information than I can provide.
lawyers, journalism and open source

I was talking to a lawyer friend of mine, telling him how law offices/firms promote inefficiency because each firm holds on to it’s IP (intellectual property) like it’s gold. This IP is organized as a document repository (bunch of word docs) that are used as templates for whatever deal or situation the lawyer is working on. I was stressing that these documents should be shared so that any firm/lawyer is strengthened with working copy and each firm does not have to re-invent those wheels. There should be a base that anyone can pull from, even me if I choose to represent myself.

Well, it seems there is exactly such a thing in the world of law. A central group (will find out the name) that works to enhance “the body of law”. So any lawyer can pull from it and become familiar with it.

So my point is, in order to create the BSDP (Berkeley Standard Distribution for Publishing :P ), you need a centralized working group on it. Not 12 different groups working to solve nearly same problem but instead creating their own non-standard non-distribution (think lawyers hoarding templates “IP”). In the end all the lawyers are weakened if the “body of law” is not strengthened. I know it’s all very abstract.

One good example of a working group is the w3c.org which works on defining specs. Implementation is left to the vendors, those who build technology to support a spec, MS, Apple, etc. Nowadays spec writing has become a thing of the past and replaced with release early/often type of software cycle, with more client input instead. But spec for the purposes of defining a new technology, like with HTML5, has been successful. And tech vendors realize there needs to
be a standard, otherwise everyone’s job is harder.

But remember that before an HTML spec was completed there was already a couple browsers out there happily rendering html and interpreting javascript. Each creating some special set of tricks that it supported. I think we are in the Mosaic (one of the first web browsers) age of web publishing. A spec hasn’t been written yet. I know I’m comparing apples and oranges here and oversimplifying, but remember I’m a techie (mostly), so that’s my viewpoint.

Not sure where to go from here other than to keep talking to my lawyer friend. I do have a project in the oven with news21, I’ll include a basic screenshot of the “content types” and “web services” that I see as vital to any web publishing organization. I am also planning, not sure if it’s feasible, to release the news21 CMS as an open source project. Not sure when it will be done, probably next year. But the more abstract idea of creating a working group to work on a spec of what needs to be supported is more valuable, but you need industry backing and it takes alot more work than building a CMS. Keeping the bigger picture in mind and abstracting a bit is a start though.

A webdev’s take on tv.adobe.com

After taking a second look at http://tv.adobe.com it is actually poorly
designed from a web developer’s point of view. I’m surely making some
assumptions here since I don’t know what went into the design of
tv.adobe.com, but this is my take on it :

1) Everytime you go to the front page you get a “Loading ..” sign. It
doesn’t matter if it’s the second or first time, though the first time
it is a longer load. This is a design flaw.

2) Does not adhere to browser conventions/standards. The back/fwd
buttons in the browser do little to help navigation in the site.

3) Not using css/html at all.

4) It’s a monolithic solution to a modular problem. The whole site
runs through AdobeTV.swf. Unlike youtube or every other video site
out there, that uses flash where appropriate.

According to the source code it was built in AIR.

<!—
Smart developers always View Source.

This application was built using Adobe Flex, an open source framework
for building rich Internet applications that get delivered via the
Flash Player or to desktops via Adobe AIR.

Learn more about Flex at http://flex.org
// —>

This statement shows some of the hypocrisy at Adobe and alot of
commercial orgs trying to sell themselves as open source. You look at
the source code, but do you see anything other than a reference to
AdobeTV.swf? No.

That doesn’t mean I won’t learn about all the cool things you can do
with flash to my heart’s content! In high def. even! One can’t deny
it’s amazing in many aspects, but design-wise from a web standpoint,
I’m a bit disappointed.

Why do google results for Nike.com kind of suck?

I got curious yesterday after doing a simple search for ‘nike shox’ which I imagined would just take me straight to a beautifully designed flash interface at Nike.com to glamorize the shoe. Well I didn’t get that… I then realized it would be more interesting to see exactly what google is doing for Nike or vise versa how Nike takes advantage of google.

My conclusion is Nike doesn’t take advantage of search. Nike’s SEO (search engine optimization) sucks pretty badly. If they did two things they would probably get the results they’re looking for.

1) Use the title tag! Using ‘Nike.com’ as your <title> is useless.

2) Use nice URLs so the keywords appear in the URL as well.

Some might jump to conclusions and say this is a consequence of using flash or some other technology. But I think it’s a pretty clear case of a web shop that doesn’t really care about search results.

See Screenshots

Notes on Django Tutorial at Pycon

Jacob Kaplan Moss

Querysets are cheap and queries (db hits) are expensive.

Models, Views, Urls and Templates, all you need to know to get started.

Views

Where you gather all the “stuff” that you want to display.

Smugmug exploit.

Your URL is a part of you application, you should design it. URLs are user interface. Some frameworks try to hide URLs, but URLs are part of the web and part of the UI.

URLs are “hackable”. You can edit a URL so you can move up a directory, etc. This used to be a “expert” feature, but nowadays people see a logic to it. People chop URLs to get there. Users are getting mor savvy.

Django doesn’t lock you in to a particular URL structure.

Object mapping

  • Unlike Rails which will by default follow your controllers and build URLs automatically.
  • Relationships defined
  • URIs should be opaque. They should define a resource but not what’s behind it.

ROOT_URLCONF is where Django starts.

import * is evil unless the package is designed for it.

from django.conf.urls.defaults import *
urlpatters = patterns('', ...)

Regular expressions, full re power is there, but you probably won’t need it.

Tips:

  • If you’re repeating yourself in patterns then you probably should move that out into a separate url file i.e. include(‘cheeserater.packages.urls’). Just don’t anchor the pattern with $.
  • You can get a little performance increase to move common URLs to top of patterns list.

Dissecting a request /documentation/url_dispatch/

  • GET /packages/Unipath/
  • ROOT_URLCONF
  • cheeserater.urls (walking down the patterns trying to match against the path)
  • (r’^packages/’,…)
  • include (‘cheeserater.packages.urls’)
  • call the view function with the first arg as request

A view function is a python function that takes a request object and returns a response object.

MVC differences

  • Your view is responsible for collecting and collating data but does not include presentation data.
  • Visual representation is in a template.

Using render_to_response() [view code example]

get_object_or_404(SomeModel, **kwargs)
  try:
        return SomeModel.objects.get(**kwargs)
  except SomeModel.DoesNotExist:
        raise Http404(...)

Templates

Glorified chunk of HTML with some variables.

  • PHP is a template language.
  • Ruby uses RHTML.
  • Python has dozens.
  • Django ships with one because we like it, you can use something else if you like. You can use a different one quite easily.

[showing example template]

Django template language has been designed for someone who is used to writing HTML. i.e. a Designer

The magic dot

  • p[“name”]
  • p.name
  • p.name()

You shouldn’t have to tell your template designers if something is a function or method … cheetah template engine idea.

Template filters
filter chaining with | built-in filters
Tags
usually do something with flow and logic, i.e. for, include, if then … same tags require end tags and others don’t

Template inheritance “big whoop idea / feature”

  • solves the problem of common code
  • base template
  • blocks / block tags
  • holes or places that will get filled in later
  • “the news hole” “i need three hundred words to fill this news hole”
  • putting a title block in the base template and let the child define it’s own if it wants to.

[block.super example]

  • Thought django template language was the stupidest idea when he first started at LJ world.
  • Most people are used to includes, while you can do that, it’s not designed for that.
  • [ inheritance example]
  • base template (absolute smallest piece of design, stuff that never changes)
  • might have base templates for each type of content.
  • requires {% extends %} to be right at the beginning.
  • typically 3 or 4 levels of inheritance

Why?

  • Lawrence world was first site built with Django.
    • It was one template before they rebuilt it.
  • matching divs with includes sucks.
  • every designer he’s worked with thinks template inheritance is brilliant.

Inheritance Tips

  • {% extends %} must be the first thing in your template.
  • More {% block %}s are better. Throw empty blocks in your template.
    • i.e. {% block extrahead %}
  • If you’re duplicating content then you’re missing a block.
  • {{ block.super }} keep it in mind
  • /documentation/templates/
  • /documentation/templates_python/

Croyden (postneo.com) friend

Generic Views

Saves time in doing common tasks.

What’s a generic view?

  • early on they realized same stuff was being repeating.
  • when copy and posting code, you know something is wrong.
  • only writing parts of views that differ.
  • pagination
    • getting that right once and not thinking about it again.
  • what does a list of objects do?
    • takes a request and a queryset. (and has lots of options)
  • generic views are just plain old python functions, just views.
    • nothing that special about them other than just used alot and tested.
  • [view code example]
  • package_list(request, package_name):
    • return list_detail.object_list(…)
  • [template code example]
  • include makes sense for pagination widget.

URLconf revisisted

(pattern, callback, extra)

Testing

Apology for being preachy.

“Tests are the Programmer’s stone, transmitting fear into boredom.” — Kent Beck

A good code base vs bade code base = quality of unit testing

Book: Test Driven Development (TDD)

“Never write any new code unless you have a failed test.” Drives Jacob crazy, TOO BORING.

“I didn’t do test driven developement. I do stupidity driven testing … I wait until I do something stupid, and then write tests to aoid doing it again.” — Titus Brown

“Never let one test break.” — Jacob

“Whatever happens, don’t let your test suite break, you’ll regret it …”

Testing Django

  • load sample data
  • deal with HTTP
  • setup and teardown
  • until recently was thought to be too hard
  • rail shipped with a test framework
    • stubs out test for you when you start a new app
    • testing isn’t THAT hard
  • inspired by rails except more pythonic

Doctest

Unit tests

Fixtures
loading data in a reliable manner

Test client

Email capture

  • allows email to be captured so you don’t actually send out email

Doctests

  • String inside triple quotes that looks like an interactive session.
  • Both tests and documentation.
  • Or create tests.py file.
  • /documentation/testing/
  • Siege (test requests/sec)

What else ya got?

ref: Report Lab (integrating PDF)

Problems at the Tribune Co

But shouldn’t Zell be making the decision about what to focus on and
what the strategy is?  Seems like a cry for help/support from his
associates which he isn’t getting?  But what is he going to do about
that?  He obviously needs to Tribune Co to focus on something
different, but what?  Revenue?  Journalists don’t focus on revenue
obviously.  Who was he referring to for help?  He doesn’t have any
ideas yet?

The problem seems to be what a news organization should be.  Nobody
has defined that very well.  Why doesn’t the Tribune have a tv show?
Why can’t I just go to tribune.com and have 3 buttons.  TV, Radio and
Print?  I should just get the news in a simple
straightforward way.  Ad placement just needs some basic editing so
it’s well placed.  They need to come up with a workflow that suits
their editors (journalists) and the profits will come.  Well that’s
one possibility.

The thing that urks me about those videos is how all the good stuff,
the conversation that happened there is edited out.  This is a pretty
good symbol for the closed model.  It’s a good example of “lesser”
usage of internet video too, from the Tribune.  The video player is
pretty horrible as well.  When ad placement begins to tear up your
layout then it’s bad placement.

There is no reason there can’t be:

* one video on the screen preferably a higher quality is available
with ads everywhere else on the screen.
* every square inch would be fine.
**As long as that video is front and center** and it’s enticing and the ads don’t overpower the content.

Think of a picture with a frame around it.  The frame is made of
advertising, kind of like an arena at a football game.    A print
button next to the video would be nice if I wanted the transcript or
comments.   But they definitely got my attention.  It’s great.
The more hits the video gets the more people will bid for that placement.


I want more from the tribune’s own content … that “story” could have
been a great opportunity for them to bing their ideas forward.  So
what if other companies learn from it.  It builds momentum if more
companies follow because you found a model people can latch on to!
Companies are just made of people anyway so…