home

git or Versions.app with MacVim diff

I’ve seen on the Versions Google group, there’s a python script for integrating Versions with MacVim diff, but because Versions doesn’t appear to be completely contextual when it comes to executing the script, I was getting the GUI load with none of my .vimrc stuff, so it was no good really.

I tried to write a PHP script to do this, as that’s what I’m most familiar with, but I also hit this hurdle so it was time to dust off my (formerly almost nonexistant) bash knowledge to try and get this done properly. I believe I’ve come up with a fix.

When writing this, I came across two problems. One being that Versions doesn’t escape space characters in the arguments is passes to your script, so it’s not just a simple case of export HOME=”/your/home”; mvim -d $@; that gives you at least 3 files to play with, so I’ve /tried/ to be a bit clever and parse what I think is a file into an array and use it as arguments. It’s not terribly elegant, but it works and I’ve been using it a couple of days.

The only issue is that you’ll have to change the path to your home directory in the script, because I don’t know of a way to detect it. If there is one, please let me know!

Download the attached zip, chmod +x and put it in your ~/Library/Application Support/Versions/Compare Scripts/ folder, restart Versions, then you should see it as an option in your File Comparison dropdown.

To use this with git, I kept the file the same, and then git config –global diff.tool /Users/Me/Library/Application Support/Versions/Compare Scripts/mvimd.sh and it works great with that too. Go me.

bash git macvim script everything svn versions vim

code

an open letter to Sony

Dear Sony,

if ((int) $month === 2){
    if ($year % 4 === 0) $days_in_month = 29;
    else $days_in_month = 28;
}

apocalyPS3 date february time

code

steal buffalo’s planner slider in mootools and css

On BuiltByBuffalo’s Proposal Planner, we use a much-revered slider thingy that we’ve had a lot of compliments on. We recently received an email asking for a little tutorial on how to put this all together. The main brief is actually pretty esoteric, and you probably won’t be working with designers of the calibre of Jason Reynolds, but this should show you how to put such a thing together.

First off, you need 3 elements. I’ve gone for divs because they’re fairly non-descript and semantically pretty viable for use here. I’ve gone for the following structure:

<div id="scale" class="m1" rel="6">
  <div id="full">
    <div id="marker"></div>
  </div>
</div>

The rel on this div refers to the maximum number of positions on the slider. Unless you shamelessly steal all my source images, you might need to change this! The class refers to a CSS class that denotes the width of the guage element (#full), defined thus:

#scale.m1 #full {
  width: 43px;
}

