git-daemon Startup Script 2

Posted by Vic Cherubini on February 27, 2010

This is a valid article, and is considered technically accurate up to Feb. 27, 2010

I’m hosting Jolt’s Git repository on my server rather than using Github. To do this, I’m using Gitosis, a small and efficient program in Python to manage your Git repositories. The brilliant thing about Gitosis is it uses Git to manage your repositories. You can learn to properly host your Git repositories quickly and easily.

What that article doesn’t mention is how to start up and shutdown the git-daemon properly on an Ubuntu system. The git-daemon program is what is used to serve a Git repository. I wrote a small init script to handle starting and stopping git-daemon. Place this script in /etc/init.d/ as gitd and make sure it is executable (chmod +x gitd).

#!/bin/sh
 
BIN=git-daemon
USER=git
GITDIR=/home/git
REPODIR=$GITDIR/repositories/
PIDFILE=$GITDIR/.git-daemon-pid
 
case "$1" in
  # Start command
  start)
    echo "Starting $BIN"
    sudo -u $USER $BIN --base-path=$REPODIR --pid-file=$PIDFILE &
    echo "$BIN started successfully"
  ;;
 
  # Stop command
  stop)
    echo "Stopping $BIN"
    if [ -f $PIDFILE ]; then
      sudo -u $USER kill -9 `cat $PIDFILE`
      sudo -u $USER rm -f $PIDFILE
    fi
    echo "$BIN stopped successfully"
  ;;
 
  *)
    echo "Usage: /etc/init.d/gitd {start|stop}"
    exit 1
  ;;
esac
 
exit 0

Change the directories to wherever you have Gitosis installed. Install the script by running update-rc.d.

update-rc.d gitd defaults

And now it will be executed on startup and shutdown.

Nope, that’s what I charge

Posted by Vic Cherubini on February 24, 2010

I do freelance work from time to time to pick up some extra money for my family. It’s generally not much, just small changes here and there on mostly existing websites. Rarely I write software from scratch for a client. I always get a surprised look when I explain how much I charge. I generally use my hourly rate to determine an overall cost for the project as well (if the project is very large, I’ll give an estimated project price). I’ll do my best to determine the number of hours I think it’ll take to complete it and multiply it by my hourly rate.

My last bid was for changing some functionality of an existing shopping cart built on Joomla and VirtueCart. I’m not familiar with either of those platforms (from a developers perspective, I’ve taken cursory glances at both), so doing the changes the client wanted was going to take longer. That learning experience will be passed on to the client. When doing freelance work, you should treat yourself as an individual corporation (and if you’re not incorporated, you should be). Corporations generally don’t do things for free, and you shouldn’t either.

I also build software correctly. Even if I’m just working alone, I try to maintain an agile approach. I write tests (this is definitely my weak spot, but I’m rapidly improving), I track bugs, I use source control. If you’re not doing these things, you’re not building software correctly. That work is time passed on to the client. If you, the client, wish for properly developed software, you will have to pay for it.

VirtueCart is horribly written. I can tell it’s horribly written just by glancing at it. I’ve been writing PHP for 10 years now, I know what crap PHP looks like quickly (conversely, I know what great PHP looks like quickly, and it’s very possible to write great PHP). The code [VirtueCart] is typical PHP garbage, very little coding standards, globals littered everywhere, no true object oriented design, etc. (Joomla has a test suite, and seems much better architected). There’s very little design that went into VirtueCart’s development, and it appears to be a horrible experience to work with. Having to work in that environment is going to cost the customer. Some refactoring will be required to make the software bearable, which will cost the client.

In the end, I lost the bid (fortunately). What was unfortunate was this was functionality the customer really wanted. This means they’ll approach a cheaper developer to get it completed. Hopefully, the developer maintains a high level of development standards, but it seems like in the web world, that just doesn’t happen often.

