Elroyjetson

Archive for May, 2012

The Power of Mobile Web for Tourism

Posted on: by

The Mobile Landscape

  • Huge number of mobile devices & 85% include a web browser
  • Mobile device is the only Internet access point for large numbers of people
    • 25% in US
    • 59% India
  • Devices aren’t limited to just small screen but come in all shapes and sizes
  • By 2015 Web access by people on the move is likely to exceed web access from desktop computers

Mobile Behavior

  • Using the Internet is no longer an activity with a specific context
  • Dramatic impact on behavior and expectations
  • Mobile is being combined with longer, completely ‘non-mobile’ contexts
  • Mobile is used to time-shift
    • 59% visit a site on mobile and follow-up on a PC
    • 34% visit a site on a PC and follow-up with mobile
    • Mobile shopping use stats Slide 34
  • The Power of Mobile is that it Acts as a Bridge between Physical and Digital Experiences

The Mobile Traveller

  • Lots of interesting stats for the travel industry
  • A trip isn’t a single event. It’s a journey and your digital experiences should embrace all stages of that journey

Tips and Ideas

Things to do While Developing a Mobile Strategy

  • Check your analytics
    • Which devices access your site most often
    • What pages or sections are most popular
  • Test most critical and commonly accessed content using devices discovered in step 1
  • Test all partner services
  • Be pragmatic
    • Take advantage of services already well optimized: Facebook, Twitter, YouTube, SlideShare etc.
    • ‘Well Optimized’ – lightweight, mobile friendly layout, site-to-site URL integrity, support for most modern smartphones
  • Lighten up!
    • Reduce page weight
  • Enhance where you can
  • Check your URL’s
    • ensure users who email, tweet or link to content can access that URL from any device
    • implement friendly error page for equivalent content that doesn’t exist
    • Don’t trap content in a native app
  • Think of the user journey
  • Start simple and experiment

References

  1. The Power of Mobile Web for Tourism – Yiibu slide deck

How to create web development sites

Posted on: by

Goal: Setup development environments that are independent of each other and operate similar to a production environment

High Level Steps

  • Create development site folder
  • Add to Apache config
  • Update hosts so names resolve in format http://dev_site_name.dev
  • Flush system so it picks up the updated hosts file
  • Restart Apache

Assumptions

  • For the sake of this how to we will use abcd.dev as the name of the development site we want to create.
  • My home directory is /Users/jking, yours will be different
  • Text editor is vim

Step 1: Create development site folder

I like to keep all of my development environments in my home directory sites folder, you can put them anywhere, but this is nice and tidy.

$ mkdir ~/Sites/abcd.dev

Step 2: Add to Apache Config

Add the following to your Apache httpd-vhosts.conf file:

<Directory "/Users/jking/Sites/abcd.dev">
Allow From All
AllowOverride All
Options FollowSymLinks
</Directory>
<VirtualHost *:80>
    ServerName "abcd.dev"
    DocumentRoot "/Users/jking/Sites/abcd.dev"
</VirtualHost>

$ sudo vi /etc/apache2/extra/httpd-vhosts.conf

Update hosts so names resolve in format http://dev_site_name.dev

Add the following entry to /etc/hosts:

127.0.0.1   abcd.dev

$ sudo vi /etc/hosts

Flush system so it picks up the updated hosts file

$ sudo dscacheutil -flushcache

For OS 10.7 and up:

$ sudo killall -HUP mDNSResponder

Restart Apache

$ sudo apachectl -k restart

How to install XDebug on OSX

Posted on: by

XDebug is a PHP extension which provides debugging and profiling capabilities.

Installation is fairly painless on OSX.

Assumptions

  • Working PHP installation
  • pecl is installed and functional
  • Comfortable with CLI and vim

Step 1: Install the xdebug extension

$ sudo pecl install xdebug

Note: Ignore the pecl prompt to add “extension=xdebug.so” to your php.ini – this will cause problems.

