C++ dev environment that works.

I have spent an awful lot of my life in the last couple of years trying to code C++. Not learning how to do it, not struggling with compiler errors or mistakes anywhere, just with the nonsense task of getting an IDE with a “compile and run” button working. Lets be clear about my requirements here. I need the standard c++ libraries, I need a compiler that is unix friendly, and I don’t need to use any win32 calls (i.e. there’s no way I’m using Visual Studio, sledgehammer to crack a nut, etc etc).

First, Kdevelop broke. The automake library it used suddenly ceased to work, and so the ubuntu and openSUSE versions just bit the dust. You could write code, but you couldn’t automatically compile it, rendering my Masters Degree source code project unusable. Useless, eh? good job I kept working TGZs of the various builds.

Next, Netbeans broke. Now to get Netbeans C++ working on windows (I abandoned Linux for development after my KDE experience) you have to install cygwin, prat around configuring netbeans (adding in new header file locations, pointing it to the appropriate bin directory, etc), but hey, give them some slack and just enter the right values. And then it throws a Java null pointer exception when you try and run. And when you try and report the bug, your report is marked as a duplicate that has been fixed in the latest version, except I am using the latest version. A similar problem appears in the v6.8 beta. AARGH. (etc).

Then, finally, I Googled “c++ dev environment windows” and read some reviews. I tried various things (Code::blocks was rubbish and threw about 400 exceptions every time I tried to compile or run, eclipse…well, that’s basically just Netbeans and I didn’t want to go down that route again.) And then I found dev c++.

It is written in delphi (yuck) it is open source (hmm, interesting) and it works out of the box. I don’t know if it was because I already had cygwin installers, but the v5 beta (4.9.9.2), specifically the version that claims to have a bundled mingw GCC, just works. You can dictate your own directory structure, it will “handle” it. You can use GCC header files, and they just work. And most importantly, you hit compile and run and you get a command window with “Hello world!” popping up so you can see your code running.

This is every headache I have ever had with this reversed and compensated for. Thank you…Bloodshed software? who write stuff in delphi? Well, thank you anyway, for this marvellous solution to what seemed to be an eternal problem.


Setting up your own flash project for free.

OK, so I am not the best person in the world in terms of finishing things off. I start a project, get somewhere (so it is doing something vaguely useful) and then forget entirely about it and leave it to rot.

But one idea that I keep coming back to is a particular project in flash (no details until I release a beta, when you will get a link and be able to see all the code), and I have installed the CS4 demo (30 day trial) that one is allowed to use to test out CS4 before purchase, and I am now in a race against the clock to finish it off before my trial expires!

I am familiar with CS4, as I use it at work, so I have a much shorter ramp-up curve than anyone else just joining in the fun (I will make available some documentation on ActionScript 3 soon, when I get around to finishing off my KB website for developers), but I hope that someone else might be up for “trying to make something in flash in 30 days”, so here are rough steps for setting up the dev environment (I’m assuming windows here, but they should work similarly on Mac OS X):

  • Go to the Adobe website and find the page to purchase Flash CS4.
  • Click on the “Try” link next to buy and upgrade, and sign up for an adobe account. Don’t worry about the fact that they have your email address, or use your “spare” account if you have one; I have never had any spam from Adobe after signing up for this.
  • Install the silly little download manager and obtain the installer. before you run it, make sure you check the following:
    1. Remove any external HDDs, USB sticks or truecrypt or linux volumes you have mounted by some magic or other. The system optimiser that runs at the start of the install process tanks if it finds any weirdness on any FS it can see.
    2. Make sure you have the latest graphics card drivers installed before you run the install; CS4 is pretty hefty as UIs go (entirely custom and native to Windows) so that CS4 optimises itself properly for your computer and isn’t painfully slow.
  • Finally, when you get to the License part of the installer, choose “I want to try for 30 days”.

Now enjoy the CS4 goodness! Make sure you use ActionScript 3 not 2 when making your applications (AS3 is much more stable, better structured and generally a bit more of a proper programming language), even if you are just going to do most stuff by drag and dropping images and components into place.

Happy flashing!


Windows 7 installation – what to watch out for!

The thing I liked about the Vista/7 activation system was that it let you “try before you buy”, much like many of the laptops that come with 60 day Office 2007 trials. You can load all your old files, install all your favourite programs and see how well they work, and so on. Unfortunately, with Windows 7, I have found that this is not the whole story with delayed activation; let me tell you how I broke it!

If you are doing the above for testing purposes, but are fully intending to activate the machine assuming there are no problems, then you won’t enter your key when you install (just in case windows sneakily activates before you are happy, and then there’s a problem).

However, the standard install disk for Windows 7 has all the different editions in there, Home Premium, Professional, Ultimate, and so on. It actually chooses which version to install based on the key you enter; if, like me when testing, you don’t enter one, it installs ultimate, which means that the home premium/professional license you have will fail to activate with a “you must buy a Windows 7 Ultimate license” warning.

