I took the initial test last Wednesday and managed 32 push ups! A bit more than I thought actually. Today I did the first day of the program for the first week and it wasn’t too bad. I guess the fun will start next week!
July 28, 2008
AOTW 31, 2008: Alice in Chains – Dirt
A brilliant album by a great band! Dirt is a dark album with some pretty strong lyrics.
My three favorite songs:
- Down in a hole
- Would?
- Dirt
July 21, 2008
AOTW 30, 2008: AC/DC – The Razor’s Edge
A great album from a great band: The Razor’s Edge by AC/DC.
My three favorite songs:
- Fire your guns
- The Razor’s Edge
- Thunderstruck
July 18, 2008
One hundred push ups
A while back I read on some blogs about the one hundred push ups challenge. I had somehow forgotten about it, but some guys at work talked about it earlier today and that got me all fired up again. Therefore … I will now try to do one hundred push ups as well! I have no idea how many I can take now but I’m guessing somewhere between 20 and 30 maybe. I post some weekly updates on how I’m doing!
July 15, 2008
July 14, 2008
AOTW 29, 2008: The Doors – L.A. Woman
The album I have chosen this week is my favorite Doors album: L.A. Woman! I really love the sound on this album. It’s gonna be hard just picking out three favorite songs from it, but I’ll give it a shot:
- Love Her Madly (probably my all time favorite Doors song)
- The Changeling
- L.A. Woman
This album sound more blues-like than most of the other Doors albums and thats probably why I like it so much. Read more about the album over at Wikipedia.
July 13, 2008
Enforcing a PHP coding standard using PHP_CodeSniffer – Part 2
Welcome back to this thrilling trilogy! You have arrived at part 2, and today I’m gonna show you how to use some of the many predefined sniffs included in the PHP_CodeSniffer package to make a shiny “new” coding standard! If you haven’t read the first part of this series I suggest you do so right away.
The coding standard we will implement is by no means a complete standard, but it will be a start and you will probably be able to take it further and define some more rules to make it more complete. The standard I will introduce is a subset of the one that Mats and myself are currently using on a secret world-domination project. I’ll define some rules on how to write control structures (if, for, while, foreach, …), some rules on how to write classes and some other nitpickery like:
- Disallow short open tag (<?)
- Max length on the lines in all source files
- No tabs for indenting
All this can be accomplished by using only predefined sniff classes in the different standards from the PHP_CodeSniffer package.
First we’ll take a look at the package and see how it is structured so we know where to find all the sniffs that I’m constantly ranting about.
After unpacking the PHP_CodeSniffer package we enter the CodeSniffer directory and then the Standards directory. There we find the following directories:
- Generic
- MySource
- PEAR
- PHPCS
- Squiz
- Zend
These are all different coding standards that define different sniff classes. Most of these standards use sniffs from other standards as well. If we enter the Zend directory we will find a script called ZendCodingStandard.php that defines the Zend standard. This class only contains one method called getIncludedSniffs that includes sniffs from other standards. If we define a standard with only custom sniffs the class does not need to implement any methods at all.
In the same directory as the class script we see a directory called Sniffs that includes the sniff classes for the current standard. The structure inside the Sniff directory is up to the developer. The only thing we need to ensure is that all scripts containing a sniff class ends in Sniff.php and that the class is named after the file and directory it is in. Example you ask?
In the Sniffs directory in the Zend standard we have three new directories: Debug, Files and NamingConventions. Inside the Files directory we have a couple of sniffs classes. One of them is called LineLengthSniff.php. The class inside this directory is named: Zend_Sniffs_Files_LineLengthSniff. The naming scheme goes something like: <standard>_Sniffs_<optional directory>_<name of sniff>.php.
Now, let’s create our own standard!
The first thing we need to do is to create a directory for our standard inside the Standards directory. Let’s just call it “MyStandard”. Inside this directory we need to create a class for our standard. Name the file MyStandardCodingStandard.php and open it in an editor and create a class for the standard:
<?php
class PHP_CodeSniffer_Standards_MyStandard_MyStandardCodingStandard extends PHP_CodeSniffer_Standards_CodingStandard
{
}
The class does nothing yet except to extend the PHP_CodeSniffer_Standards_CodingStandard class.
The first thing we want to add to our standard is to disallow the short open tag (<?). If we browse the sniff classes we find a sniff called DisallowShortOpenTagSniff.php in the Generic standard. Just what we need! To include sniffs from other standards we will need to add a method called getIncludedSniffs to our class. That method will simply return the sniffs we want to use from other standards. Lets add the DisallowShortOpenTagSniff sniff:
<?php
class PHP_CodeSniffer_Standards_MyStandard_MyStandardCodingStandard extends PHP_CodeSniffer_Standards_CodingStandard
{
public function getIncludedSniffs()
{
return array(
'Generic/Sniffs/PHP/DisallowShortOpenTagSniff.php',
);
}
}
Lets try our our new coding standard! All you need to do is to create a php script class script.php that includes a short open tag. Make something like:
<?
print('foobar');
and run the test:
/usr/bin/php /path/to/PHP_CodeSniffer/scripts/phpcs –standard=MyStandard /path/to/script.php
Hopefully you will get the following output:
FILE: /path/to/script.php -------------------------------------------------------------------------------- FOUND 1 ERROR(S) AND 0 WARNING(S) AFFECTING 1 LINE(S) -------------------------------------------------------------------------------- 1 | ERROR | Short PHP opening tag used. Found "<?" Expected "<?php". --------------------------------------------------------------------------------
Fix the problem and run the test again and you will not get any output, which means everything looks fine. If you get an error when trying to run the command above be sure to change the path to the php bin if it placed somewhere alse, and be sure that the path to the script.php is correct as well.
Lets add some more sniffs to get a more complete standard.
<?php
class PHP_CodeSniffer_Standards_MyStandard_MyStandardCodingStandard extends PHP_CodeSniffer_Standards_CodingStandard
{
public function getIncludedSniffs()
{
return array(
'Generic/Sniffs/PHP/DisallowShortOpenTagSniff.php',
'Generic/Sniffs/Files/LineLengthSniff.php',
'Generic/Sniffs/WhiteSpace/DisallowTabIndentSniff.php',
'PEAR/Sniffs/Classes/ClassDeclarationSniff.php',
'PEAR/Sniffs/ControlStructures/ControlSignatureSniff.php',
);
}
}
Edit the script.php file (or whatever you might have called it) and add some more code:
<?
// This is a long line but it stays under the absolute length, so it only causes a warning.
// This is a longer line that goes over the maximum limit, so it will produce an error. You will need to fix this line to pass the test!
class className {
public function __construct($var = true) {
if ($var)
{
// do something
}
else
{
// do something else
}
}
}
When we run the test again we will get a few more errors and a warning:
FILE: /path/to/script.php
--------------------------------------------------------------------------------
FOUND 7 ERROR(S) AND 1 WARNING(S) AFFECTING 7 LINE(S)
--------------------------------------------------------------------------------
1 | ERROR | Short PHP opening tag used. Found "<?" Expected "<?php".
2 | WARNING | Line exceeds 80 characters; contains 91 characters
3 | ERROR | Line exceeds maximum limit of 100 characters; contains 136
| | characters
5 | ERROR | Opening brace of a class must be on the line after the
| | definition
7 | ERROR | Spaces must be used to indent lines; tabs are not allowed
7 | ERROR | Expected "if (...) {\n"; found "if (...)\n {\n"
8 | ERROR | Spaces must be used to indent lines; tabs are not allowed
11 | ERROR | Expected "} else {\n"; found "}\n else\n {\n"
--------------------------------------------------------------------------------
The errors are pretty self explanatory. The only problem here is that the standard we want to make defines control structures to be written just as we have done in script.php. To be able to fix this we need to extend the PEAR_Sniffs_ControlStructures_ControlSignatureSniff class and edit the regular expressions so they fit our standard. This, and more, in the last and final part of this series which I will try to publish within a week!
July 11, 2008
Zend/PHP Conference & Expo in September
Naveed from work and I will be going to Zendcon in Santa Clara in September. We will be going to San Francisco on September 12th and will be staying there for the weekend.
I’m really looking forward to seeing a small part of SF (can’t get too much done when we only have a couple of days). The conference looks really great as well! The schedule is packed with cool stuff. I haven’t decided on anything yet but I’ll keep you posted.
So if any of my readers are in SF that weekend (Friday 12th and Saturday 13th) and would like to show me some great bars I would be delighted! :)
July 7, 2008
AOTW 28, 2008: Machine Head – Burn My Eyes
This is where it all started! Machine Head’s first album, Burn My Eyes! I think I can say without a doubt in my mind that Machine Head is my all time favorite band. If some of you have read the two previous AOTW posts (week 26 and 27) may be surprised by the genre I have chosen this week. Wikipedia’s entry about Machine Head puts them in the following genres:
- Groove metal
- Thrash metal
- Nu metal (mid career)
What I like most about Machine Head music is the aggressiveness and the groove of it all. Some of the lyrics are also great! Burn My Eyes is not my favorite MH album but I’ll put it on once in a while and it kicks ass, every time!
If you like MH and haven’t seen them live yet, please do so … as fast as you can. I have seen them live several times and they sound absolutely insane! The crowd usually goes bananas (yours truly as well) and the atmosphere is amazing! They are playing in Oslo Spektrum in November, so if you live nearby, go see them! I know I will. Hopefully they will get to be the first band that sounds really amazing there!
My favourite tracks on the Burn My Eyes album are:
- Davidian
- None but my own
- Block
I feel like I’m repeating myself here, but expect more from Machine Head on AOTW! I’ll probably put every album they have made on here (with the exception of one maybe).
Until next time, Cheers!
new Bicycle();
So … what has old Edvartsen been up to the last couple of days? Well … last Friday I picked up my brand new bicycle from the local postal office. I ordered it the week before and it arrived at my place last Tuesday but since I wasn’t home it was sent to the postal office.
My first trip with it was on Saturday when I rode out to Engelsviken for a summer party at a friend. The trip was about 14km and it took me ~32 minutes which was ok I guess considering I hadn’t been sitting on a bike for about 2 years, which my ass kindly reminded me of after about 10 minutes on the not-so-soft seat.
The bike I got is a Full-Dynamix R4.0 20″ alloy frame with Deore XT all over and a Rock Shox Reba Race fork. The colors in the picture below are a bit off. The pink-ish color is actually red.

Full-Dynamix R4.0
The first two trips (to Engelsviken and back home) was not exactly off road and the tires I have on aren’t suited for fast straight riding, but I went for a 15km trip on my old running track today to see if I still had some guts to ride at least a little hard. The frame seems stiff and solid and the fork was very pleasant. I can adjust the stiffness of the fork from a lever on the handlebar (2 positions only) so I can soften it if I need it, and harden it if I need that. Worked like a charm.
Since I forgot to reset the timer on the computer before I took off today (I only reset the distance) I have no idea how long I rode but I will take the same trip a couple of times more this week. I’ll probably even make some graphs of some sort (yeah, I’m a statistics nerd).
My friend Mats has challenged me to enter Grenserittet which is a 80km long race from Strømstad (in Sweden) to Halden (in Norway). The route profile is shown below and the colors represent the type of the surface. Red means a “path” in the wood, blue is asphalt and gray is gravel, so it’s mostly gravel with a couple of pretty steep parts.

Route profile
I’ll do 2-3 shorter trips this week and a longer trip on 55-60km in the weekend to see what kind of shape I am in! If all goes well I’ll enter the “competition”.





