trying an un-annoying lightbox

Lightboxes are really irritating. No users I ever speak to like them, but all website owners love them – communication problems there, maybe?

Here’s why I don’t like lightboxes:

  • They usually override keyboard functionality. I use my escape key to clear fields and I use my arrow keys to navigate pages – don’t overwrite that. I know best, not you.
  • They’re unnecessarily schmancy and animated – if I opened a lightbox, chances are I want to look at a picture and nothing else. Leave me alone otherwise. I don’t want to see your great “close” icon or any of that crap so just drop it!
  • Some are nearly impossible to close

There are probably a bunch more reasons, but you get the idea.

My lightbox stays out of your way. It doesn’t override any standard keyboard behaviour and it doesn’t use visual fluff to irritate you. What it does do is open a big version of the picture you clicked on so you can see it in more detail. When you’re done, it closes. Here’s how you use it:

  • Click a flickr image to open the lightbox (this might be the last time you need your mouse/trackpad)
  • j = next
  • k = previous
  • o = open the flickr page for this image
  • q = close the lightbox
  • You can also click anywhere to close the light when it’s open

If you’re wondering why j,k,q; use Vim for a day. I would’ve used e to open, but who’s going to remember that?

I’m probably going to implement a resizing thing for people with small monitors so that screens don’t get flooded – if this affects you, please tell me whether you’d like the process to automatically detect your browser size, or whether you’d prefer to handle it yourself. I’m aware that this will affect basically all portrait images – this will probably make me make it automatic. Pictures are pretty pointless if you have to scroll, but I’m tired now and can’t be bothered.

If you want the code for this, view source and find the javascript yourself. There’s a PHP file to make Flickr API calls, but that encapsulates my API credentials. If you can’t figure out what to do here, holla so we can all have a good laugh.

that’s a big one

Transmitting file data …………………………………………………………………………………….
…………………………………………………………………………………….
…………………………………………………………………………………….
…………………………………………………………………………………….
………………………………………….

I must write out 1000 times…

Copying directories resets permissions
Copying directories resets permissions
Copying directories resets permissions
Copying directories resets permissions
Copying directories resets permissions
Copying directories resets permissions
Copying directories resets permissions
Copying directories resets permissions
Copying directories resets permissions
Copying directories resets permissions
Copying directories resets permissions
Copying directories resets permissions
Copying directories resets permissions
Copying directories resets permissions
Copying directories resets permissions
Copying directories resets permissions
Copying directories resets permissions
Copying directories resets permissions
Copying directories resets permissions
Copying directories resets permissions
Copying directories resets permissions
Copying directories resets permissions
Copying directories resets permissions
Copying directories resets permissions
Copying directories resets permissions
Copying directories resets permissions
Copying directories resets permissions
Copying directories resets permissions
Copying directories resets permissions

Not 1000, but you get the idea. Fuck.

impress yourself

Just recently, I realised how important impressing yourself is when trying to maintain enthusiasm with your job. Doesn’t really matter what you do (as long as you care!), but things can go stale if you keep doing the same thing over and over, and never really provoking an “AWESOME! I did that!” reaction. Even if it’s only something small (at 8 hours a day, 5 days a week, little things can be fairly impressive!), it can give you a needed boost to productivity (ugh), enthusiasm and general satisfaction with work, life and all that!

Personally, I get my kick from cleaning really crappy data. Lucky for me, I’ve had a lot of crappy data to clean recently, so I’ve been able to flex my XPath, Regex, semi-complex MySQL and image manipulation muscles relatively frequently. If you’re as much of a fanatical cleaner and hoarder as I am, cleaning data is probably for you. Grab a 50MB CSV and try to programmatically make sense of it. It’s fun! I promise.

Unit testing

This is something that’s been in my peripheral vision for some time now. I’ve periodically been struggling to see the need for unit testing in general, without any justification. I can obviously see the benefit of making sure that your code all works and, seeing as I frequently work on ecommerce sites, I can see it causing far fewer headaches when making changes to purchase processes – simply being able to run a script to see if anything I changed works right.

However, one drawback of unit testing as a concept is that computers are, as a rule, infallible when it comes to this sort of thing. Humans, on the other hand, are completely fallible. If I make a change to some code in my checkout process that has a knock-on effect I didn’t count on in my unit testing (like changing the way delivery is calculated/stored/whatever), I wouldn’t necessarily foresee there being any problems in the email that gets sent after a transaction is completed (that may seem pretty esoteric, but it happened today). Part of this issue arose because I didn’t write the original site, and there was no way for me to detect that this could’ve caused a problem without going through every file on the site and manually checking that there was a problem, but another part could have been solved if a good unit testing framework was in place.

Now, when I say “good”, what I really mean is “comprehensive”. Anyone can write a good unit testing framework and here’s how, in my opinion. You test /every single dependency/. Everything. Bar nothing. If unit testing could’ve solved my problem today, it would’ve been done a little something like this (not exactly like this because the code on this site is largely a mish-mash of procedural and I-don’t-quite-understand-OOP-so-I’ll-give-it-my-best-shot – I assume it would’ve been very difficult to express this as a unit test).

Say I have a method that outputs this email that gets sent. I would write a unit test to capture the output of that method (when supplied with sample data from my database table, for a little extra reliability). I would then take this method and write my own version of it inside my unit test, so that I know it’s correct and compare the output of the two methods. If they differ, I would (PHPUnit) assertSame(legacy_method_output,my_method_output), and the test would pass if I hadn’t fucked it up. Now, the perceptive among you will have spotted something wrong here. In order to write this unit test, I would first have had to know about this email’s pre-disposition to causing problems in the first place. This, in this case, is the entire battle. Furthermore, I would have had to completely rewrite the method, solely to test that the old method hadn’t been broken in some way. For future testing purposes, this is really useful but, chances are I’d just rewrite the method and move on.

All of this isn’t to say that unit testing is fundamentally flawed. Far from it, in fact. I can see that it’s an incredibly useful tool for documentation and future-updates. When I come back to code that already has a unit testing framework, I’d simply make my alterations, run my unit tests until they all pass, then write some more to cater for my currently augmented feature-set. I would then know (with only a shadow of a doubt) that everything is brilliant and nothing is going to get fucked up when I put my code live. That’s got to be worth it! Not only the above, but unit tests seem to me to serve as excellent developer documentation. If you want to know how something’s supposed to work, never mind asking the project manager or client (who probably don’t know, and don’t really care!), you can just look and the guy who wrote it will have told you! Brilliant.

The only (and sadly, this is a pretty substantial “only”) problem is time (as with everything, I guess). You get all of this great peace of mind, but you have to put time into it. And it’s not just a small amount of time either, it’s a lot of time. Once you’ve written all your code (maybe doing it as you go along – 30 minutes a day or something) you then have to write tests to try and break it, and cater for every potential outcome that could arise from user or developer input of the code you wrote. That’s a large investment of time. I can’t quite decide if the net gain is quite worth the input, but I’m tipping towards a yes. I spend a lot of time a bit stressed about whether a modification I’ve made is going to cause unexpected problems, and I’d really like to be able to be more confident with this. I’m also one of those people who likes doing little scripty things, and gets a great sense of satisfaction from ticking boxes and watching “make test” throw out 100% success. Maybe this is for me, after all!