Step 2: Configure PHP to utilize xdebug

Search the php.ini to find “zend_extnsion”. In mine the line to enable xdebug already existed and just needed to be uncommented (remove the ;). If not add the following line.

zend_extension="/usr/lib/php/extensions/no-debug-non-zts-20090626/xdebug.so"

Step 3: Restart Apache

$ sudo apachectl -k restart

How to specify layouts by module in Zend Framework

Posted on: by

Assumptions

  • Tested on Zend Framework 1.11.11
  • Application has been setup to use modules

General Steps

  1. Set default layout in application.ini
  2. Create controller plugin to become the layout picker

Step 1: Set default layout in application.ini

Add the path to the layouts folder and make the default layout name (layout.phtml) match the default module name (default.phtml) which seems more sensible.

resources.layout.layoutpath = APPLICATION_PATH "/layouts"
resources.layout.layout = default

Step 2: Create controller plugin to become the layout picker

Setup autoloader for plugin in application.ini and add resource for frontController Plugin

// ZC_ is the namespace for ZendCast where I found the instructions
autoloaderNamespaces.zc = "ZC_"
resources.frontController.plugins.LayoutPicker = "ZC_Controller_Plugin_LayoutPicker"

Create the LayoutPicker file in the library/ZC/Controller/Plugin/ directory with filename of LayoutPicker.php

<?php
class ZC_Controller_Plugin_LayoutPicker
    extends Zend_Controller_Plugin_Abstract
{
    public function preDispatch(Zend_Controller_Request_Abstract $request)
    {
        Zend_Layout::getMvcInstance->setLayout($request->getModuleName());
    }
}

Now if you have an admin module that needs a different layout from the default, create an module_name.phtml in the layouts folder with the new layout.

Additional Resources

Add mcrypt to PHP in OS X Lion (10.7.x)

Posted on: by

I had found a great write up on how to do this here, unfortunately Apple made changes to Xcode. So if you have Xcode 4.3 or greater this write up will get you there.

Assumptions

  • Mac OS X Lion 10.7 or greater
  • PHP 5.3.8
  • Xcode 4.3 or greater
  • curl CLI utilitiy

Steps Overview

  1. Install libmcrypt-2.5.8
  2. Install autoconf-2.68
  3. Install PHP 5.3.8 source
  4. Turn on mcrypt in PHP

Preliminary Setup

** Note: All steps are performed from the command line. Also I would have preferred to install autoconf with HomeBrew, but there is some back and forth on it in the HomeBrew repo on github, so at some point it probably won’t be necessary to do manually.

To make things easy and keep things tidy, create a directory to store all of the downloaded source code to:

$ cd ~; mkdir SourceCode

Step 1: Install libmcrypt-2.5.8

Download libmcrypt-2.5.8

$curl -O \
http://superb-sea2.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
$tar xzf libmcrypt-2.5.8.tar.gz
$rm libmcrypt-2.5.8.tar.gz
$cd libmcrypt-2.5.8

Configure libmcrypt for compilation

$ MACOSX_DEPLOYMENT_TARGET=10.7 \
CFLAGS='-O3 -fno-common -arch i386 \
-arch x86_64' LDFLAGS='-O3 -arch i386 \
-arch x86_64' CXXFLAGS='-O3 -fno-common \
-arch i386 -arch x86_64' \
./configure --disable-dependency-tracking

Compile libmcrypt

$ make -j6

Install the library

$ sudo make install

Step 2: Install autoconf-2.68

Download autoconf-2.68

Make sure we are in ~/SourceCode

$ cd ~/SourceCode
$ curl -O http://ftp.gnu.org/gnu/autoconf/autoconf-2.68.tar.gz
$ tar xzf autoconf-2.68.tar.gz
$ cd autoconf-2.68

Configure autoconf for compilation

$ ./configure

Compile autoconf

$ make

Install autoconf

$ sudo make install

Step 3: Install PHP 5.3.8 source