When I first started to learn about agile approaches and test driven development, the ideas sounded absurd: no client is going to pay for that! They throw a fit when it costs them even the slightest change. But that’s not how it works. If you wish to have properly developed software, you need to spend the money to get it. There is too much shit out there, and it’s only going to get worse unless developers become active, passionate, and involved in their craft. The client does not have to understand or know you’re writing unit tests, they simply need to know how much it will cost them.

Software development should not be a “thing I do for a living”. It should be your passion. If it’s not, please leave the industry and find something else to do. I charge what I do because software development is my passion, and not one I take lightly.

So, yes, that is what I charge, no, I’m not changing it: take it or leave it.

Jolt Interceptors

Posted by Vic Cherubini on February 23, 2010

This is a valid article, and is considered technically accurate up to Feb. 22, 2010

Interceptors will be a new feature added to Jolt. When dealing with a classic Model-View Controller, the Router should determine both the type of content coming in (via the Content-Type header), and the type of data the client with accept (via the Accept header).

If an HTTP/1.1 request contains these headers, the RESTful application should respond correctly.

Content-Type: text/json
Accept: text/json

The MIME-type application/json is also valid, I believe. The Router needs to interpret this headers and tell the Controller how to respond accordingly. Of course, the default Content-Type and Accept headers are text/html in Jolt, but in the cases when they are different, what should be done?

The concept of Interceptors are introduced. An Interceptor takes the resulting object from the Controller and determines what View to send it to and how. By default, an Interceptor will take the entire Model and turn it into the appropriate type.

class User_Controller extends Jolt_Controller {
  public function bookListGet($user_id) {
    // Assuming the Accept header is text/json, Content-Type is normal text/html
    $user = new User($user_id);
    $book_list = $user->getBookList();
 
    // Render accordingly
    $this->book_list = $book_list;
    $this->render('book-list');
  }
}

The render() method will know what type of content the client accepts. If it’s the default HTML, that View will be loaded, rendered, and returned. In this example, the JSON Interceptor would turn the $book_list object (or array) into a JSON object and return that to the client.

What if the resource were to only return a single object? How might that look?

class Post_Controller extends Jolt_Controller {
  public function postGet($post_id) {
    $post = new Post($post_id);
 
    $this->post = $post;
    $this->render('post');
  }
}

The client would receive a JSON object that contains the post data.

{"date_create":1266926552,"date_modify":0,"title":"My First Post","content":"Here is the body of my first post."}

This is a fairly straight-forward example, but what if you didn’t want the date_create or date_modify fields returned in the object? The default JSON Interceptor does a 1:1 conversion between a PHP object and JSON.

An extended Interceptor would be written for that resource that would remove those fields.

class Post_Interceptor extends Jolt_Interceptor_Json {
  public function run() {
    // $this->post is the object from above passed into here.
    $this->post->remove('date_create', 'date_modify');
 
    // Encode everything to JSON and return it to the client.
    parent::run();
  }
}

The above are just examples as I’m fleshing out Jolt, but this should allow for systems that can be quickly and easily built. Basic models will easily handle themselves. More complex models may require further action; an Interceptor could run additional operations on an object before it was returned to the client.

As Jolt becomes more mature, I promise the methods above will change; this should give you an idea of how a small system would work.

Artisan System Becomes Jolt 2

Posted by Vic Cherubini on February 22, 2010

This is a valid article, and is considered technically accurate up to Feb. 22, 2010

I released Artisan System in November 2008. Ever since I released it, I was never crazy about the name. I always felt like it would be difficult for developers to say they used Artisan System. I intended it to be a “system” level framework, where it handles many of the system requirements of Internet software. It has since morphed from there to something more, so I feel its time for a name change.

Coming up with a new name is very difficult. It seems like every other framework out there has a great name, except mine. I tried going the ancient god’s route, and thought Gnosis was good, but there are already plenty of Open Source projects named that, one of which is related to PHP development. So that was out. I found a Hindu god of knowledge and creativity, Saraswati, and thought about the name Swati. It was unique, easy to pronounce and spell, but after talking to ZDC, I determined it wasn’t a fitting name.