Gah! So how do you downgrade your new installation (which you just spent ages configuring, installing all your games, building cygwin, and generally massaging into a usable windows install)? Oh bad luck, you can’t! You have to reinstall from scratch!

Now on that thread it says the disk will let you choose – not so my friend! There are no warnings (or if they are then I missed them in 2 RC installs and 2 final version ones)!

So just in case you are installing in a testing environment that might become a proper environment in the future – make sure you can activate before you invest too much of your life setting up the machine!


How to run Ubuntu on your Intel Mac, from a USB stick.

When I discovered Virtual Box I vowed never to install Linux again. But then came the crashes. And then I upgraded to Snow Leopard. Screw this, I need some kdevelop goodness now….

So, today I found myself installing ubuntu on a USB stick. Here’s how it goes:

  1. Download, burn and boot from your ubuntu disk of choice. Running a MacBook Pro from July this year I chose the amd64 disk, as a liveCD. To boot from CD just hold down “C” when you hear the angels as your Mac turns on.
  2. Choose “try ubuntu without changing your system” from the menu to boot the OS from the liveCD.
  3. Run the install as usual, specifying the USB drive you plugged in as your disk and selecting “use entire drive” from the partitioning options.
  4. This is where it gets tricky. Restart, and hold down left option (alt). Observe that only the “proper” hard disks are listed – intel Macs don’t natively support USB booting. 😦 cheer up and boot OS X – there is a solution.
  5. Download and install rEFIt – an open source EFI bootloader for just this type of occasion.
  6. Reboot one more time, holding down option, and choose refit.
  7. Choose your “legacy” OS (it only says it in that patronising manner because it’s jealous of the MBR goodness) and fly all the way to open source Heaven without breaking your precious OS X install!

I hope you enjoy this one – you’ll need a fairly decent USB stick though. Cheap ones are terribly slow to write to, so installing and updating may take you well over the 2 hour limit of my how-tos. If you can, I recommend a proper USB HDD in an enclosure – much less worrysome and much quicker.

EDIT: This actually isn’t complete and leaves you with a grub error because the ubuntu installer is a moron and overwrites the MBR on the bootcamp drive, even though you haven’t installed it on that HDD. (my way around this on my previous laptop was to remove the HDD before starting – but I couldn’t quite bring myself to on the shiny new unibody MBP…) you need to resync the MBR with the refit EFI data using the partitioning tool here on the boot menu:

Apologies for the brokenness and thanks to bagellord (see comments) for pointing this out!


How I keep my Passwords Safe.

Hi all. Apologies for the gap, apparently remembering to post every day is a bit ambitious!

Today I’ll write a quick entry about a few things everyone should know about p@s5w0rds.

Web 2.0 brought us a mass of online applications (as opposed to pages); sites we don’t just visit but use, participate in, modify and so on. Whether this be commenting on a Blog, upvoting a link on Reddit or correcting a typo on Wikipedia, we will be asked to register, providing an email address, username and password.

It is very very very bad practise to use the same password everywhere, which is some people’s response to this situation. I was once working as an IT admin at a school and a student, upon logging in, asked me “so how to I change my password?”. “You can’t, that way we can tell you again if you forget,” I said. She looked aghast at me and exclaimed “What? But I have to use the same password for everything! That’s how I remember it!” The practise is bad for one simple reason; it gives an opportunist “hacker” access to all your websites. Grabbing a password from a passing HTTP request is not that hard, since most of these sites don’t bother with an SSL certificate (don’t bother to encrypt the request, like your bank, and most payment systems, will be very careful to do).

So, you should use different, not guess-able passwords for your website logins. But how to remember them all!? You can’t be expected to memorise lots of non-word-like passwords for all 25 of your regular websites, plus the 80 or so you use occasionally, can you? And saving them all to a text file on your hard disk is so insecure; anyone else using your computer could copy/steal them all onto a USB stick, and you wouldn’t even have them with you at work.

This is where a wonderful piece of open source software comes to the rescue: TrueCrypt. This allows you to create a dummy partition on a USB stick that looks like an ordinary file (you could call it “Health and Safety Assessment June 2006.doc” or something), but when you point TC at it, and enter one single master password, you can access a completely safe disk space on which to drop a small text file containing all your logins and passwords. This software is available for basically every operating system (I think Gentoo has banned it on the basis that they have quite a defensive version of an open source license: entirely irrelevant to end users), so you can get at your passwords on Linux or Mac OS X at home, on Windows at work, or anything, it also runs a tutorial when you first install it which shows you how to create a properly secure hidden drive. You can take it with you in your wallet or on your key-ring, even backing it up to your home computers hard drive is safe. You will need to memorise one difficult password; the master one to this encrypted volume. You should make sure you know it off by heart before you use it; you will lose the data if you forget it! I recommend either using multiple old passwords chained together, or practising typing it out 50 or so times in notepad/textedit/gedit (without saving, obviously) to get it into your fingers’ muscle memory. (You could also keep it on a piece of paper at home “just in case” until you are confident you know it off by heart completely, at which point you should burn it, but this is a last resort!)

