Reading GET variables with JavaScript

I found a great piece of code whilst trying to figure out how to read get variables with javascript.


function $_GET(q,s) {
s = s ? s : window.location.search;
var re = new RegExp('&'+q+'(?:=([^&]*))?(?=&|$)','i');
return (s=s.replace(/^?/,'&').match(re)) ? (typeof s[1] == 'undefined' ? '' : decodeURIComponent(s[1])) : undefined;
}

Credit goes to Online Aspect

Posted in Code | Leave a comment

Apple Mail 5.0

Apple Mail 4.2 is a product in dyer need of upgrade. Whilst it’s an excellent product with unequaled stability, it has major Usability issues, and it lacks any useful Syncing ability. I am also told that addon’s are unreasonably tricky to develop (whilst I have no first hand experience of this, the dearth of extensions supports this).

Simple things like allowing the preview pane to appear on the right (rather than below) should be standard on a modern email client, yet it falls to 3rd party developers to jury rig extensions that ultimately detract from the stability of the application. Mail’s usability also falls short in other areas which are standard on most other email clients, such as colour coding emails, advanced search and attachment checking (a great Thunderbird feature).

“Places” and “People” are also features that could add value to Mail, tied in of course with the same features from iPhoto.

But the email client isn’t Apple’s only failing, the entire email protocol is in dire need of an overhaul, and it seems that Google’s Wave isn’t going to come to save the day afterall.

Microsoft’s Exchange is currently the defacto standard in office email, yet it’s horribly bloated, requires considerable administration and most importantly is ridiculously overpriced. This presents and opportunity for an open source alternative that offers the best features of Exchange and a task that Apple is ideally suited to.

Needless to say, such a product must be multi-platform. OS X based GUI products for Apple’s Servers would also give their hardware line a great boost. Ultimately though, the platform needs to be a product that can be installed as an addition to any server, rather than an operating system in it’s own right.

Posted in IT | Leave a comment

Run Forrest Run!

Motivation is a killer for me when it comes to fitness. The most prominent word for me when it comes to working out is “Later”. The Gym had some good points for me, it allowed me to monitor my progress and gave me some real goals. Predictably though it wasn’t enough, and my visits to the Gym eventually petered out.

Recently though I’ve actually wanted to go running. I actually do enjoy it, but the effort and lack of progress monitoring keep me coming back to “Later”. Whilst browsing the iTunes App Store the other week I was looking through the deluge of running applications and was very impressed with the previews I saw and the comments I read.

There were 3 or 4 that seemed to be good contenders, but I settled on the Nike+ app, which with it’s excellent progress reports and sub £2 price looked to be an great product.

To the distress of my legs, I’ve been out for a few runs since then, and it’s living up to my expectations. I get to see my route mapped out for me with a colour representation of my pace. Whilst running, I get audio progress reports, which I can set to either distance or time. It tells me my mile pace and how I’m comparing to previous runs.

Once I’m done with my run, it uploads the details to the Nike+ online portal where I can compare with other runners. I don’t though, I don’t think my ego could take it :) .

All in all, a great app and one of my best App Store purchases.

Posted in Health and Fitness | Leave a comment

Handy code: ifelse()

As with most web developers about half of my code is collecting information via forms (the other half is presenting that information). When a form is submitted there are a variety of variables that I might want to display back to the user in the form elements. The code snippet below simplifies how I handle which variable to display.

Previously my code for an input field would have used a lot of nested inline if statements to determine which variable to fill the field with. It might have looked something like this:

echo '<input type="text" name="email" value="' . (($_POST['email']) ? $_POST['email'] : (($user['email']) ? $user['email'] : 'Email') . '" />';

The code above would show the posted email address first, and if that’s not present defer to one from the database. If neither of those are present then it would display a label, “Email” in this case.

That’s a nightmare to manage, and it looks nasty. So I wrote a function called postOrNot($post, $other) which simplified the inline if statement a touch. If the first variable was present, it was displayed, if not then it would display the 2nd.

With the introduction of “func_get_args()” to the function it can handle any number of arguments, falling over to each one in turn, and finally returning false if none are present.

function ifelse(){
if(func_num_args() < 2) trigger_error("ifelse() requires 2 or more arguements", E_USER_ERROR);
else {
$args = func_get_args();
foreach($args as $arg){
if($arg) return $arg;
}
return false;
}
}

It's a function that I use pretty much every day and saves me lines and lines of code.

Posted in Code, php | Leave a comment

Magic Mouse vs Wicked Weasel!

I decided to treat myself to something I’ve lusted after for a while but not yet worked up the courage to purchase.

I’d been pondering getting a Magic Mouse for a while. My first experience at the Apple Store didn’t convince me. It’s petite size just didn’t seem quite right. Apple Magic MouseI’m used to wrapping Miss Palm and her 5 loving daughters around a Logitech MX1000, so the idea of something as sleight as the Magic Mouse was something I couldn’t really get to grips with (excuse the pun :D ).

I finally decided that if I wasn’t happy with it as a permanent replacement for my array of venerable MX1000′s then it wouldn’t be a total loss as it would make an acceptable companion for my MacBook Pro.

First impressions were my usual irrational “stop wrapping everything in plastic goddamnit” rant whilst having a coffee with @alanogden and not being able to resist having a fiddle (with the mouse!).

When I got it home I wasn’t terribly surprised to find that I got used to it very quickly. You hold it a lot more daintily than the MX1000 of course, which gives you the room to use your fingers for the various gestures it allows. The 2 finger swipe to the left/right for forward/back webpage movement is particularly useful.

All said and done, I’m pleased with my purchase and I’ll probably take it to and from work as it’s worlds improved over the horribly flawed Mighty Mouse.

Posted in Other | Leave a comment

This is going to kill me

When I was 18 I spent 3 months in the Army. Before I joined up I was relatively fit and in decent shape. When I left, I was very fit and in incredible shape.

Unfortunately it’s been downhill from there and now I’m very unfit and bordering on needing to shop at High and Mighty :s.

I’ve been on the verge of saying “enough is enough” for a few months now, and last Monday I took the plunge and joined a gym again.

Remarkably I’m actually excited to be going to the gym. I’ve had 2 nights so far where I’ve been close to not going, but apart from a meeting that kept me at work too long, and an evening where it’d have been stupid to go (sooo much pain from the day before) I’ve kept at it. 4 days a week for the past 2 weeks and I’m still going strong.

My god it hurts though! I went to a short class that teaches you some work out techniques today. Granted I’ve experienced a lot of it before, but it was very useful to get a catchup class. We did some interval training on the treadmill, incredible workout, exhausting but so satisfying!

Goal so far… fit into my linen suit again (don’t laugh, it’s a great suit for the summer!).. Goal for the future, I’m going to think big and try for a marathon.

Posted in Health and Fitness | Leave a comment

3 posts before failure

Ugn!! I swore that this 3rd attempt at a blog would be successful, and that I’d update it regularly with insightful and useful comments to amuse and inform.

3 Posts in the first 2 days of my new site, and then silence… this seems to indicate that I am not cut out for blogging. I shall however persist, and today’s very short post shall contain 2 things, a link to the tools from the old mousepilot website, and a list of future posts which I shall complete.

So, the link. At 3DPixel.net we combined my two very simple tools from the old site along with a couple of others and created our tools website 3dpx.net. Mainly just as a place where things we use every day can reside, but also as a tool for anyone else to use.

….and now the list:

  1. Complaining post about the complete lack of consideration and awareness in society, particularly focusing on muppets in Sainsburies and plebs on the road
  2. Tutorial on how to right a funky jquery/php application to upload, resize and crop images
  3. Complaining post about benefits

I swear to the gods of beer and pizza, that I’ll update again soon :)

Posted in Code | 1 Comment

Very Excited about CSS3

After spending a portion of the weekend coding my shiny new site I’ve really got the CSS bug again. So I was delighted when I checked Smashing Magazine for new articles and stumbled on their latest article about CSS3!

As usual, their article is an amalgamation of many many sources and very comprehensive. Wide support for attribute selectors is particularly good news as it means no more damn id’s on inputs! Psuedo classes look particularly useful for lots of things, but support for odd/even in table rows is pretty cool. Columns, Shadows (text and background), Border Images, Word Wrap are all very cool, but what I’m bowled over to see is multiple layered backgrounds. It’s a feature I’ve craved for so long, but honestly never expected to see, AND IT’S HERE!

Posted in Code | Leave a comment

A new beginning without Internet Explorer 6

IE6 DeadAt 3DPixel made the decision a few months ago that 7 years was a pretty good run for Internet Explorer 6, and that enough was enough. So we killed support for it in all future projects.

At the time, I don’t think I really considered the implications this would have to future designs, but 2 projects down the line, I have to say THANK GOD. I feel like a coder reborn (cheesy I know), I’ve rediscovered the joys of transparency, inline-blocks, and padding that doesn’t make me want to tear my own face off.

I’m also actually taking the time to look into CSS3, now that there’s actually a chance I’ll use it. Rounded corners are a godsend!

So I’d encourage any other coders out there to follow in the footsteps of 3DPixel, Facebook, Apple.. and numerous other big name websites, and lets kill it off for good!

Posted in Code | Leave a comment

CSS Rounded Corners

My first post on my shiny new blog is being written whilst I’m actually coding the template.

The CSS3 spec gives us access to rounded corners without the need for images and loads of xhtml.  Just add the following to the appropriate <div>.  I’ve absolutely no idea whether this works in IE7+ but I suspect it doesn’t and as it’s for my personal blog, I don’t care.  Internet Explorer users deserve to look at shitty looking pages tbh :p

-moz-border-radius: 5px;
-webkit-border-radius: 5px;

Posted in css | Leave a comment