Ultimately stuck, I turned to my wife. I explained to her my dilemma, and within about three or four attempts, she came up with Jolt. I loved it. Easy to spell, four letters that mean a lot. Speed, intensity. The things I wan to convey with my framework.

Jolt.com is, of course, taken (and for sale consequently). After coming up with a name is finding the right domain to go along with it. This one was easier than expected. I like the name “core” associated with my projects since I want Jolt to be the core framework you use for your project. Unfortunately joltcore.com is taken, but not used for anything. Joltcore.org was free, and since this is a non-project Open Source, a .org works great for it.

I’ve reserved a sizable Linode server for hosting. Issue Tracking, Wiki, Technical Docs, Mail, Git, and the main website will be hosted there. Copies of Jira and Confluence will be used for the issue tracker and Wiki, respectively. I’ll be using Gitosis for Git hosting, and Doxygen will be used for documentation.

This is an exciting time for my software. With a rename comes an entirely new roadmap and scope for Jolt.

What’s New For Jolt

Jolt aims to be an entire solution for building Web based software quickly and painlessly. Jolt will support an entirely RESTful interface for building a front facing website or an API.

More will announced later this week as I develop the roadmap and timeline even more. If you’re a developer and wish to contribute, I’d love to hear from you.

I’m very excited about this change and what it will bring to software development. Who knows, maybe I’ll even win a Jolt Award.

Happy hacking.

Compiling HipHop-PHP on Ubuntu 9.10 64bit 15

Posted by Vic Cherubini on February 21, 2010

This is a valid article, and is considered technically accurate up to Feb. 22, 2010

Facebook recently open-sourced their new software, HipHop-PHP. HPHP compiles PHP source to very efficient C++, which is then compiled to an executable binary. After a few hiccups, building HPHP is surprisingly easy. HPHP must be compiled on a 64bit platform. If you only have a 32bit platform and you really want to play with it, set up a VM at Slicehost or Linode and compile it there (if you have a 32bit platform, you can’t install a 64bit VM). I eventually used my Linode account and built it there.

First, you’ll need to install Git if you haven’t already.

# You might as well drop into root. You'll be doing everything as root
# so I won't prepend everything with sudo.
sudo su
apt-get install git-core

Ubuntu comes with a handy package called build-essential which installs all of the tools you need (make, gcc, g++, and more) to build software from scratch.

apt-get install build-essential

Navigate to the /opt directory and clone the project from Github.

cd /opt
git clone git://github.com/facebook/hiphop-php.git

It comes with another Git module, libmbfl, which will cause you a lot of headaches if you don’t initialize it.

cd hiphop-php
git submodule init
git submodule update
cd ..

HPHP requires a patched version of cURL and libevent, so you’ll have to patch and compile those normally.

# cURL first, this will be installed into /usr/local/lib/,
# manually change the prefix in ./configure to install it elsewhere
wget http://curl.haxx.se/download/curl-7.20.0.tar.gz
tar -xvzf curl-7.20.0.tar.gz
cd curl-7.20.0
patch -p0 < ../hiphop-php/src/third_party/libcurl.fb-changes.diff
./configure
make && make install
cd ..
# libevent will be installed to /usr/local/lib/,
# manually change the prefix in ./configure to install it elsewhere
wget http://www.monkey.org/~provos/libevent-1.4.13-stable.tar.gz
tar -xvzf libevent-1.4.13-stable.tar.gz
cd libevent-1.4.13-stable
patch -p0 < ../hiphop-php/src/third_party/libevent.fb-changes.diff
./configure
make && make install
cd ..

HPHP requires libicu, a Unicode library. However, it requires 4.2+, and the latest version in the Ubuntu repositories is 4.0, so you’ll have to manually compile that as well.

# libicu will be installed to /usr/local/lib/,
# manually change the prefix in ./configure to install it elsewhere
wget http://download.icu-project.org/files/icu4c/4.2.1/icu4c-4_2_1-src.tgz
tar -xvzf icu4c-4_2_1-src.tgz
cd icu/source
./configure
make && make install
cd ..

