Tools

I don’t think humans should do boring or repetitive things. Humans are better at creating and learning then doing the things that machines can do faster and more accurately. This is a strong enough belief that I’ve put it in my resume.

My excellent friend Curtis Lassam seems to be of the same opinion, as his fun little romp, Automation For The People, demonstrates. You should go check it out (and mad props, Curtis, for using Github as a blogging platform). It’s funny, tells a great story, and you might learn something.

 

What is it?

A library to return the name and branding colour of a bank by the first few digits of a card number.  It will also help you generate CSS files to use.

What is it good for?

Changing the colours on a billing page to match the user’s banking colours, making you look impressively switched on (and maybe a little creepy).

Is there a demo?

There Sure Is.

What issues does it have?

There are only entries for users which have contributed them, so some banks will be unmatched (unless you contribute!).

Users may think you’re stealing their credit card information, despite the fact that they’re literally about to give it too them.

How do I…

Install it? npm install banks-db

Ensure my bank is present?  Like So.

Use it from Javascript?  Got you covered.

Get the docs and source?  Right Here.

 

Git (and its ilk) are tools for working collaboratively (especially with hosted services). Your commit messages are your best weapon for communicating context, and every collaborator, including Future You, depends on context to be productive. It’s not opinion, it’s Science!

See, human memory is so bad it can be erased by passing through a doorway. We can defeat doorway-induced time wasting (not to mention the change of screaming “what the hell is this?!” at code someone, maybe Past You, wrote) with great commit messages.

Randall from http://www.xkcd.com knows what's up.
(Image courtesy of XKCD because Randall is a champ.)

A great commit message:

  • Is never ‘left behind’ by code changes (unlike comments)
  • Gives all the info you need (ticket numbers, reasons for change, expected behaviour changes)
  • Shows relevant changes around your change
  • Summarises everything in 50 characters or less as the ‘subject line’

All this info, the context of the change, makes problem solving (read: coding) more efficient.  Good context helps any collaborator; there’s evidence that context-based approaches to problem solving are more effective.

Continue Reading

 

A quick tip. It’s relatively easy to build a test, or an entire suite, and never actually ensure it gets run. Which makes all the effort that goes into it worthless AND gives you a false sense of security. It’s like having a photo of a security camera feed instead of the feed: “Of course everything’s safe, look!”

So, every time you create a new test file, assert that false == true. And run it. And make sure it fails.

Otherwise you’re wasting everyone’s time, especially your own.

 

I love IDEs. There. I said it. All Y’all can fuck about with VIM and TextMate until the cows come home. Give me a project navigator, tabs and windows to drag around, an entire environment I can commit to a repo. That’s where I’m most comfortable.

I use the fantastic RubyMine for Ruby projects. I’m often digging about in other areas for debugging and might not want to navigate all the way back to my project. But I don’t have too. All you have to do is click the little RubyMine icon (second from the left at the top in the picture) to be taken to your project’s root directory.

What are you hovering for? This isn't XKCD

RubyMine’s File Dialog

(Bonus tip: The folder icon, on the far right of the toolbar, shows hidden files and folders)

 

JQueryUI has updated, and I want to take advantage of one of the new features (the response event for auto complete, fired after a search result is returned but before the menu is displayed), which means updating to the new version of JQuery… And re-creating my theme.

Now, “Luckily” I’m constrained in the colours I can use by another developer’s choices (I have to look pretty in their page, and was directed to use their colour scheme exactly), but that still left me with the prospect of trying to remember all the damn colour values, shades, effects and additional wunkery to apply, a prospect of slow revision over several hours, and not one I was looking forward too anymore then I’d look forward to being repeatedly slammed up against a large, moist, shaved yak covered in flaming mashed bananas. Bananas are fucking repulsive.

Reading through the CSS file produced last time, though, I don’t have too! Line 50 of jquery-ui-1.8.23.custom.css contains this gem:

1
To view and modify this theme, visit http://jqueryui.com/themeroller/?ffDefault=Verdana,%20Arial,%20sans-serif&fwDefault=normal&fsDefault=1.1em&cornerRadius=6px&bgColorHeader=444444&blahblahblah.......

That link takes you to the theme roller, with all your previous settings, ready to download suitable for the latest version of JQueryUI.

Fucking. Rad.

 

Because this just tripped me up, and I’d like to think that I’m not the only totally braindead developer out there.

Git is wonderful. You shouldn’t use any other source control. Even if your co-workers don’t get it (It’s because they’re stupid). Disk is cheap, you can afford to keep it all local. It’s fast, it’s flexible, it’s not actually that hard either.

But sometimes you might be trying to fetch a remote branch from your development server. You’ve checked documentation for the syntax and you know you can show your remote branches by issuing git branch -r, and the branch you want isn’t there.

What the Fuck?

Well, it’s actually embarassingly simple and not worth the 5 minutes you spent re-reading the documentation like a cargo-culting toddler whining about how unfair it is he has to eat dinner(“But it says this should wooooooorrrrrkkkkkkk!“).

git pull

.

That’s all. git pull won’t bring across any changes for the current branch (because there aren’t any) but it will bring across metadata changes, like new branches.

FFFFFFFUUUUUUUUUUUU………

 

I’ve been using a gem called rails3-jquery-autocomplete to easily hook up AJAX autocomplete into my views.  It’s fairly easy to use if a bit muddily documented.  However, I’ve recently had cause to want to pre-filter my input before using it in a search, and it seems that’s not a feature that the library offers.

 

Well Now It Is!  Providing they accept my pull request, which is anything but certain.  I’d never used rr before (lovely mocking/stubbing framework, writes much more fluently in my humble and naturally correct opinion), or shoulda, and frankly probably made arse-awful code and will bring down judgemental wrath.  I’d appreciate pointers if there are any readers who are fluent in Ruby and can give critique, it’s one of the hazards of working Forever Alone that you don’t get much feedback.

*{Crickets}*

O…K, I’ll just show you a usage sample then.  Both of you.

ZimController < ActionController::Base

  def more_horror (term)
    "Horrible #{term}"
  end

  :autocomplete :punishment, :name, :term_filter => :more_horror
end

 

Now, whenever the user is selecting a torture from one of their extensive list (drowning, Christmas with relatives, ASP.Net, those espresso flavored Monster’s, thumbscrews), before the auto-complete does its thing to return a list of possibilities, “Horrible ” will be prefixed to the selection, thus ensuring maximum pain and torment.  Take thatDib!

(As a somewhat worrying aside, either WordPress or Opera knows the spelling for thumbscrews.  Quite off putting.)

 

What is wrong with this guy’s tutorial?  No thoughts?  OK.

How about this guy?  (Who is possibly even more egregious.)

I’ll give you a hint.  Even ScottGu is doing it.  In fact, he’s kinda responsible.

CODE DOES NOT BELONG IN VIEWS WHAT IS WRONG WITH YOU PEOPLE?

*{Sigh}* It feels better to have that out there.

Code belongs in Controllers.  Constraint Code belongs in Models.  Views?  They’re meant to be templates, and just templates.  Code should be limited to conditionals and loops, but only where those loops might change their display formatting.

Helpers are where you’re supposed to put formatting functions and template manipulation code.  Helpers are also usually not just littered all over your damn templates because Hey, they’re View Related right?.  Wrong. Also, I hate you.  Sure, it’s up to the individual developers to follow MVC principles, but most people are sheep.  You’re just encouraging them to write shitty applications.

There are some cures.  If you put your helpers in your App_Code folder, they’re fairly self-contained (although the syntax is still disgusting).  You can declare them as extensions to HtmlHelper (Same link as before).  And, using Single File Generators you can turn them into reusable libraries (Thanks David Ebbo!)  Just please, please, don’t put this crap directly into your views.