Generating random strings in PHP

When looking to generate random strings using PHP, there are a few sources of information that are available, but with a lot of conflicting advice. I have just had a need to implement this functionality and thought I would document what I did for the benefit of others.

function generate_random_string($length)
{
  $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
  $output = "";

  for ($i = 0; $i < $length; $i++) {
     $pos = mt_rand(0, strlen($chars) - 1); 
     $output .= $chars[$pos];
  }

  return $output;
}

Kayaking in Helsinki

My better half is working in Helsinki for a couple of weeks, so this weekend I went over there to see her and hang out. We did quite a few cool things that I want to share over the next few posts for the benefit of all by way of a recommendation.

Helsinki by kayak

On Saturday morning we went kayaking in the Helsinki archipelago. We chose to book an organised tour from Natura Viva that included all transport from the city centre and all equipment for €65 per person. The minibus picks you up at 10am and takes you out to the paddling centre, dropping you back in the centre again afterwards.

Kayaking the archipelago of Helsinki

Kayaking the archipelago of Helsinki

The online booking process indicates that groups can be as large as 8 at a time, but we were very lucky as no-one else had booked for our day, so we effectively had a private tour with our guide Matteo.

Since we both had some prior experience (I had kayaked once before; my fiancee several times before), the instruction given was brief and functional at the beginning, with further tips given as the tour progressed. However, they cater to absolute beginners too, so please do not let the fact that you have not kayaked before put you off doing this!

<img title="The guide takes photos as you paddle" alt="The guide takes photos as you paddle" src="http://photos similar viagra.markhatton.co.uk/photos/i-dZGzC9V/0/S/i-dZGzC9V-S.jpg” width=”400″ height=”300″ />

The guide takes photos to capture the moment as you paddle

The distance you cover on the tour will depend on how fast you paddle, but for us it was about a 3 mile paddle out to the small public island where we stopped for lunch. The tour includes a lovely ham and cheese sandwich (tell them in advance if you are vegetarian), and a juice box. We were also given some sea buckthorn berry juice, but I’m not sure if that was part of the tour deal, or just the excellent hospitality of our guide!

After lunch, you paddle back toward your starting point. You can stop to take a break at any time if you need it – something that I did regularly so that I could take pictures using my phone (for which I highly recommend an AquaPac to keep things dry while still allowing photos). The guide also takes pictures throughout the tour using a waterproof camera, and the centre emails you a gallery of the pictures to you after your tour – no rip-off prints here!

Once you’re back on dry land, you are taken back to the city centre in the minibus. I recommend stretching and maybe having an upper body massage, since your upper body probably just got worked out harder than it has in a long time!

Overall, if you have a few hours to spare across the middle of a day in Helsinki, I cannot recommend this activity highly enough.

Virgin Media cable broadband packet loss

I hope this is just an error on my line, or maybe a faulty SuperHub or something, but I fear that it is something wider scale. This is the MTR output from my Linux home server to the NAS box on the end of my parents’ Virgin Media cable line about 2 miles away.

MTR trace showing horrendous packet loss within Virgin Media's own network
What are they doing with all my lovely packets?

This is not good. If they can’t get under 10% packet loss on network segments that they entirely control themselves, this is not a good sign!

I shall be calling them to see if they would like to do something about this.

Airplay-style music streaming without a Mac or AppleTV

I’ve always been slightly jealous of the Apple ecosystem’s ability to easily stream content around between devices. A friend of mine uses his MacBook Air to stream Spotify to his Apple TV via Airplay so that it comes out of his regular stereo system in his lounge room. I have always been very impressed at how easy it was and is what I view as the killer application of Spotify. Sadly, as a Windows and Android user, I couldn’t find any way of achieving this audio nirvana without taking the plunge and handing over my soul, and my credit card, to Apple.

