I received an email from a developer the other day, who had forked the repository for my “IIS Express Here” shell extension on GitHub [editors note – no longer available]. He had noticed there was no license information available in the project, so asked if I could either add a license, or give him written permission to adapt my code and share it to others (as is the spirit of GitHub and OSS).

To be honest, this wasn’t something I’d thought about before, and was a bit of an oversight on my part. I’d not really considered the need to add explicit licenses to my repositories. After all, the code is out there anyway – it’s open to use on GitHub, and I’ve often shared it on this blogā€¦ if someone wanted to copy the code, they could, right?

Unfortunately, this creates a grey-area, which some are naturally uncomfortable with. Can I use this code in something else? Can I modify it at all? Do I have to pay royalties if I do?

But licensing is hard, isn’t it? All the different types, with different caveats, liabilities, and legal mumbo-jumboā€¦ well, yes, it can be hard. The good folks at GitHub have a solution:Ā ChooseALicense.com is attempting to demystify open source licenses so you can pick the right one for your project. More than this, when you create a new repository on GitHub, the site will ask if you want to add a template license during the initialisation process:

repo_licenses

Coming back to the developer who emailed me – I mailed him back to let him know that IIS Express Here is now licensed under the MITĀ license. This fits best with how I see the code and projects I share on this blog (unless noted otherwise) – free for anyone else to use, but with no warranty, so if something goes wrong then I’m not liable and it’s not my responsibility to fix it. I haven’t got around to updating all of my repos with licenses, as I’m evaluating each one in turn, based on my goals and even whether the project is going to archived.

ChooseALicense.com

This is just a bunch of stuff I’ve wanted to link to over the last few days, but didn’t get around to doing individual link posts for:

Did you know you can use custom PHP extensions on Heroku? Neither did I, cos I can’t find it in the documentation. But you can:

https://gist.github.com/1288447

I came across this while searching for a way or workaround to use the MongoDB PECL extension on Heroku (don’t get me started on that…).

If you can’t be bothered checking the link, the summary is this:

  1. Create a folder in your app called ‘ext’ or similar.
  2. Copy your extension into this folder.
  3. Create a php.ini file with the following contents:
    extension_dir = "/app/www/ext/"
    extension=mongo.so
    
  4. Deploy

the CodeIgniter logoMost of my small personal projects tend to get built with CodeIgniter (CI), which is a simple to use, fast, lightweight PHP5 MVC framework.

the Facebook logoFor a while now I’ve had an itch to build something fun against the Facebook API so I can start learning how Open Graph works, and as a primer to building a “proper” Facebook integrated application. I also realised I hadn’t actually tried using CodeIgniter 2.x since it was released (quite some time ago). With an abundance of free time this weekend it seemed like the perfect time to get hacking!

Before I could build anything I would need to know one thing: just how do you connect a CodeIgniter app to Facebook?

Continue reading

The beauty of web development is that, ultimately, the code behind it is simple. Yes, web apps have taken leaps and bounds over the last few years, and are capable of so much more than ever before, but lets face it ā€“ weā€™re not exactly writing DNA sequencers. Yet.

It frustrates me when I find someone has made life difficult for themselves or the person who will inherit their code, by using the wrong tool for the job. Iā€™m not claiming to be a saint here either ā€“ I often look back at some of my own code and shudder (it helps keep me right in the future!).

Consider the following snippet, from the View (presentation) file of anĀ MVCĀ app I inherited:

<?php
echo "<h1>$category</h1>";
echo "<h3>$company ($name)</h3>";
echo "<p>";
echo "$address<br />";
echo "$town<br />";
echo "$city<br />";
echo "$post_code<br />";
echo "$phone<br />";
echo "$email<br />";
echo "</p>";
echo "<br />";
echo "<br />";
?>

PHP needs to be used to output the data passed from the Controller, yes, but thereā€™s no need for it to be outputting the HTML too. Let HTML itself worry about that!

<h1><?= $category ?></h1>
<div>
<h3><?= $company ?> (<span><?= $name ?></span>)</h3>
<address>
<span><?= $address ?></span>
<span><?= $town ?></span>
<span><?= $city ?></span>
<span><?= $post_code ?></span>
<span><?= $phone ?> </span>
<span><?= $email ?></span>
</address>
</div>

I donā€™t know about you, but the HTML-based version above is easier to follow and spot coding errors. No doubt someone will point out thereā€™s more HTML tags/bytes in this example than the first, but that is because I coded it with semantics andĀ microformatsĀ in mind; add in the right classes and you suddenly have aĀ hCard.

Possibly more importantly in my mind, the HTML example is easier to follow for someone who isnā€™t PHP literate, like many front-end designers I know.

Iā€™m picking on this example as itā€™s the most recent Iā€™ve come across, and the first to come hand. Itā€™s not the first example Iā€™ve come across, it wonā€™t be the last, and itā€™s certainly not the worst!

Pure, simple HTML can be a wondrous thing. Lets try not to spoil it by abusing it with our fancy server-side languages. K.I.S.S!