Oniguruma is a Unicode regular expression library that you’ll need to compile and install.

# oniguruma first, this will be installed into /usr/local/lib/,
# manually change the prefix in ./configure to install it elsewhere
wget http://www.geocities.jp/kosako3/oniguruma/archive/onig-5.9.2.tar.gz
tar -xvzf onig-5.9.2.tar.gz
cd onig-5.9.2
./configure
make && make install
cd ..

Head back into the hiphop-php source tree. We’ll be able to install the rest of the required libraries from Ubuntu’s repository.

cd hiphop-php
 
# Libraries
apt-get install cmake flex bison re2c libmysqlclient16 libmysqlclient16-dev libxml2 libxml2-dev libmcrypt4 libmcrypt-dev binutils binutils-dev libcap2 libcap2-dev libgd2-xpm libgd2-xpm-dev zlibc libtbb2 libtbb-dev libpcre3 libpcre3-dev libpcre++-dev libssl0.9.8 libssl-dev
 
# Boost, in reality you do not need *all* of Boost, only a few
# libraries, but you might as well install all of it to play with.
apt-get install libboost-date-time1.40.0 libboost-date-time1.40-dev libboost-filesystem1.40.0 libboost-filesystem1.40-dev libboost-graph1.40.0 libboost-graph1.40-dev libboost-graph-parallel1.40.0 libboost-graph-parallel1.40-dev libboost-iostreams1.40.0 libboost-iostreams1.40-dev libboost-math1.40.0 libboost-math1.40-dev libboost-mpi1.40.0 libboost-mpi1.40-dev libboost-program-options1.40.0 libboost-program-options1.40-dev libboost-python1.40.0 libboost-python1.40-dev libboost-regex1.40.0 libboost-regex1.40-dev libboost-serialization1.40.0 libboost-serialization1.40-dev libboost-signals1.40.0 libboost-signals1.40-dev libboost-system1.40.0 libboost-system1.40-dev libboost-test1.40.0 libboost-test1.40-dev libboost-thread1.40.0 libboost-thread1.40-dev libboost-wave1.40.0 libboost-wave1.40-dev

Define some environment variables for compiling.

# Ensure you are in /opt/hiphop-php/ at this point
export CMAKE_PREFIX_PATH=/usr/local
export HPHP_HOME=`pwd`
export HPHP_LIB=`pwd`/bin

Compile and install everything.

cmake .
 
# Assuming cmake doesn't give you any errors.
make && make install

After you’ve compiled HPHP, the binary is located in hiphop-php/src/hphp/ and is aptly named hphp. From here, you can follow the instructions on http://wiki.github.com/facebook/hiphop-php/running-hiphop on how to use it.

So far, it’s very promising. Of course, you probably don’t fit the use-case for this. Regardless, I believe this will take PHP application in new directions. No longer will you need a Zend Encoder or Optimizer, application deployment can be installing a single binary, and it will be possible for companies to sell their applications without giving away the source code. Everything I release will still be entirely Open Source, however, a HPHP binary may be attached for easy deployment.

Validating Articles

Posted by Vic Cherubini on February 21, 2010

I recently read an article about a problem with blogging: very outdated and inaccurate articles (particularly technical articles) are still indexed by Google, so when you’re browsing for a solution to your answer, and you find an article from 2001, you end up becoming more frustrated.

Because this is a technically oriented website, I’ll be validating all of my articles, and doing it on a routine basis. You’ll see a banner above each article explaining that it is still technically valid should you happen onto it by way of a search engine.

Valid articles will see a describing the date the article is valid until. If the current date is after that date, that doesn’t mean the article isn’t invalid, simply that it hasn’t been validated since that time.

This is a valid article, and is considered technically accurate up to Feb. 21, 2010

Invalid articles also have a header describing them.

This article is no longer valid as of Feb. 21, 2010

HipHop PHP From Facebook Released