Then I read Fred Wilson’s article about using Bluetooth to achieve much of the same thing. Go read it (and the rest of his blog) – it’s great. In it, he recommends the Logitech Wireless Speaker Adapter. It’s a tiny box that plugs in to your amplifier and pairs with any Bluetooth device that supports audio streaming (e.g. your laptop or your phone). I checked out the price on Amazon.co.uk, found that it was less than £25 and immediately ordered one.

All I can say is “wow”. I love it viagra barcelona. It is the best £25 I have ever spent.  It’s super-easy to set up and it just works. It has completely changed my relationship with not only Spotify, but with music as a whole. I was totally on the fence about the usefulness of Spotify before I got this, but now I’m hooked. I wholeheartedly recommend it if you love music on your computer and want it to come through your stereo with minimum fuss.

Fred Wilson posted a follow-up article about a month later in which he comes to the same conclusion. It seems that he had trouble making it pair with more than one device, but I haven’t had that problem – I’ve got two computers and a phone all paired (although obviously you can only connect one at a time!).

Buy one now. You won’t regret it.

Airline emergencies

I had the delight of a transatlantic flight today. Flying is something that I have to do quite a bit for my work and it lost its glamour a long, long time ago.

The part that it is easy to become blasé about is the safety demonstration. Today I noticed that they still ask passengers to locate the emergency exit that is nearest to them. As far as I can tell, the seats on planes are pretty fixed in position without serious work, so why not take the guesswork out of the situation and just write the location of the nearest exit on the back of the seat in front? They can make room to tell you where your lifejacket is located, but not where the door is?

Book review: The Myths of Innovation by Scott Berkun (O’Reilly)

I first came across Scott Berkun’s work when Joel Spolsky <a href="http://www.joelonsoftware donde se compra el viagra.com/items/2009/03/09.html” onclick=”_gaq.push([‘_trackEvent’, ‘outbound-article’, ‘http://www.joelonsoftware.com/items/2009/03/09.html’, ‘recommended’]);” title=”Joel on Software – How to be a program manager” target=”_blank”>recommended Making Things Happen, Scott’s excellent book on project management. I continued my adventure through Berkun’s back catalogue with Confessions of a Public Speaker which I found very enlightening. I have now read his latest published work: The Myths of Innovation, published by O’Reilly Media.

Front cover - Myths of InnovationThis book attempts to discredit the numerous inaccurate ideas about innovation that are both written about in other books, and commonly held beliefs in the wider public. He shows that innovation is not a formulaic concept that can be copied at will, nor something that just happens when you decide you want to be “innovative”. It is also rarely the case that a “lone inventor” beats the odds to produce a world-beating product.

One of the other major myths that he dispels is that of the “eureka moment” – the sudden spark that resulting in a complete idea overnight. Instead, most innovations are the result of many years of hard work on improving and productising ideas that may have first seemed like irrelevances. The myth of snap innovation continues to be perpetuated because these ideas are often revealed to the world as a complete concept, without showing the hard work that has been done behind the scenes to get there.

Berkun looks at what kinds of corporate environments produce the seed ideas that are required at the start of this process, as well as allowing those ideas to incubate over the course of many years to reach a successful conclusion. He looks at examples of companies that have made extremely successful businesses out of this type of innovation (e.g. 3M, Google) to see what they do differently from those companies that merely pay lip-service to innovation in their mission statement.

Finally, Scott takes us through some ideas around how to think creatively, how to get your ideas noticed and keeping yourself motivated throughout a process that might last a lot longer than you expect.

Overall, I enjoyed this book. I read it over the course of a few days on my Kindle on my commute to and from work and found myself eager to get on to the train so that I could continue reading. If you have a role where you need to come up with ideas in any capacity, this book will give you a real insight in to the best ways to do that. Even if you don’t have a job that requires you to produce structured innovation right now, I still recommend this book to you as it will help you to see where you can innovate regardless, both at work and in your home life.

Recommended.

The Myths of Innovation is available to purchase directly from O’Reilly, Amazon [UK; US] or from your local friendly bookshop.

(Disclaimer: The Myths of Innovation was provided to me free of charge by O’Reilly for review purposes, but I assure you that my views on it are genuine.)