Download PHP 5.3.8

Make sure we are in ~/SourceCode

$ cd ~/SourceCode
$ curl -O http://www.php.net/distributions/php-5.3.8.tar.gz
$ tar xzf php-5.3.8.tar.gz

Prepare mcrypt extension for compiling

$ cd php-5.3.8/ext/mcrypt
$ /usr/bin/phpize
$ MACOSX_DEPLOYMENT_TARGET=10.7 \
CFLAGS='-O3 -fno-common -arch i386 -arch x86_64' \
LDFLAGS='-O3 -arch i386 -arch x86_64' \
CXXFLAGS='-O3 -fno-common -arch i386 \
-arch x86_64' \
./configure \
--with-php-config=/Application/Xcode.app/content/Developer/SDKs/MacOSX10.7.sdk/usr/bin/php-config

Compile mcrypt.so

$ make -j6

Install mcrypt.so

$ sudo make install

Step 4: Turn on mcrypt in PHP

If you have never made changes to your php.ini, then odds are you will have to create one from the php.ini.default, if not modify your current one.

$ sudo cp /etc/php.ini.default /etc/php.ini

Turn on dynamic loading of PHP Extensions (use your favorite editor, I use vim). Change enable_dl = Off to enable_dl = On and remove the ; in front of it if it exists.

Some where under the “Dynamic Extensions” header add the following line: extension=mcrypt.so

Finally you need to restart apache to make sure that everything is working: $ sudo apachectl -k restart

To check it, use phpinfo();

Install pandoc with Homebrew

Posted on: by

Since pandoc is written in Haskell, you cannot install it directly with Homebrew. But there is an indirect way to install it using Homebrew. Before you ask, pandoc does have an OSX installer, but I prefer to manage all of my tools with Homebrew.

Assumptions

While this may work in earlier versions of OSX, I have only tested it on 10.7.4

Obviously you will also need a copy of Homebrew installed

Step 1: Install Haskell Platform

Using Homebrew install the Haskell Platform.

$brew install haskell-platform

This takes a few minutes so you will need to be patient.

Step 2: Install pandoc

In the previous step we installed the Haskell Platform which installs the cabal package manager.

$cabal update
$cabal install pandoc

By default, cabal installs pandoc in ~/.cabal/bin/pandoc. This can be changed, but I just added this to my path and am done with it.

Now you are ready to go.

Working with External Commands in VIM

Posted on: by

Introduction

Some of the power you get from Vim, besides the incredible text processing ability, is that you have access to run command line programs from within the application. If you are running on a Unix based system, that means you have the power of Unix at your disposal as well as the most powerful text editor.

If you develop in PHP, it would be nice to run php lint without having to open another terminal or exiting Vim. If you don’t have permission to write to a file, it would be nice to fix that so you can save all the changes you have made. These are just a few of the common uses, but the sky is the limit.

Vim has this all built right in and it is simple to use.

Take Note

Here is a list of the commands we will use and what they do before I show examples:

  • :! This tells Vim to execute the command that follows in a shell
  • % Not really a command but it references the current file
  • %:p The current file and it’s full path
  • :r Read contents into the current buffer
  • :shell Drop to a command prompt, exit to return to vim

Examples

Get the word count of the current file

:! wc -w %

Get a directory listing and read it into the current buffer

:r ! ls -l

Run PHP lint on the current file

:! php -l %

Conclusion

This provide you with tremendous power all without ever leaving the confines of Vim. Obviously commands can be strung together in any way you can imagine them.

Check File Type in VIM

Posted on: by

If you use snipmate and want to add a new snippet set, you may need to determine what file type vim thinks your working in.

For instance, I wanted to add Markdown snippets. I added all of my files to a markdown.snippets file, but nothing worked. It turns out that vim didn’t know what a .markdown file type was and was reporting it incorrectly as a .conf file. To determine what file type vim thinks a file is run:

:set ft?

