Kristian Lunde

Zend_View and base paths outside the application directory

without comments

I’ve recently been working on a Zend application (v1.11.11) that required several views directories and they had to be located outside the application directory. The documentation says that you can have as many view basePaths as you like, which sounds great. The only problem is that the Zend_Controller_Action_Helper_ViewRenderer checks that the alternative basePaths are located within the default basePath (APPLICATION_PATH “/views/”).

The easiest way of resolving this is to add the full path to the directory like this:

APPLICATION_PATH . '/views/../../themes/my-theme/';

The example below is from my Bootstrap file:

protected function _initView() {
$view = new Zend_View();

$view->setBasePath(APPLICATION_PATH . '/views/../../themes/my-theme/');
$viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer();
return $view;

Written by Kristian Lunde

February 1st, 2012 at 11:57 pm

Automated backups with Amazon S3

with 3 comments

I recently decided that I my half hearted backups to an external drive wasn’t really good enough, so I started to look at alternatives.

Note, this howto is for Mac and *nix system, if you need a windows version please try to google it.

I tried Crash plan, considered a extended dropbox plan but none of them seemed like the correct solution (still I love dropbox, its a great app). I ended up registering an Amazon S3 account.

After a quick google search I found this brilliant little blog post “Using Amazon S3 for personal backups” which describe how to use jetS3t to semi automate the synchronization of the iPhoto library on a Mac OSX.

I am not going to repeat the instructions found on the “Using Amazon S3 for personal backups” blog post, I did however have to do a few minor tweaks to get it to work, I also extended the functionality slightly, to enable a fully automated backup solution.

JetS3t has had a few releases since the “Using Amazon S3 for personal backups” article was written, I downloaded Adding the link of the jetS3t directory to the path in .profile didn’t work for me (I’m on Mac osX 10.6), so I added it to my .bash_profile file. You can find .bash_profile in /Users/YOUR-USERNAME/, you’ll have to replace YOUR-USERNAME with your proper username of course. Other than that I followed the examples in “Using Amazon S3 for personal backups”.

Once that was in place and worked properly I started to add some custom scripts.

1. Create a scripts directory in your home directory
2. Create a logs directory in the scripts directory

  1.  cd
  2. mkdir scripts
  3. mkdir scripts/logs

2. Navigate to your scripts directory and create a file.

  1. cd scripts
  2. touch

3. Use your favourite text editor to add the following code to the script

  1. #!/bin/bash
  3. #Backup iPhoto
  4. UP YOUR-IPHOTO-BUCKET /Users/YOUR-USERNAME/Pictures/iPhoto\ Library >> logs/amazon-s3-iphoto-backup.log
  6. #Backup Documents
  7. UP YOUR-DOCUMENTS-BUCKET /Users/YOUR-USERNAME/Documents >> logs/amazon-s3-document-backup.log

Replace YOUR-IPHOTO-BUCKET with the amazon S3 bucket you want to use, and replace YOUR-USERNAME with your username on your mac or *nix system. We pipe the output from the sync process to files in the logs directory, one log file for the iphoto and one log file for the documents process.

4. Edit your crontab. The crontab is a file where you can add files that you want to automatically execute on a regular basis.

  1. crontab -e

5. Add the script to your crontab, I’ve chosen to run it once a week at 20:00 every Sunday, which is expressed by (0 20 * * 0).

  1.  0 20 *  * 0 /Users/<em>YOUR-USERNAME</em>/scripts/

6. Save your cronjob

There you go, now you’ll backup your iPhoto library and Documents every Sunday at 20:00 as long as your computer is turned on and online. You can of course tweak when and how often you want to sync to Amazon S3, you can read more about scheduling cron jobs at wikipedia

Written by Kristian Lunde

May 21st, 2011 at 9:04 pm

Posted in Mac,Misc,Real Life

Tagged with , ,

Review: PHP5 Social Networking

without comments

Packt publishing contacted me couple of months back, asking me if I was interested in reviewing “PHP5 Social Networking” by Michael Peacock. The title intrigued me as I’ve built several social networking applications and I was interested in seeing Michaels approach to this.

The first chapter starts by defining social networking, it looks at the most known social networks out there. It also reviews available social network software out there such as Elgg, drupal and joomla. The approach taken in this book is to roll out an own application from scratch with no base framework. The basics of this framework is described in chapter 2 and 3.

Chapter 4 to 10 deals with the core elements of social networks, such as friends, friend requests, statuses, streams, messaging and events. Each chapter describe how to the functionality should work, a detailed implementation plan is shown and ideas for further development is discussed.

Chapter 11 show the reader how the application easily can support an API, I really like that Michael chose to add this chapter as I think it is a crucial element to any social network that is going to go somewhere.

Maintenance, security and deployment is discussed in chapter 12. I find this chapter a bit odd as it describe very basic steps to get the application up and running on the production server. I would have liked to see more about automated deployment in this chapter.

All social network sites need to get users and hopefully generate some revenue, this is the topic of chapter 13 which describe solutions and approaches to marketing, SEO techniques and monetization.

The last chapter is “Planning for growth” a very important chapter in my mind. It describes approaches for profiling of web applications, server scaling, redundancy and more.

It is a well written book with good examples and it describes the build of the application in detail so the user easily can follow and copy the examples. I would definitely recommend this book to novice developers as it is a good introduction to a lot of good programming practices. It can also be a decent book to read if you are an experienced developer that want to learn more about the core concepts of building a social network.

Written by Kristian Lunde

May 6th, 2011 at 8:34 pm

Reviewing “PHP 5 Social Networking”

without comments

Packt Publishing has asked me to review Michael Peacocks “PHP 5 Social Networking” something I’ve happily agreed to do. I am expecting to receive the book soon and look forward to read it. Social networks and PHP is something I’ve worked quite a bit with and I am interested to see Michaels take on this topic.

I’ll be posting the review as soon as I’ve finished the book.

Written by Kristian Lunde

February 8th, 2011 at 12:51 pm

Lunde Development – In Business

with 2 comments

Say hi to Lunde Development.

The 3rd of August 2010 was the first official day of my own company, Lunde Development. I had at that point already been working with the company ideas and proposals for a while and was able to hit the ground running with my first project already secured. Since then I’ve had several cool clients such as hoverState a high-end US based digital agency, the Newcastle based software company Band-X and Sharpe Recruitment a recruitment agency in Newcastle. You can read more about these projects on my portfolio page.

The future looks bright for Lunde Development and I enjoy every second of running my own business, it is challenging, I learn so much and most important of all, it is fun.

Please check out

You know where to go if you need a new web site, a piece of software or consultancy ;)