Also keep in mind that if the data is valuable to other people, you shouldn’t advertise it’s presence!

In order to generate properly random passwords I recommend the strong password generator. This application generates the passwords in JavaScript, which means it actually works on your computer locally and the site itself doesn’t know what password it has given you. You should include non alphanumeric characters if possible (some systems choke on these, e.g. mysql; not strictly a website though!) in order to fully take advantage of the number of available combinations. As mentioned, bashing out one of these per website login is highly advisable. It also makes it easy to regularly change your passwords, which is also very good practise.

This really does take less than a couple of hours to set up, allowing for logging in to all your sites and changing the passwords (you can always add more as you remember them if you forget some initially…) and it will vastly reduce the chances of problems with people taking over your online identity.

I also recommend using this system for “proper” websites like PayPal, Gmail, and others that do use SSL; as someone guessing your Gmail password shouldn’t be able to send funds to whomever they want from your PayPal!


Subtheming in Drupal is really easy

I just created a Drupal Subtheme in about 20 minutes!

If you like the look (mostly) of one of the exiting Drupal themes, you can easily add a few customisations by extending a theme rather than starting from scratch. This is also a good way to start the development of a from-scratch theme, as you can build up some CSS and new logos and colours without losing most of the functionality until you are finished coding it all.

The first thing to do is create the bare minimum required to activate your theme. Go to the sites/all directory, and create the themes directory (if it isn’t already there). In there, create another directory with the same name as your theme (the machine readable name, all lower case, as opposed to the human readable name, which we will specify later). The rest of these instructions assume that you named your theme “theme”.

Next, you need to create a theme.info file. Below is a sample:

; filename theme.info
; $Id$
name = Human Readable Theme Name
description = a simple example theme that depends on the marvin core theme.
version = 0.1
core = 6.x
base theme = marvin

This is really all you need to create a theme; you will get an empty logo (replaced by a link called “home”), and you will have the rest of the marvin theme there to play with. To insert your own site logo, just drop a logo.png into your theme directory and you are done!

You can then add a stylesheet, which will allow you to override the marvin CSS elements one at a time as you develop your theme further. Just add the following lines to the info file:

; for the default stylesheets:
stylesheets[all][] = style.css
; for your own stylesheet:
stylesheets[all][] = my-styles.css

Where to go from there is up to you! You have the full armoury of CSS styling available to you. I recommend something like Firebug (Firefox plugin) for finding out the names of the different CSS elements you want to change, but you can just dive straight into the marvin CSS files if you prefer.

In a future post I will explain how to take an existing scheme (page and CSS) and turn them into the base for a Drupal theme (which may be more useful to people who want to change their CMS, or borrow a theme that they saw that was cool).


MAMP / phpwiki

Today I got a personal wiki working in well under 2 hours on my Mac.

If you are a Mac user and would like an easy way to keep track of rough draft thoughts and your own personal memory jogging how-tos in a secure and simple way, I recommend the following:

  • Download MAMP (Mac Apache, MySQL and PHP)
  • Install by dragging to your applications folder as normal.
  • Use the myPhpAdmin web-software (available at localhost:8888/MAMP/) to configure your database server (mysql) to accept connections from a new user (phpwikiuser, for example) and add a new database for it (e.g. phpwiki).
  • Download phpwiki, and extract the archive using

    tar -xzf phpwiki-version.tar.gz

    (you may not need the z if the extension is just .tar, as safari automatically gunzips the file when it finishes downloading.)

  • Rename the folder to whatever you like (e.g. phpwikiname) and move it into the docroot (default is /Applications/MAMP/htdocs, but you can reconfigure it in preferences).
  • Finally, you will need to open the config file and enter the database login details for it, e.g.

    pico lib/config.php

    or whichever your favourite text editor. (If you just use textedit or word, then you can go to the location (e.g. /Applications/MAMP/phpwikiname/lib/config.php) in finder and double click on the file, choosing TextEdit if no default is set.)

  • Change the db type to mysql, and make sure that the database login details further down (in the mysql section!) match what you entered when you created the account. You could just use ‘root’ and ‘root’, but I would advise a less privileged user which only has permissions over the phpwiki database so it can’t break anything else you end up using MAMP for later.

Thats it! Navigate to localhost:8888/phpwikiname/ and edit your front page. Advantages of phpwiki are that it is small and light, has very simple creating and editing (just creating a link creates the page) and it does the job. It’s disadvantages (very insecure as anyone can edit and see who has been editing down to the IP address) are irrelevant if you are using them on a personal system, although you may prefer something a bit prettier (like mediawiki, which is what wikipedia uses; although I don’t use it because it is a sledgehammer to crack a nut for a personal wiki on your laptop – the instructions would be roughly the same though.).

That’s my 2 hours for today, tomorrow I will be covering the basics of theming a drupal web site.