This will return what type of file vim thinks you are in. You can adjust your snippets file or add the new filetype.

How to soft wrap text in VIM

Posted on: by

I use markdown for blogging on this site and I don’t like to artificially put in linefeeds in my text. But if you are using VIM the lines get too long if you don’t. So I got to wondering if there was a way to soft wrap the text. It turns out there is and it is pretty simple.

:set wrap linebreak textwidth=0

Thats it. Now the text will wrap based on the size of your window and not some artificial boundary.

VIM CheatSheet

Posted on: by

Cursor movement

  • h – move left
  • j – move down
  • k – move up
  • l – move right
  • w – jump by start of words (punctuation considered words)
  • W – jump by words (spaces separate words)
  • e – jump to end of words (punctuation considered words)
  • E – jump to end of words (no punctuation)
  • b – jump backward by words (punctuation considered words)
  • B – jump backward by words (no punctuation)
  • 0 – (zero) start of line
  • ^ – first non-blank character of line
  • $ – end of line
  • G – Go To command (prefix with number – 5G goes to line 5)

Note: Prefix a cursor movement command with a number to repeat it. For example, 4j moves down 4 lines.

Insert Mode – Inserting/Appending text

  • i – start insert mode at cursor
  • I – insert at the beginning of the line
  • a – append after the cursor
  • A – append at the end of the line
  • o – open (append) blank line below current line (no need to press return)
  • O – open blank line above current line
  • ea – append at end of word
  • Esc – exit insert mode

Editing

  • r – replace a single character (does not use insert mode)
  • J – join line below to the current one
  • cc – change (replace) an entire line
  • cw – change (replace) to the end of word
  • c$ – change (replace) to the end of line
  • ct[char] – change (replace) everything up to but excluding char
  • cf[char] – change (replace) everything up to including char
  • s – delete character at cursor and subsitute text
  • S – delete line at cursor and substitute text (same as cc)
  • xp – transpose two letters (delete and paste, technically)
  • u – undo
  • . – repeat last command

Marking text (visual mode)

  • v – start visual mode, mark lines, then do command (such as y-yank)
  • V – start Linewise visual mode
  • o – move to other end of marked area
  • Ctrl+v – start visual block mode
  • O – move to Other corner of block
  • aw – mark a word
  • ab – a () block (with braces)
  • aB – a {} block (with brackets)
  • ib – inner () block
  • iB – inner {} block
  • Esc – exit visual mode

Visual commands

  • > – shift right
  • < – shift left
  • y – yank (copy) marked text
  • d – delete marked text
  • ~ – switch case

Cut and Paste

  • yy – yank (copy) a line
  • 2yy – yank 2 lines
  • yw – yank word
  • y$ – yank to end of line
  • #yl – yank # number of characters to the right
  • p – put (paste) the clipboard after cursor
  • P – put (paste) before cursor
  • dd – delete (cut) a line
  • dw – delete (cut) the current word
  • x – delete (cut) current character

Exiting

  • :w – write (save) the file, but don’t exit
  • :wq – write (save) and quit
  • :q – quit (fails if anything has changed)
  • :q! – quit and throw away changes

Search/Replace

  • /pattern – search for pattern
  • ?pattern – search backward for pattern
  • n – repeat search in same direction
  • N – repeat search in opposite direction
  • :%s/old/new/g – replace all old with new throughout file
  • :%s/old/new/gc – replace all old with new throughout file with confirmations

Working with multiple files

  • :e filename – Edit a file in a new buffer
  • :sp filename – Open a file in a new buffer and split window
  • ctrl+ws – Split windows
  • ctrl+ww – switch between windows
  • ctrl+wq – Quit a window
  • ctrl+wv – Split windows vertically

Working with buffers

  • :qall – Quit all open buffers
  • :ls (or :buffers) – List all open buffers
  • :bnext (or :bn) – go to next buffer
  • :bprev (of :bp) – go to previous buffer
  • :bd – delete a buffer (close a file)