Written by Kristian Lunde

October 5th, 2010 at 8:54 am

Posted in Misc,Real Life,web

Zend_Input_Filter and the Alnum Validator

without comments

The Zend_Input_Filter is a very useful tool when you need to validate and filter the input to your application. It allows you to both filter and validate the input without a lot of hassle. One of the cool features it has is that it allows you to add the validators you need and meta commands to each validator. For instance you can set an Alnum validator to allow empty fields, set a default text and so on.

I came over this annoying issue the other day when I tried to setup the Alnum validator to allow white spaces and have a few meta commands attached to the validator chain. The manual says that you can do this:

  1. $validators = array(
  2.     'month'   => array(
  3.         'Digits',                // string
  4.         new Zend_Validate_Int(), // object instance
  5.         array('Between', 1, 12)  // string with constructor arguments
  6.     )
  7. );

Which I assumed would also work like this:

  1. $validators = array(
  2.     'name'   => array(
  3.         'Alnum',                
  4.         new Zend_Validate_Alnum(true), //allow whitespaces
  5.        'default' => '',  //meta command 1
  6.        'presence' => 'required', //meta command 2
  7.     )
  8. );

This does not work though. You need to remove the validator type string and replace it with an instance of the Zend_Validate_Alnum validator to get it to accept whitespaces and meta commands. This is the right way to do it:

  1. $validators = array(
  2.     'name'   => array(            
  3.         new Zend_Validate_Alnum(true), //allow whitespaces
  4.        'default' => '', //meta command 1
  5.        'presence' => 'required', //meta command 2
  6.     )
  7. );