Because the marker element (#marker) is floated right, it will always stay to the right side of the guage div, so there’s no need for any more CSS than this.

Now that we have our layout and have defined our images (I won’t insult you by teaching you how to set a background image. If you really don’t know that, the declarations are in the source!), we need a method of getting between them. In the actual planner, we do a bunch of ajax-y stuff between stages that’s not relevant here, so here’s a simple breakdown. We’ve got 2 links, next and previous. We, therefore, need 2 event methods to handle input.

In our Marker class, the initialize method deals with identifying the container, marker and guage elements so that we don’t need to keep traversing the DOM to get them. It also sets the current state of the marker and gleans the capacity from the rel attribute (even though it shouldn’t really – you can hardcode it if you want!). We then have our next and previous methods, which just check that their respective states are valid (we don’t want the marker trying to go to 0 or 7, so we stop it from happening).

The method do_morph is where all the legwork is done. We construct the class to Fx.Morph to (mootools requires the whole CSS declaration, not just the element) then define some other options for the morph (namely the duration and a method to run when it’s completed). The completed function calculates the background position needed on the marker image so that we display the correct state.

I’m not great at explaining things, but hopefully that’s done a little to make it clearer for the person who asked for this post, and easy to steal for the people who are that way inclined!

Enjoy the demo:

buffalo craptorial css html javascript mootools slider

code

2a rookie mistake, a programming challenge and a fresh start

It’s gone. 4 years and 30GB of photos gone because of a stupid lapse in concentration. All my originals are just nowhere – rsync –delete really fucked me this time!

Never the one to look on the dull side of things, this presented an interesting challenge. Seeing as I don’t know exactly when it happened, the chance of an undelete was pretty slim. So I turned to Google to see what was available to me in the way of backing up my flickr photos. It’s not quite 30GB of originals, but 1145ish decentish resolution exports is much better than nothing.

There are a couple of things available, but the only notable one is Java, slow, crap and doesn’t download some photos with no explanation, so that’s that. Seeing as I basically only wanted a straight backup of everything of mine on flickr, I figured that there had to be a way that I could just get a list of all my photos so that I could archive them and be done with it. This wasn’t really the case, so I opted for using flickr’s API calls for everything in sets and everything not in sets. Because, if I ever decide to put it out in public, I wouldn’t want it getting abused; I’ve decided to use flickr’s authorisation API to confirm the user as well. It works really well, and is downloading my originals as we speak.

The only potential issue is, because it puts your set photos in their own directory, there will probably be some duplicates, but I’d rather have 2 of one than none. If you want a copy of the script, you’ll need OSX/Linux with PHP 4 at least. Leave a comment and I’ll email it over.

CLI Backup in action (by jaspertandy)

And, now it’s time to start a new era of photos.

annoying api backups flickr idiot mistakes

code, photography

8PHP 5.3, iconv, OSX, Symbols Missing _libiconv

I’m not sure how many people will have this problem, but I did so this will remind me.

PHP 5.3 release, for some reason, does not like my default install of iconv. Firstly, I made the grave mistake of failing to point PHP properly at an install in /usr/local/, so replaced my OS installation of iconv with a new one. This was all well and good until I started opening apps that needed specific parts of OSX’s default iconv. So, an OSX restore later, we’re at square one. PHP keeps telling me various crap when I’m trying to compile that it didn’t work with iconv because it’s the wrong version, but would fail during make because it couldn’t find the correct symbols.

annoying problems compile configure fucking waste of time iconv leopard make osx php snow leopard symbols missing _libiconv

code, mac

1Die, spaghetti-code, die.

spaghetti

I never really got what spaghetti code was until today. That might sound dumb, but it’s a term that is quite widely-used in different contexts so it can be an odd one.

Today, I have been working with code that is devoid of any design, regard for future developers or useful documentation. Like so much PHP, the end result works, so it’s great. Except it’s not.

Imagine each line above is a function or method call, which has its own integral part to play in the execution of a web page (in this case). The entry and exit points are single entities, but what goes on in between is nothing short of scary!

pretty

Ideally, I like to see code the main vein of which is there at the start and the end of the app’s execution. Logic can branch from this as far as it wants to get what it needs, but it’s ultimately serving a purpose for the main line. The more I delve into OOP in many languages, the more I realise that procedural code is quite liable to spaghetti, whereas OO is not. That’s not to say it’s impossible, but it’s easier to have one method that sets everything in motion, configures your program and then receives and redirects input in OO than it is procedurally.

Since I started properly getting into OO, I started to liken the execution cycle of a procedural program to a glass of water falling. Everything starts from the same point, but over time everything splays out and does its own thing. Debugging procedural code, therefore, is analogous to blindly cleaning the aforementioned spillage – there is a good chance that the part of the spillage you’re working on has nothing to do with what you’re actually trying to achieve – no matter how relevant it looks!

Unfortunately, I blame PHP for the natural progression of spaghetti code from procedural to half-assed-OO. It’s so easy to get things done without really knowing what you’re doing that it’s actually borderline dangerous. A mishmash of procedural and OO is the absolute worst thing to debug, as it normally combines the horrible execution cycle of procedural apps with the potentially confusing trail of inheritance. Let me tell those who don’t know – it is VERY obvious when you’re working with code written by someone who does not understand inheritance (and I don’t mean what it is, I mean *why* it is) and it almost always makes their half-baked bastardisation of OO impossible to work with.

Have I had a difficult day? You could say that.

code diagram oop php procedural programming spaghetti tongue-in-cheek visualisation

code

260: Documentation

260: Documentation

You try being creative when you’ve spent all day describing parameter data types.

365:365 code documentation moleskine work

365.1, code

I love CSS

I finally got the strength to give IE6 even less attention than I usually do, off the back of a post from Roger Johansson. Because of this, I also feel confident that it’s acceptable to use techniques available to more advanced browsers. The idea that all websites should look the same in all browsers is unrealistic and inappropriate, so this has opened up a whole new world of CSS that I can now freely use, and I’ve found it really fun. For example, in older browsers, all my category and archive links in my “sidebar” will be white, but new-browser-users will be rewarded with easier differentiation between link colours with the following gem:


#menu > li li:nth-child(2n) a {
color:#656565;
}

And to tidy up the last paragraph margins and get rid of the unattractive superfluous margin, I can now use this and be safe in the knowledge that people who care about this sort of thing will be able to see/appreciate it:


#menu div.content p:last-child {
margin-bottom: 0;
}

I don’t know how some people can dislike CSS. It’s such an awesome way of working.

Enthusiasm fuelling this post brought to you by grape juice and vodka.

456bereastreet css css3 IE6

code, internet, jspr

Custom Ordering of WordPress posts.

I seem to be becoming the go-to guy for WordPress in my circle of friends. I don’t mind—I’ve grown fond of pulling apart other people’s code, and the monster that WordPress is always makes that interesting.

Last night, I was asked if I know how to order posts differently in The Loop. I don’t trust The Loop. I much prefer to use WP_Query, as I feel more in control, but my friend had already written a lot of functions that seemed to depend on using The Loop, and I’ve never been one for rocking the boat where live code is concerned!

bug hack post order wordpress

code, wordpress

1Twitter Stuff 0.3

happy downloading!

It’s been literally minutes in the making, but it’s here. Now with lovely added templates, to save you lazy people even more leg work, you can do things like:

hack twitter twitter-stuff wordpress

code, wordpress