I loves me someĀ jQueryĀ ā€“ without it I probably wouldnā€™t write any JavaScript at all (seriously, IĀ hateĀ the stuff). Anyway, today I needed to add some ā€œopen in new windowā€ links to an internal application using jQuery. Being the Standardista I am, I wanted to make itĀ a)Accessible, andĀ b)Ā UnobtrusiveĀ . If the user has JavaScript disabled (it happens, even on ā€œcontrolledā€, intranet environments), the link should just go to the new page anyway ā€” new window be damned.

My first attempt (below) didnā€™t work as expected. The following code takes allĀ <a>Ā tags with a class of ā€œnewwindowā€ and applies an onclick event to open a new window.

$(function(){
$('a.newwindow').click(function(){
var w = window.open($(this).href(), 'newWindow', '');
return false;
});
});

Nothing would happen with the above, because of theĀ return false;. RemovingĀ return false;Ā would open a new window, but also send the opening window to the new page. In the end, the following worked the way I wanted:

$(function(){
$('a.newwindow').click(function(){
var w = newWindow($(this).href(), 'newWindow', '');
return false;
});
});
function newWindow(url, wName, opts){
w = window.open(url, wName, opts);
return true;
}

Basically the ā€œheavy liftingā€ was moved to a seperate function. Itā€™s slightly longer to type, but not exactly finger-breaking stuff. No doubt some bright-spark could tell me anĀ even betterway (feel free!), but thisā€™ll do for now.

So Iā€™m writing my first serious bit ofĀ PHPĀ inĀ aaaages. This last few months, Iā€™ve either been adaptingĀ existingĀ systemsĀ to fit the bill, or Iā€™ve been writingĀ ASPĀ (all while learnngĀ Ruby on Rails).

I feel like Iā€™ve been out of the game. Before I fell out of writing my ownĀ PHPĀ every day, I was using theĀ CakePHPĀ framework. CakePHP is a wonderful framework. It greatly speeds up development and makes things so much easier.

Unfortunately, frameworks are only of use to the developer or your customer has someone who knows what theyā€™re doing to set up everything for them. When youā€™re building a product for those who arenā€™t so technically minded, giving them something like CakePHP/Rails/Django, etc, to install ā€“Ā beforeĀ they can use the product ā€“ is a big no-no1.

So anyway, Iā€™m writing this new product. Itā€™s not terribly exciting, nor should it be particularly difficultā€¦ but what looked a piece of cake on paper is going slower than I would like. I need to get my head around the fact I donā€™t have a framework or existing application doing 90% of the grunt-work for me. All those framework-specific shortcuts and existing functions Iā€™ve grown used to donā€™t work any more so I need to do things manually2. Joyful.

On the plus side, this is probably the coding equivalent of getting back into shape for a World Championship fight, after getting slower and fatter from being too comfortable ā€“ a la Rocky in RockyĀ III.

Frameworks are a wonderful thing for speeding up development in large projects where you have control over your environment. Just remember not to rely on them too much.

  1. This isnā€™t to knock the work of the developers of frameworks like CakePHP and Rails, et al ā€“ not at all. I think theyā€™re doing great,Ā greatĀ work, which makes the lives of countless developers worldwide just that little bit easier. ā†µ
  2. Another thing keeping me from top-speed is an insistence Iā€™ve put on myself to follow best coding-practices all the way, and most importantly,Ā document everything as I go. I usually write something then document it later once everything else is finished. ā†µ

Today I fired upĀ TextMateĀ to do my first bit of seriousĀ PHPĀ coding sinceĀ my stroke. Iā€™ve been almost entirelyĀ XHTML/CSS since getting out of hospital last August, with aĀ littleĀ light coding (ASP mostly) since then.

Probably the closest Iā€™ve got to writing any realĀ PHPĀ in 8 months has beenĀ learning the basics of WordPress themes fromĀ Blog Design Solutions… To be honest, Iā€™ve not had the same drive or determination to ā€œJust Code Itā€ as I once did.

Iā€™ve been readingĀ 37 Signalsā€™ excellent book,Ā Getting RealĀ today. Iā€™m about three quarters of the way through. I doubt Iā€™ve ever said this about a ā€œtechā€ book before, but itā€™s a real ā€œpage-turnerā€;Ā Getting RealĀ pulls you in and is real hard to put down once you get started. All the praise you may have heard about this book is justly deservedā€”itā€™s essential reading for developersā€¦ hell, it should probably be essential reading for anyone who has to work on just about any type of product or in a team.

While Iā€™ve been readingĀ Getting Real, Iā€™ve been feeling like I want to write code again; I want to write something simple, elegant andĀ real. I want to stop thinking about some of the ideas Iā€™ve had over the last few month ā€“ noĀ yearsĀ ā€“ and actually do something. So I set-up a development site and database for one such idea, opened TextMate and created a new project.

It hit me like a slap in the face;Ā Iā€™ve forgotten how to do this. Itā€™s like Iā€™m back on square oneā€¦ like someone sucked most of my programming ability out of my head. I can remember lots of stuff about variousĀ PHPĀ functions, syntax and a million myriad details, but actually doing anything with any of it is another matter. I started thinking about the initial, basic class/data structure I would need and it was like the lights were on but nobody was home.

Looking on the bright-side: if IĀ doĀ have to relearn myslef this stuff, it means Iā€™ll be able to do it with a clean slate and Be Real from the very outsetā€¦