The entire script ends up looking like this:

  2. $filters = array('name' => 'StringTrim');
  3. $validators =  array(
  4.     'name'   => array(            
  5.         new Zend_Validate_Alnum(true), //allow whitespaces
  6.        'default' => '',
  7.        'presence' => 'required',
  8.     )
  9. );
  11. $input = new Zend_Input_Filter($filter, $input, $this->getRequest()->getParams());

Written by Kristian Lunde

July 18th, 2010 at 9:00 pm

The big move

with 6 comments

There is a lot of things going right now. We (@ramonahz, my daughter and myself) have decided to move back to Norway. We have thought about this for a while now and finally made the decision a few weeks ago. The main reason for moving back is that we want to be closer to our family, and not restrict our daughter to only see her grandparents a few times a year.

The move has affected my work slightly, I have resigned from my position at MySapient LTD and are now looking to do some freelance work from Norway. I also have a few other interesting things coming up, but I’ll leave that for a later blog post.

We have already started the process of moving back, and we’ll be leaving Newcastle and the UK on the 26th of July. We have spent almost 2 years in Newcastle, I have met some amazing people during these past two years, made some good friends and worked for two really cool companies. I am really going to miss living here, but hey, I’ll be back to visit soon.

Arrivederci Newcastle.

Written by Kristian Lunde

June 19th, 2010 at 6:00 pm

Posted in Real Life

Tagged with , ,

CentOS, where is all my memory gone?

with 3 comments

I encountered a rather strange issue on one of MySapients CentOS 5 servers the other day, the server seemed to run fine, without any issues what so ever, but it seem to run very low on memory. In fact it only had 150MB memory available of a total 4GB.

This obviously caused me a bit of a worry, but after some digging around I found the answer, linux is borrowing unused memory to do disk caching. Memory is automatically reassigned when the server needs to allocate memory to other services, in other words there is nothing to worry about.

There is a good site about this describing this functionality in more detail, you can read it at:

Written by Kristian Lunde

January 15th, 2010 at 10:25 pm

Posted in Linux

My Bookshelf & openbook

without comments

Yesterday I installed the openbook plugin for wordpress on this site. My intentions was to build a “My bookshelf” page similar to what Mats Lindh and Trond Huso have on their sites.

I installed the plugin without any problems but the layout was a bit nasty. I don’t know if that was because of the theme I am running on this site or if the openbook markup was messed up. Anyway I rewrote the html and css for the openbooks template on its configuration page and added some custom css to the site to get it working.

This is my openbook template:

  1. <li>
  2. <div class="medium">[OB_COVER_MEDIUM]</div>
  3. <div class="description">
  4. <div class="title">[OB_TITLE]</div>
  5. <div class="meta-1">Written by: [OB_AUTHORS]</div>
  6. <div class="publisher-year">[OB_PUBLISHER] [OB_PUBLISHYEAR]</div>
  8. </div>
  9. <div class="clearboth"></div>
  10. </li>

This is the css I added:

  1. ul.books {
  2.  list-style-type: none;
  3. }
  5. ul.books li {
  6.  border-bottom: 1px solid #ccc;
  7.  margin-bottom: 15px;
  8.  padding-bottom: 15px;
  9. }
  11. ul.books li div.medium {
  12.  float:left;
  13.  margin-right: 10px;
  14. }
  16. ul.books li div.medium img {
  17.  width:120px;
  18. }
  20. ul.books li div.description {
  21.  float: left;
  22.  width: 450px;
  23. }
  25. ul.books li div.description div {
  26.  font-size: 11px;
  27.  padding-top: 5px;
  28. }
  30. ul.books li div.clearboth {
  31.  clear: both;
  32. }

At last I added this custom html in the “my bookshelf” page:

  1. <ul class="books">
  2. [No Book Data for this Book Number]
  4. [No Book Data for this Book Number]
  6. [No Book Data for this Book Number]
  8. </ul>

You can see the result here: My Bookshelf .

Written by Kristian Lunde

November 22nd, 2009 at 11:19 pm

Posted in web,web development,Wordpress

Tagged with ,

Great article on Super Columns and Cassandra

without comments

This is a great article describing super columns and the general structure of cassandra. A must read for NoSQL newbies.

Written by Kristian Lunde

November 21st, 2009 at 4:37 pm

Posted in NoSQL

Tagged with ,

Get Adobe Flash player