Installing CyanogenMod 7 on your HTC Desire

I am writing this as a guide to others based on what I had to do to succesfully upgrade my own HTC Desire handset from the official FroYo software release to CyanogenMod 7.03. I couldn’t find a simple one-stop-shop guide for the whole process, so I am trying to make one.

This is for the HTC Desire (GSM version), also known as the HTC Bravo. It is not for the HTC Desire HD, HTC Desire Z, HTC Desire S or any other phone. ONLY the HTC Desire.

Before we get started, a word of warning. This may or may not work for you too. This process is not safe. There is no guarantee this will work. There is a strong possibility that your phone will be bricked, destroyed or eaten before, during or after this process. Most importantly, in all probability, THIS WILL VOID YOUR HANDSET WARRANTY. Consider this your fair warning and don’t do it unless you really, really want it. Don’t even think about blaming me when it all goes horribly wrong. I am not responsible for what you do with your handset.

Anyway, with that in mind, this is how I performed the upgrade. Overall, it took me about 90 minutes, but that was because I had to go and find all of these bits of information and make it work together. I imagine that you could do it under an hour using this guide.

I used:

  • An HTC Desire handset running Android 2.2 (FroYo)
  • A standard micro USB cable
  • A PC running Windows

It may be perfectly possible to use a Mac or a PC running Linux to do this, but I haven’t done so and so you’re flat out of luck if you’re hoping to read that here. Suck it up and borrow a Windows PC from a friend for an evening.

1) Back up everything

This software upgrade will remove everything from the phone. Things you might want to back up include your SMS messages, call history and any application-specific data that you wish to keep. You may also want to make a note of the applications you have installed so that you can easily reinstall them all. There are free applications available to help you with all of this. I used SMS Backup & Restore and Call Log Backup & Restore.

It is important to note that the contents of your SD card should not come to any harm during this process, but you might want to back that up to a PC too, just in case.

2) Install the HTC Sync driver on the PC

In order to let your PC communicate with your HTC Desire handset when it is fully turned on and booted up, you need the HTC Sync drivers installed. Seemingly you don’t want the full HTC Sync application though, as this might cause trouble, but I didn’t verify that. I found that the drivers are available on their own to download and install.

3) Install the HBOOT driver on the PC

In order to let your PC communicate with your HTC Desire handset when it is in the boot menu, you need the HBOOT driver installed. You can download the driver here. Unfortunately, there is no installer with these drivers, so you will need to do the following:

  1. Turn off the HTC Desire handset
  2. Hold down the Volume Down key and press and hold the power button. This will boot the phone in to the “HBOOT menu”.
  3. Plug the handset in to the computer via USB. Your computer should now detect a new device but it won’t have the drivers to successfully install it.
  4. On the computer, go to Start, right-click on Computer, click Properties, and select Device Manager. 
  5. Look for the an entry called “Android 1.0” that should have a little yellow triangle next to it.
  6. Right-click on the “Android 1.0” line and select Update driver software.
  7. Select Browse my computer for driver software and locate the directory to which you just expanded the zip file.
  8. Hit Next and continue in the positive through any warnings that come up (e.g. unsigned driver alerts).
  9. Hit Close and verify that you now have an Android Phone category in Device Manager, with something called the Android Bootloader Interface listed inside it.
  10. Use the Volume Up and Volume Down buttons on the handset to select the Reboot option and push the Power button to select. The phone should reboot in to Android as normal and be detected by Windows as an HTC Desire.

We’re done installing the HBOOT driver.

4) ‘Root’ and install a new recovery image

Now for the fun bit. Up until now, no lasting changes have been made to your phone. This is your last opportunity to chicken out. Steps after this may eat your puppies and generally cause misery if they go wrong.

