Categories
Archived Mac & OS X Uncategorized

How to host multiple websites on OS X Snow Leopard

I've been doing a ton of web development lately and, since switching to Mac back in November 2009, it means all my local development is now done using the OS X implementation of Apache Webserver. Because there are a couple of different sites on the go right now I figured that simulating the production environment as much as possible would be a good idea. To me that means using actual hostnames e.g. http://digitalformula4.local/ rather than http://localhost/digitalformula4/ or, another alternative on OS X, http://localhost/~user/digitalformula4 (yuck).

The Process

Luckily, because OS X has access to pretty much all the Apache Webserver configuration options that are available on the full production install of Apache, setting this up is easy. For this example I’m going to assume you’ve got at least OS X 10.6 as that's what I'm using and I haven’t tried it on anything older. At a guess, though, I can’t see why this won’t work on some older versions of OS X. Here are the steps I followed.

  • Open System Preferences, go to Sharing and make sure Web Sharing is enabled. Without this option checked Apache won't work. If you want FTP access you can also enable that by clicking Options under 'File Sharing'. This isn't part of this article, though.
  • Navigate to /Library/WebServer/Documents/ and make a folder that means something. For now I'll stick to the example above – 'digitalformula4.local’'. You can either do this using Finder or by using the Terminal if you're comfortable doing it that way like me. The Terminal somehow makes you feel a bit more geeky, too. 😉
  • Edit /private//etc/apache2/extra/httpd-vhosts.conf. You'll need to do this as a user with appropriate permissions although using 'sudo' will also work. E.g. sudo nano /private/etc/apache2/extra/httpd-vhosts.conf from the Terminal should prompt you for your password and then allow you to edit the file. Here's a screenshot of what my digitalformul4.local section looks like in my httpd-vhosts.conf file. Don't forget to change the email address section to your email address!

    httpd-vhosts.conf

  • You then need to edit /private/etc/apache2/httpd.conf and uncomment (remove the leading #) from the line that reads Include /private/etc/apache2/extra/httpd-vhosts.conf. Why? If you don’t, the changes you just finished making to httpd-vhosts.conf won’t mean anything.
  • Once you've modified and saved those files you'll need to restart Apache. The command for this, also requiring relevant privileges, is sudo apachectl restart.
  • Edit /etc/hosts on the server and add the following line: 127.0.0.1 digitalformula4.local. Make sure you change digitalformula4.local to the name of YOUR host.
  • On the machines you'll be browsing FROM you'll need to tell them how to find the new server. In my case I'm using a static IP address scheme – my server is configured on 192.168.0.3. On OS X this means editing /etc/hosts and adding the following line: 192.168.0.3 digitalformula4.local.
  • On OS X you may need to clear your DNS cache before you can find the new hostname. Again from the Terminal, this command should work: sudo dscacheutil -flushcache.

Using those steps you should be able to then save files into /Library/WebServer/Documents/digitalformula4 (replaced with YOUR host name, of course) and have them show up in the browser. This is good for when you want to use 'real' paths e.g. /images/ instead of worrying about virtual paths when doing your development.

Hope that helps someone!

Categories
Archived ExpressionEngine Uncategorized

Allow EE code in EE with ‘Allow EE Code’

One of the great features of ExpressionEngine is that you can change pretty much everything that affects layout. EE tags are a big part of this but I found that by default you can have EE tags inside templates, obviously, but not inside entries. Putting EE tags into entries will simply show the EE tags in the browser when viewing the entry – not good. So, how do we do this?

The first step is to download and install the ‘Allow EE Code‘ plugin, a first-party plugin from the makers of ExpressionEngine. As always the best place to get info about the EE plugin manager is the EE documentation.

Without going into too much detail the remaining steps are as follows.

  • Edit your custom fields, in particular the ones you’ll be using EE tags in. Edit the list ‘Default Text Formatting for This Field’ and make sure the option ‘Allow EeCode’ is set to ‘Yes’.
  • Unless you set the default text formatting drop-down box on the previous screen to ‘Allow Eecode” you’ll also need to set ‘Allow override on publish page?’ to ‘Yes’.
  • Next time you edit or publish an entry you’ll be able to have EE tags in your entries IF you set the default text formatting option to ‘Allow Eecode’. If not you’ll have to change the default text formatting from ‘XHTML’ to ‘Allow Eecode’. See the previous setup if you don’t have that option available.

I was trying to do this so that I could use the Freeform plugin by Solspace inside an entry instead of inside a separate template.

Hope that helps someone. 🙂

Categories
Archived Mac & OS X Software Uncategorized

What tools, software & applications do I use? v3.0

This post is intended as a couple of things. Firstly, it’s the 2nd rewrite of a post I wrote a while ago that covered the same thing as this one covers but from when I was running Windows.

I’ve actually had a couple of people ask me what tools I use for various tasks so I’m going to compile a list of the various applications I use ‘every day’. That’s in quotes as obviously I don’t use all of these tools EVERY day but I consider them part of the list of tools I couldn’t do without. I don’t use anything particularly special but I’ll make this list for those that’ve asked anyway. Secondly, I keep meaning to make a list of tools I use for my own reference so it’ll double as that, too.

I’m not going to go into a whole load of detail about what the benefits of each one are – I’ll let you work that out for yourself if you want to try them (feel free to contact me if you want to discuss any of these though). I will include a couple of things which aren’t strictly applications too, e.g. hosting services. So, here we go – these details are correct as at July 18th, 2010.

Applications & Utilities

  • » Operating system :: Mac OS X 10.6.4 (Snow Leopard) on a 27″ iMac and a 15″ Core i7 Macbook Pro. I made the switch from PC to Mac towards the end of 2009 and am wishing I’d done it years ago (based strictly on what I use my machines for). Please keep comments about Mac vs PC to yourself as I’m not interested in comparing the two – they’re both great for different reasons.
  • » Office Suite :: Microsoft Office 2008 for Mac … unfortunately I have to say that compared to the Window version this really is quite crap. Office 2011 for Mac promises to bridge the significant feature gap between Office for Windows and Office for Mac, though.
  • » Email client :: Mozilla Thunderbird 3
  • » App dev environment :: Xcode 3.2.1 when writing for OS X, Visual Studio Express (C#) when writing for Windows (Parallels Desktop)
  • » Web dev environment :: Coda by Panic
  • » FTP client :: Transmit by Panic
  • » MySQL administrator :: Navicat Lite
  • » Text editor :: Fraise
  • » Primary browser: Mozilla Firefox 3.6
  • » Other browsers: Opera 10.6, Google Chrome, Safari 5
  • » Twitter client :: Kiwi for Mac
  • » Password storage :: KeePassX – *highly* recommended on both OS X and Windows (the Windows version is called KeePass although KeePassX is available for Windows, too).
  • » iPod manager :: iTunes – on OS X it’s actually really good and seems 100x more stable than the Windows version.
  • » Photo processing :: Adobe Photoshop Lightroom 3 – I used to use Capture One 4.8 from Phase One but it started to fall WAY behind Lightroom in terms of post-processing options … a real shame.
  • » Fitness management :: Rubitrack for Mac (my training device is a Garmin 310xt)
  • » Instant messaging :: Windows Live Messenger>
  • » Movie player :: VLC (everyone should use this although it struggles with the TSCC codec unfortunately).
  • » Audio player :: iTunes

System Stuff

  • » System management :: MacKeeper.  The differences this thing can make to your Mac’s performance (which is probably already pretty sweet) are astounding.
  • » System hackery :: Tinker Tool.  Purely for the Mac geeks out there.

One thing you might notice is they’re pretty much all free tools with the exception of Lightroom, Rubitrack, Coda, Transmit and MacKeeper, all of which I own licenses for (no they’re not pirated!).

Online Services

  • » Website host :: ICDSoft – these guys are AMAZING. I wouldn’t use anyone else for Linux hosting.
  • » Email service :: Gmail
  • » Website CMS :: ExpressionEngine 2.1 and WordPress 3.0
  • » Online photo sharing :: Flickr (I own a ‘Pro’ account)
  • » RSS feed management :: FeedBurner
  • » Website statistics :: Google Analytics
  • » Search engine :: Altavista … haha yeah right. 😛
  • » Bookmarks :: Delicious – I stopped using browser-based bookmarks many years ago. Ok, so bookmarks are considered a bit backward now but I’ve got stuff on Delicious that I refer back to all the time. Thankfully the functionality doesn’t seem to have changed at all since its acquisition by Yahoo some time ago.

That’s about it really. As I said earlier I’m happy to discuss any of these if you like – just post a comment or use the Contact Me link at the top of the page.

Thanks!

Categories
Archived Sports Uncategorized

Calculating distance and speed manually

I’ve been doing a reasonable amount of training on the road bike lately and given that the weather here in Melbourne is temperemental at best coming into winter I decided to get another indoor wind trainer. Because I didn’t want to break the bank I didn’t buy one that shows you your speed or distance. Apart from the fact that effective training should be based off heart rate and cadence anyway (or power output if you’re REALLY serious) you’re looking at AUD$800+ for that sort of thing, money I’m not prepared to spend on a trainer at the moment.

Anyway, I still wanted to know how far I’d gone and what my average speed was so I set about figuring out how to calculate these figures given the information I do have – cadence, time, wheel size and gear sizes.

Required Info

A bit of research came up with a few different ways of calculating the distance and average speed when you know the following:

  • Wheel circumference
  • Average cadence for the training session
  • Chainring sizes (measured in number of teeth)
  • Sprocket/cassette cog sizes (measured in number of teeth)
  • Training session time

The method I found that worked best for me came from a Wikipedia page entitled Bicycle Gearing. It contains a whole load of useful information, including how to calculate what is referred to as “metres of development” i.e. the distance travelled for a single crank revolution. This, of course, is dependant on which gear you’re in. Another thing to note before carrying on is that it’s often recommended to train for certain intervals at certain levels of intensity and cadence. The only problem I can see with the calculations below is if you change gears a LOT during a trainer session you’d need to know how long you were in each gear for (in order to calculate the metres of development for each gear used). I’m not a doctor either so please be responsible and don’t train before consulting a physician if you’re not sure what you’re doing. However, carrying on …

Categories
Archived Photography Uncategorized

When it rains in Wellington, it REALLY rains …

On June 27th 2010 the Wellington Harbour Marathon was held in … yes, Wellington, New Zealand. 🙂

First up, the weather! The wind was an icy 40kph from the south (straight off Antarctica), the temperature was around 5 degrees and the rain was constant from start to finish. I was part of a team of photographers assigned with the difficult task of photographing each of the 6000 competitors at least once each.

The job was contracted to marathon-photos.com, a company who shoots sporting events so that the competitors can purchase photos of themselves after the event is over. It’s a great idea!

Unfortunately the weather really stopped the event from being as fun as it could be but we got there in the end and some great shots were taken. If you want to see the photos or if you were there on the day, please check out marathon-photos.com. 🙂

Categories
Archived Mac & OS X Uncategorized

Playing about with AppleScript…

I’ve been playing about with AppleScript today as there are a couple of tasks I want to automate on my system (Snow Leopard 10.6.3 as I write this). My background in I.T. means that task automation is something I’m into for obvious reasons … why take ages to do something many times when you can automate the process and have it done in 1/10 of the time when it needs to be done next? 🙂

Anyway, I use KeePassX to store my passwords (it’s the OS X version of KeePass, in my opinion easily the world’s best open source password safe. Although I use Time Machine (it does a great job) I need to carry my passwords with me. I don’t use the same password all over the place which means I have a whole bunch of passwords – KeePassX means I don’t have to remember them all.

So, where does AppleScript fit in? I used to use a bash script to keep my USB key (a LaCie itsakey) and local hard drive password databases in sync and, while it worked fine, I decided to have a go at doing the same thing using AppleScript.

AppleScript is, for lack of a better expression, painfully close to being English. It’s stupidly easy to write although there are some advanced things you can do with it too (I’ll get to those in a future post).

Here’s my entire script – hope someone finds it useful. 🙂 Please note that this version uses Growl to display notifications – I highly recommend installing it if you don’t have it installed already. Please also note that a production script would have much better error handling but this one does what I need it to. Comments welcome!

Script to backup KeePass database

-- see if Growl is available on this system
tell application "System Events" to set GrowlAvailable to exists application process "GrowlHelperApp"

if GrowlAvailable then
	-- enable the script to send Growl notifications
	tell application "GrowlHelperApp"
		set the allNotificationsList to {"Old KeePass versions removed.", "Old KeePass versions backed up.", "Master KeePass versions copied successfully."}
		set the enabledNotificationsList to {"Old KeePass versions removed.", "Old KeePass versions backed up.", "Master KeePass versions copied successfully."}
		register as application "Backup KeePass Database" all notifications allNotificationsList default notifications enabledNotificationsList icon of application "Script Editor"
	end tell
end if

set diskName to "LaCie"
set folderName to "KeePass"
set databaseName to "passwords.kdb"
set databaseBackup to databaseName & ".bak"
set keyfileName to "passwords.key"
set keyfileBackup to keyfileName & ".bak"

-- get the username of the current logged in user
set userName to do shell script "whoami"

try
	tell application "Finder"
		if exists folder folderName of disk diskName then
			-- set the locations of the original, destination and backup KeePass files
			-- because we're using aliases, these files & folders MUST exist first or an exception will be thrown
			set sourceDB to file databaseName of folder folderName of folder "Data" of folder userName of folder "Users" of disk " HD" as alias
			set sourceKeyfile to file keyfileName of folder folderName of folder "Data" of folder userName of folder "Users" of disk " HD" as alias
			set destDB to file databaseName of folder folderName of disk diskName as alias
			set destKeyfile to file keyfileName of folder folderName of disk diskName as alias

			set bakDB to file databaseBackup of folder folderName of disk diskName as alias
			set bakKeyfile to file keyfileBackup of folder folderName of disk diskName as alias

			-- set where the files will be copied to
			set destFolder to folder folderName of disk diskName as alias

			-- if exists file databaseBackup of folder folderName of disk diskName then
			if exists file bakDB then
				-- delete the existing backup files
				delete file bakDB
				delete file bakKeyfile
				if GrowlAvailable then
					tell application "GrowlHelperApp"
						notify with name "Old KeePass versions removed." title "Backup KeePass Database" description "Old KeePass versions removed." application name "Backup KeePass Database"
					end tell
				end if
			else
				set continueResult to display dialog "Backup files are missing from " & folderName & " on disk " & diskName & ".  Continue anyway?" buttons {"Yes", "No"} with icon caution with title "Backups missing"
				if button returned of continueResult is "No" then
					return
				end if
			end if

			-- backup the existing files
			if exists file destDB then
				set name of destDB to databaseBackup
				set name of destKeyfile to keyfileBackup
				if GrowlAvailable then
					tell application "GrowlHelperApp"
						notify with name "Old KeePass versions backed up." title "Backup KeePass Database" description "Old KeePass versions backed up." application name "Backup KeePass Database"
					end tell
				end if
			end if

			-- copy the master files
			copy file sourceDB to folder destFolder
			copy file sourceKeyfile to folder destFolder
			if GrowlAvailable then
				tell application "GrowlHelperApp"
					notify with name "Master KeePass versions copied successfully." title "Backup KeePass Database" description "Master KeePass versions copied successfully." application name "Backup KeePass Database"
				end tell
			end if
		else
			display dialog "Oops!  The destination folder you selected, /" & diskName & "/" & folderName & "/, ain't there!.  :(  Please check it and try again." buttons {"Ok"} with icon stop with title "Oh no!"
		end if
	end tell
on error
	-- an exception occurred
	display dialog "An expected error has occurred while backing up your KeePass files.  Have a look to see if all the required files are there and try again ... k?  :)" buttons {"Ok"} with icon stop with title "Oh no!"
end try
Categories
Archived Mac & OS X Uncategorized

Make the OS X Dock nice and tidy…

I’m bit a of a tidy-freak when it comes to icons, desktops and overall system organisation … geeky? Yes. Easier to work with afterwards? Definitely.

So now that I’m using a Mac I’ve been slowly getting used to organising things better – including the Dock. I’ve got everything ordered how I want but still thought it was a bit of a mess (visually) so I tried to find a way of adding some space to the Dock, thereby creating ‘groups’ of Dock icons. Yes, I know about stacks but they didn’t do what I wanted.

All you need to do is run a pretty simple shell script to get it done. There are 2 scripts to use, one for the Applications side of the Dock and the other for the Documents side of the Dock. By ’side’ I mean the parts of the Dock on the relevant side of the existing resizer/splitter thingy.

Shell script I hear you say? Bad! Well … no, not as bad as you might think. Thankfully OS X has a built-in scripting language all of its own called … wait for it … AppleScript. From AppleScript you can run shell commands which you don’t even need to mess about in the shell if you don’t want to. For the Windows people out there think of this example as a batch file – the end result is the same.

Anyway, fire up the AppleScript Editor (it’s under Applications/Utilities if you haven’t moved it) and paste the following script into it. Note that this one is to add a spacer to the Application side of the Dock!

Add a spacer to the Applications side of the dock:

-- add a spacer to the Application side of the Dock
do shell script "defaults write com.apple.dock persistent-apps -array-add '{tile-data={}; tile-type="spacer-tile";}'"
-- restart the Dock
-- process names are case-sensitive!
do shell script "killall Dock"
Categories
Archived Databases Uncategorized

Unattended installation of SQL Server 2005 Express

To continue on with the theme of unattended installation-related posts lately, what if you want to install SQL Server 2005 Express Edition in unattended mode? SQL Server 2000 had the ability to save the installation into a file called setup.iss – how nice of Microsoft to remove this feature from SQL Server 2005 … however, let’s get rolling.

This post has been removed in favour of pushing readers towards installing SQL Server 2008 Express instead of SQL Server 2005 Express.

The benefits of using the 2008 version over 2005 are too numerous to list here and an article has been published on Digital Formula that goes into detail on how to perform an unattended installation of SQL Server 2008 Express. Please click the preceding link for full information.

Categories
Archived Mac & OS X Uncategorized

Reloading hosts files in OS X

Now that I’m using a Mac at home I’ve had to go through a bit of a mind switch when it comes to doing things I’ve been to doing for years.

Today’s mind bender came about because I needed to edit the hosts file to force Snow Leopard to find a URL on a different IP address to where it actually is. In Windows you just edit %SystemRoot%system32driversetchosts then run nbtstat -R to reload the hosts file but in OS X this obviously doesn’t work.

You still need to edit the hosts file, located at /etc/hosts, but obviously there’s no nbtstat command to run afterwards. Depending on where you look on Google you’ll find a number of answers, from running niload to lookupd but none of those worked for me. Thankfully I found the answer – here it is.

Flushing DNS Cache:

sudo dscacheutil -flushcache

Obviously you’ll need the sudo part unless you’re running your shell as root … let’s not get into that, though. 🙂

If you want to make an alias to this command so you don’t need to type the whole thing every time, do this:

Flushing DNS Cache:

alias flushcache=’sudo dscacheutil -flushcache’

Sorted!

Categories
Archived Business Development Uncategorized

Microsoft Excel – Count coloured cells

Most companies have some sort of backup strategy in place and that strategy often involves documenting the success & failure rate of the backups on a daily basis. For obvious reasons all the companies I’ve worked with in the past have documented this using a variation of the well-known “backup matrix”, created using Microsoft Excel.

I choose to create my backup matrix documents so that backup results are colour-coded. That way they’re easily visible and it’s easy to see what happened when and to get an overall idea of how good your backups have been. Green coloured cells are successful backups, red cells are failed backups etc.

The first thing I need to do when I create these documents is to make some ‘reference cells’. These cells are coloured with the various colours that will be used in the matrix, e.g. green for successful etc, as listed above. So they don’t look like reference cells I also use them as the key for the matrix so people know what the various colours mean.

How, then, do you work out how good the backups have been if there’s no text in the cells to look for? You need a VBA function that looks for the cell’s colour instead of its contents – easy. Below is the function I wrote for that purpose – you’ll need to make sure you are using .XLSM documents if you are using Excel 2007 for Windows as .XLSX files are, by default, secured so that macros won’t run.

Please note that the code below won’t work in Office for Mac 2008 as VBA is not supported. Office for Mac 2011 will have has full support for VBA – I’m looking forward to see if this code works there. I haven’t tried it there, though.

Microsoft Excel – Count Coloured Cells

Function countColours(colourReferenceCell As Range, cellRange As Range)
    ' countColours
    ' Chris Rasmussen, April 2010
    '
    ' Count occurences of cells that are a certain background colour
    ' E.g. for use in a backup matrix

    Dim currentCell As Range
    Dim colourReference As Long
    Dim vResult

    colourReference = colourReferenceCell.Interior.ColorIndex

    ' reset the total count back to zero to prevent errors
    vResult = 0

    ' go through all the cells in the specified range and look at the background colour
    For Each currentCell In cellRange
        If currentCell.Interior.ColorIndex = colourReference Then
            vResult = vResult + 1
    End If
    Next currentCell

    countColours = vResult

End Function

Once you’ve got this function in place, all you need to do is choose the cell that will show the total of successful backups (for example) and enter the following formula. We’ll assume that cell A1 is the cell that is coloured green for reference. We’ll also assume that the Excel cell range C1:C5 contains the results.

=countColours(A1,C1:C5)

If you have 5 successful backups in your range and they’re all coloured green, the cell containing that formula with contain the number 5. Easy. 🙂