Development Uncategorized

Packagist & Github – How-To Guide

I’ve got a few PHP libraries and classes that I use regularly and, since making the decision to base all my projects on the Laravel framework, have gotten fairly used to installing packages using Composer.

I battled occasionally with getting my libraries to work with Laravel, mostly because of the way I’d written them, but I figured the smart way forward would be to make them available to other Composer users. For PHP, this means structuring the libraries in a specific way and making them available through Packagist, “The PHP package archivist”. You probably know this already, but when you add a package to your project’s composer.json file, Packagist is where it gets downloaded from.

Anyway, after some searching around, I found a bunch of articles that covered how to do *some* of the things needed to create Packagist packages, but no decent end-to-end guide.

So here we go – I’m going to write one. Hopefully it comes in useful.

Pre-requisites & initial steps

  • Sign up for Github. It’s free until you need to go beyond their basic account limitations. Packagist packages are based on Github repository *releases* (or tags).
  • Get familiar with Semantic Versioning, if you haven’t already.
  • Sign up for Packagist. It’s also free.
  • Decide on your *vendor* name – mine is ‘digitalformula’.
  • Install Composer

It’s an excellent idea to have the same usernames on Github and Packagist, if possible.

Creating the base package structure

Create the directory structure for your package. There’s no “right” way to do this, but I’m following the structure used by almost every Packagist package I’ve installed so far. The structure below is for the package we’ll be creating in this article.

Packagist directory structure

Here’s a basic explanation of what each part is.

  • digitalformula – your *vendor* name, your Github username and your Packagist username.
  • hello-world – the name of the package, following proper directory naming guidelines.
  • .git – Git repository information. This gets generated by git when you run ‘git init’ below.
  • .gitignore – list of files that should be ignored during git adds and commits. Each line should contain a filename, path or pattern.
  • src – the ‘root’ directory for your package. It’s also where we’ll tell the PSR-0 autoloader to look – we’ll get to that in a bit.
  • DigitalFormula – the first segment of the PHP namespace we’ll use. This must match your vendor name although at this point you’re free to use appropriate capitalisation, if you like.
  • HelloWorld – the second segment of the PHP namespace we’ll use.
  • HelloWorld.php – the PHP file containing our package’s code. Obviously more complex packages will have multiple files, but a single file will suit us just fine for now.
  • LICENSE – the license that covers usage of your package.
  • – information about your package. Every Github repository should have one.
  • composer.json – probably the most important file here. It describes your package, what it’s for, who worked on it, dependencies and how PSR-0 autoloading will work. Unless you’re interested in the technicalities (I’m not), don’t worry about how PSR-0 works. It just works, I promise.

For those wondering, the complete PHP namespace will be *DigitalFormula\HelloWorld*.

Hold on … namespace? What’s that? If you’re not already familiar with PHP namespacing, I highly recommend reading Dayle Rees’ excellent PHP Namespaces Explained article.

Archived Software Uncategorized

Set network interface IP address with Powershell

The Problem

While setting up our partner technology centre recently, I found myself switching back and forth between networks so often that I was constantly having to change my laptop’s IP address. For reasons that are outside the scope of this article I’m unable to use the option for an alternate network configuration.

Powershell to the rescue

The solution? Two small Powershell scripts – one to setup my network connection for our corporate LAN, the other to setup my network connection for the PTC. The scripts are shown below – feel free to use them in any way you like.