Most of the other guides out there seem to treat this as two separate stages, but these days it can all done automagically using a tool called Unrevoked.

  1. Download the Unrevoked tool for the HTC Desire.
  2. Run the downloaded program – no installation required.
  3. Plug in the handset via USB if it is not already plugged in and make sure it is in Charge Only mode.
  4. Enable USB Debugging mode on the handset by going to Menu » Settings » Applications » Development and ticking the USB Debugging option.
  5. Hopefully Unrevoked will now recognise your device.
  6. Follow the warnings and instructions provided by Unrevoked and let it do its thing.

The phone will reboot multiple times as Unrevoked works its magic. Keep an eye on the Unrevoked screen to see when it’s done. It will tell you near the bottom of the window.

So that’s the phone ‘rooted’ and with a custom recovery image (ClockworkMod) installed.

5) Install CyanogenMod

The final stage is to install the CyanogenMod 7 ROM to the phone. You also need to install the standard Google applications as they are not included in the main CyanogenMod ROM for copyright reasons.

  1. Download the latest stable release of CyanogenMod 7 for the HTC Desire (GSM version) and save it somewhere on your computer.
  2. Download the Google Apps package for CyanogenMod 7 (scroll down to near the bottom of the page for the download link) and save it somewhere on your computer.
  3. Switch your HTC Desire in to USB storage mode so that you can copy files on to the SD card.
  4. Copy both of the downloaded files in to the root directory of the SD card.
  5. Turn off your HTC Desire handset.
  6. Hold down the Volume Down key and then press and hold the power button.
  7. Use the Volume Down key to select Recovery from the menu. Select it using the Power key. The phone should boot in to the ClockworkMod menu.
  8. Although not essential, I recommend backing up your old system ROM image to your SD card. Use the volume controls to navigate to Backup and restore and click the optical trackball to select (many of the other buttons simply turn the screen on and off).
  9. Select Backup by clicking the optical trackball. Your current system image will be backed up to the SD card (so make sure your SD card has enough space).
  10. Once completed, you will be back at the ClockworkMod menu. Navigate to Install zip from sdcard.
  11. On the next menu, navigate and select Choose zip from sdcard.
  12. Navigate and find the Cyanogenmod zip file and select it using the optical trackball.
  13. If you are sure you want to go ahead, navigate to the Yes – Install… option and select it with the optical trackball. CyanogenMod 7 will be installed.
  14. Once you have done that, repeat steps 10 and 11.
  15. Navigate and find the GoogleAps zip file and select it using the optical trackball.
  16. Navigate to the Yes – Install… option and select.
  17. Once completed, use the back button to get back to the root menu of ClockworkMod where you can select Reboot system now.

All being well, the phone will now reboot in to your new CyanogenMod 7 installation. You will need to go through all of the setup procedures like the phone was new and then restore all the data you saved right at the start in step 1, and reinstall all your apps.

That’s it! We’re done. Enjoy your Gingerbread-flavoured goodness! I hope this post has helped you through your upgrade. If something went wrong and your phone’s bricked, tough – you were warned before you started.

I would love to know how you get on and hear what you think of the ROM once you’re running it. Leave a comment!

References

I put this post together because I found that I had to get information from all over the internet in order to do this upgrade. As a courtesy, here are the pages that I ended up using, and to which you may wish to refer in case of difficulties.

  • The official CyanogenMod wiki page – out of date, but still covers some aspects well.
  • <a href="http://www.mydaily-gadget el viagra es con receta.com/how-to/8663-how-to-root-the-htc-desire-gsm-cdma-with-unrevocked” onclick=”_gaq.push([‘_trackEvent’, ‘outbound-article’, ‘http://www.mydaily-gadget.com/how-to/8663-how-to-root-the-htc-desire-gsm-cdma-with-unrevocked’, ‘How to root the HTC Desire using Unrevoked’]);” title=”How to root the HTC Desire using Unrevoked”>How to root the HTC Desire using Unrevoked – dates back to the days that Unrevoked only did the rooting, without the ClockwordMod installation.
  • The Unrevoked for Desire download page.
  • The Unrevoked wiki covering installation of the HBOOT drivers