Posted by Vic Cherubini on February 20, 2010

This is a valid article, and is considered technically accurate up to Feb. 21, 2010

Facebook has officially released HipHop for PHP on GitHub. I’ve spent all morning attempting to compile it on my local machine (Ubuntu 9.10 32bit) with no luck. I’ll try another computer in a moment, and then post a detailed instruction set on how to build it fully.

If you’re not familiar with compiling programs on a Linux environment, it definitely has a steep learning curve.

Stay around for updates throughout the day.

Update: You must compile this on a 64bit platform.

Subversion to add DVCS like features

Posted by Vic Cherubini on February 19, 2010

This is a valid article, and is considered technically accurate up to Feb. 21, 2010

According to a new press release from Wandisco, a company associated with the Subversion project, they are working on Subversion 1.7 to “provide the groundwork to allow offline commits and other features associated with Distributed Version Control Systems (DVCS) such as Git and Mercurial.”

I just want to point out that I called this a while ago.

Unstable branch for Artisan System Updates

Posted by Vic Cherubini on February 19, 2010

This is a valid article, and is considered technically accurate up to Feb. 21, 2010

This morning I made some changes to the unstable branch in Artisan System. I added the following directories:

  • Docs
  • Framework
  • Hooks
  • TestSuite

A new ArtisanSystem.dox file was placed in Docs to auto generate the Doxygen documentation. Framework is where the entire framework will reside (and it will be split back up into sub-directories). Hooks are Git hooks, and TestSuite obviously holds the new tests for Artisan System.

The unstable branch is located at Github: http://github.com/leftnode/Artisan-System/tree/unstable

New Roadmap for Artisan System

Posted by Vic Cherubini on February 18, 2010

This is a valid article, and is considered technically accurate up to Feb. 21, 2010

I recently rejoined the ranks of the working at a great company. As a result, I am not as concerned about trying to get contract and freelance work and I can now concentrate on my personal projects more. In the last 6 months I spent a lot of time working on other software, and while it paid the bills, I’m anxious to get back to my own.

My first real piece of Open Source software I wrote is my PHP Framework Artisan System. I haven’t had a chance to work on much since it was originally released, only changing a few things and undergoing some reconstruction since. I’ve now written a new roadmap for 2010 in the direction I’d like to take Artisan System.

2010 is going to bring a new change to Artisan System, and the roadmap includes the following items.

  • System fully under test (SUT). A new test suite will be written for all existing functionality, and new development will be done through tests.
  • Controller mechanism will be made fully RESTful. You will be able to access Controllers through a URI via PUT and DELETE methods. GET will list all items in a collection, PUT will update an item in a collection, POST will create a new item in a collection, and DELETE will delete an item in a collection.
  • A new design pattern called Interceptors will be introduced. Interceptors intercept the output of objects from a Controller to return them in the format that the Accept header asks for. HTML will be the default, but XML, JSON, JavaScript or other formats will also be allowed. Thus, if you wanted to return an object from a Controller that only includes a certain number of fields, a custom Interceptor could handle that, rather than having the Controller handle it.
  • The Controllers will read the Content-Type header to determine the format of the input.
  • The appropriate HTTP response code will be sent after a call to a URI. 200 for HTTP OK, 404 for not found, etc.
  • Everything will be time tested and sped up if necessary.
  • My other framework, DataModeler, will be integrated with Artisan System. They’ll become a single framework.
  • Redis support, and potentially support for other NoSQL databases will be added.
  • The codebase will be Doxygenated.
  • The Router will support routing tables for vanity URL’s.
  • A new website and community will be launched to create a strong developer community. The website will include a bug tracker, wiki, and forum.
  • Videos, screencasts, tutorials, and podcasts will be released to help support this effort.

I’m really looking forward to seeing what I can create. Of course, I’ll appreciate any help I can get. You can fork the Artisan System project on Github and help develop it. After I get the new website up and running, you’ll be able to access the bug tracker, wiki, and forum. From there, we’ll correspond development efforts.