PTC configuration script {#ptcconfigurationscript}

 $index = (gwmi Win32_NetworkAdapter | where {$_.netconnectionid -eq “Local Area Connection”}).InterfaceIndex $NetInterface = Get-WmiObject Win32_NetworkAdapterConfiguration | where {$_.InterfaceIndex -eq $index} $NetInterface.EnableStatic(“”, “”) $NetInterface.SetDynamicDNSRegistration(“FALSE”) 

Corporate LAN configuration script

This script just resets the network adapter back to DHCP

 $index = (gwmi Win32_NetworkAdapter | where {$_.netconnectionid -eq “Local Area Connection”}).InterfaceIndex $NetInterface = Get-WmiObject Win32_NetworkAdapterConfiguration | where {$_.InterfaceIndex -eq $index} $NetInterface.EnableDHCP() $NetInterface.SetDynamicDNSRegistration(“TRUE”) 

Extra stuff

Although I don’t need them in my PTC environment (it’s internal only, with no internet access), you can also use the snippets below to add some extra functionality. Set gateway:


Set DNS server search order:

 $NetInterface.SetDNSServerSearchOrder($dns) # (e.g. “” for single server or “,” for multiple servers) 

Enable dynamic DNS registration (e.g. in AD environment):


Archived ExpressionEngine Uncategorized

ExpressionEngine Plugin – Entry Age

Today I threw together a quick plugin as I couldn’t find an easy way of doing what I wanted without putting JavaScript in my templates.  The plugin, called ‘Entry Age’, allows you to specify a message that can be displayed if the entry being viewed is older than a certain age.

Why a plugin?

I’m assuming that someone else out there will find this useful.  I’m sure plugins like this exist already but, if they do, I can’t find them.

For an example of what the plugin looks like when it finds an outdated entry, please see this article: Move ExpressionEngine to a different server (and yes, the content there is actually outdated).

Can I get it?

Of course you can.  If you want to download Entry Age and try it out, you can head over to my GitHub page any time. 🙂 Entry Age 1.0 on GitHub.

Hope it helps someone.

Archived Mac & OS X Uncategorized

Pimp My Desktop using GeekTool

Continuing with the theme of pimping various aspects of the OS X system configuration, today’s article covers how to use GeekTool 3 to display useful info on your OS X desktop.  For those that missed it, one of my recent articles, "Pimp My Prompt … like Paul Irish covered using the .bash_profile script to add some geek bling to your bash prompt – check it out.

The idea of GeekTool is to use the often under-utilised desktop area of OS X to display useful info.  Some people use it to display images but most use it to run Bash shell commands to interrogate and display various system-level statistics.  For example, my desktop looks like this (click for larger version):

My GeekTool Desktop
My GeekTool Desktop

Before you ask, the desktop background is an InterfaceLift image called The Solutionist.  🙂

Now, I’m going to assume that you’ve already downloaded and installed GeekTool 3 from the GeekTool homepage.  If you haven’t done that already, do it now, please.

Once you’ve got it installed, open System Preferences and click the GeekTool preference pane that should now be available.  For this article, please drag a "Shell" Geeklet onto your desktop.  Configure it any way you’d like in terms of position – for the sake of comparison, the screenshot below shows the settings for my date and weather Geeklet.

Date and weather Geeklet settings
Date and weather Geeklet settings
Archived Linux Mac & OS X Uncategorized

A couple more BASH prompt examples

Yesterday I published an article called "Pimp My Prompt … like Paul Irish" in which I showed how to make your BASH prompt similar to the one used by Paul Irish.

I also included a couple of sample prompts that you could use for reference so I figured I’d write a follow-up article that shows what they look like.  So, without any further ado, here they are.

Example 1 – Green username, blue host, magenta working directory, white git branch:

PS1='${GREEN}u${BLACK}@${CYAN}h:${MAGENTA}w${WHITE}`__git_ps1 " (%s)"`$ ‘

The example above uses the short colour codes outlined in the original article and looks like the screenshot below.

Green username, blue host, magenta working directory
Green username, blue host, magenta working directory

Example 2 – Blue user and host, magenta working directory, white git branch:

PS1='[33[0;36m]u@h[33[01m]:[33[0;35m]w[33[00m][33[1;30m][33[0;37m]`__git_ps1 " (%s)"`[33[00m][33[0;37m]$ '

The example above uses the built-in colour codes but can be harder to read.  It looks like the screenshot below.

Blue user and host, magenta working directory, white git branch
Blue user and host, magenta working directory, white git branch

Don’t forget to read the original article, "Pimp My Prompt … like Paul Irish", if you’re unsure about how to enable the __git_ps1 and short colour code commands.

Archived Linux Mac & OS X Uncategorized

Pimp My Prompt … like Paul Irish

There’s been a lot of talk lately about those cool colours that Paul Irish uses in his videos.  If you don’t know who Paul Irish is and you dabble in a bit of web design … well … shame on you!  😉  The things referenced in this article, including the prompt, can be found in Paul’s YouTube video entitled "The Build Script of HTML5 Boilerplate: An Introduction".  Anyway, I think the prompt colours are pretty useful, especially if you’re speedy at navigating your way around the CLI/shell in Linux or OS X and want to see where you are very quickly..  They help identify where you are in the file system, whether or not your current working directory is a git branch and, depending on what options you set, whether or not there are untracked files present etc.

Here’s what Paul’s prompt looks like (screenshot from the video linked above).

Paul Irish’s OS X prompt
Paul Irish’s OS X prompt

I believe Paul is using iTerm, as am I.  Combined with the stuff below, my iTerm configuration looks like this:

iTerm Configuration
iTerm Configuration

Pimp my prompt!

Ok, so you want your prompt to look like that?  It’s not that hard, actually.  You have to grant me a little latitude, though, as I’m guessing what Paul uses the various CLI prefix symbols for.  In this example I’m using an "o" to indicate a working outside a git branch and a + to indicate that the current working directory is a git branch.

This only works if you’re running an OS X or Linux shell – I’m sure you can do it with Windows but I’m not going to cover that here.

Step 1

If you haven’t got one already, open or create a file called .bash_profile in your home (~) folder.  You might be asking why not use .bashrc?  We want the command we’re adding to apply to interactive login shells – .bashrc only applies to interactive non-login shells.  There is an exception to this if you’re using OS X (like me) – .bash_profile is run for each new window, by default.

If a file with that name already exists, make sure you don’t remove anything from it that you want to keep.  From here I’m going to explain what each part of my .bash_profile does.  The complete file will be shown at the end, including a couple of extra bits.

Note: If you’re going to include the git parts, you’ll need to download the git source and put the file .git-completion somewhere (mine is in my home directory).

Archived Evolution Training Uncategorized

Brunswick to Sassafras

On Saturday Erin & I went for a drive from our place in Brunswick to Sassafras, a small mountain village up in the Dandenong Ranges near Melbourne.  Sassafras is a place I had ridden to before, back when I was living in Hawthorn.  Back then it was a 75k round trip – not bad for the bike I was on at the time (bone-charring aluminium, for those in the know).

After spending the day in the hills I was reminded of how nice the area is up there, and also of the beautiful road conditions.  They’re smooth, flowing, relatively low-traffic and, on the Mountain Highway side, really not very steep at all.  Needless to say, this was enough to get me thinking about biking up there the following day.  I knew it’d be close to 100km return but hey, if you don’t go, you’ll never know what you’re missing, right?

A good dinner and what seemed to be a pretty good sleep that night prepared me for the 7:30 a.m. start on Sunday morning.  The conditions were like nothing I’ve seen in Melbourne before.  It was pretty cold (around 8 degrees Celcius) and completely calm but man … the mist and fog?  Nuts!  Visibility at sea level was no more than about 50 metres at any time during the first 2 hours of the ride, making the use of my usual cycling glasses completely redundant.  The fog and mist was so thick, in fact, that I just took my glasses off and rode without any until about 45 minutes before arriving home.

Riding up Mountain Highway from The Basin to Sassafras really was something else.  It’s an easy climb by any standards despite its profile (see below) but the mist caused the sun to be heavily diffused and to cast those amazing shadowy rays that happen when bright sunlight is filtered through trees.  Simply awesome and I found myself wishing I had a camera with me.

The Climb

The climb from The Basin to Sassafras
The climb from The Basin to Sassafras

Re the ride itself?  In all honesty I was half expecting to get some of the way back and hit the wall since 100km is a long ride for me right now.  Maybe it was the decent rest but I felt pretty damn good throughout the whole thing.  The route from my house to Sassafras is technically uphill the whole way but does roll a lot; that allows for some recovery during the ride.  The climb was no problem and I found myself cranking through the middle section at a pretty easy pace.

I’ll definitely be doing this ride again very soon and plan to try and make it a regular weekend thing.  If you’re in Melbourne and want to join me, fire me an email and I’ll be more than happy to ride with you.  🙂

NB: After posting this and having heard of a hill climb called the "1 in 20" near Melbourne, I realised that the road climb from The Basin shops to Sassafras is the "1 in 20" ride … lol.  Next time I go out there I’ll have to try it under 20 mins – this time was around 21 mins through the ‘official’ timed section, I think.

The Ride

Here’s the ride itself from Garmin Connect.  The climb from The Basin to Sassafras is pretty obvious, huh?  Cool.

Archived Design Mac & OS X Uncategorized

A couple of deviantART submissions

Over the last couple of days I’ve been hacking about with theming in OS X.  It’s something I’ve always quite liked since back in the day when WindowBlinds used to be the way forward on Windows.

The first theme setup I tried incorporated the Gill Sans Text Dock Icons available from deviantART.  Because the icon collection didn’t have icons for some of the apps I use, I made my own and submitted them for others people to use.  The first collection extension is available on deviantART by going to Gill Sans Text – More Icons.  I’ve also made an icon for Traktor Scratch Pro after another user requested it – it can be downloaded from Traktor Scratch Pro for Gill Sans Text on deviantART.

New theme?

I then tried the Float Dock Icons that I found on a MacThemes forum – they’re awesome!  That didn’t have icons for some of the most popular apps, either, so I made some for the best-known Adobe apps.  The icons can be downloaded from Round shiny Adobe dock icons on deviantART.  Cool.  🙂

What did I come up with?

After playing about with a ton of different combinations I came up with one that I quite like.  It’s simple (in my opinion) yet functional without being overly garish – check it out.

Modified OS X desktop
Modified OS X desktop


Why did I do this?  There’s really no good reason other than being a bit of a geek and needing an excuse to dive back in the graphics software that I’ve been missing lately.  I’m no designer (obvious, huh) but doing this stuff is pretty relaxing.  🙂


I’m in the process of writing up how I made those changes now so if you’re interested in doing this yourself, stay tuned.

Archived Geocaching Uncategorized

Melbourne heat + Geocaching = Exhaustion

It’s been so freakin’ hot recently that going out geocaching has been tough.  It’s been an exhausting but worthwhile experience, though.

Anyway, I got home from work and decided that I’d head out to grab a couple of geocaches that I’d been meaning to get for a while.  Most of them were easy, with one exception … it was downright mean!  Check this out …

Yes, it’s a fake piece of chewed chewing gum!  It actually has a tiny logbook on the inside … W.  T.  F.

Archived Geocaching Uncategorized

Another cool geocaching container

Even though I only wrote about Geocaching a day or so ago, I had to write another quick post to show another of the cool & inventive hide methods that cache owners have come up with.  This one was an easy enough find but I did have to use the hint, despite the hint actually being part of the cache name.  Check this out …

Cool Geocache container!

Cool, eh?  🙂

Spoiler Alert!

If you want to try and find this cache yourself, the GC code is GC2KFTJ. Be sensible and don’t click that link if you don’t want to know which geocache this is.  After all, the hunt is most of the fun, right?