Blog

Tag Archives: Scripts

Align comments in Textmate

Unless I’m using Objective-C, which is fantastically self-documenting, I often like to add comments to parameters to remind me of what they do. For example:

imagecopy($image, $frame, 
          ($x=max($width-$this->topRightCap[kCapWidth], $this->topLeftCap[kCapWidth])), // Destination x
          0,  // Destination y
          $x,  // Source x
          0,  // Source y
          min($this->topRightCap[kCapWidth], $width-$this->topLeftCap[kCapWidth]),  // Source width
          $this->topRightCap[kCapHeight]); // Source height

The only thing is, it looks terrible and is very hard to read. I usually carefully insert spaces before the comments so they line up, but that’s really hard to maintain.

I use Textmate, and found an ‘Align Assignments’ script by Chris Poirier which applies very nice formatting to a block of assignments.

Some trivial modifications resulted in a similar script to align comments. Hit Ctrl-Option-Command-/, and:

imagecopy($image, $frame, 
          ($x=max($width-$this->topRightCap[kCapWidth], $this->topLeftCap[kCapWidth])), // Destination x
          0,                                                                            // Destination y
          $x,                                                                           // Source x
          0,                                                                            // Source y
          min($this->topRightCap[kCapWidth], $width-$this->topLeftCap[kCapWidth]),      // Source width
          $this->topRightCap[kCapHeight]);                                              // Source height

Here it is:

Align Comments.tmCommand.zip

Also tagged , | Comments closed

Facebook News Feed RSS

Tired of either logging into Facebook frequently, or being entirely oblivious to friends’ activities, I was searching for a way to view the Facebook front page news feed as RSS, so I could load it into my news reader and forget about it.

‘Nemik’ has created such a thing and kindly made it available. It was a bit elderly, and didn’t work with the new Facebook, so I jazzed it up a bit.

Put it on a webserver, configure it, and access the URL to view the RSS feed. Probably a very good idea to provide password protection, as well.

Use at your own risk, and Facebook, please don’t sue me.

Download the script here

Also tagged | Comments closed

Counting words in LaTeX documents with TextMate

When working on LaTeX documents in TextMate, the default word count feature isn’t too helpful, as it also includes all of the LaTeX control sequences in the count. There are plenty of suggestions out there, but this is one I came up with, which works the same way as the default word count facility (Ctrl-Shift-N):

#!/usr/bin/env ruby -wKU
 
def pretty(number)
  number.to_s.gsub(/\d{1,3}(?=\d{3}+(?!\d))/, '\0,')
end
 
counts = `detex -l | wc -lwc`.scan(/\d+/)
counts[0] = counts[0].to_i + 1 # increase one to the line count
 
%w[ line word byte ].each do |unit|
  cnt    = counts.shift
  plural = cnt.to_i != 1 ? 's' : ''
  printf("%11.11s %s%s\n", pretty(cnt), unit, plural)
end

This is just a copy of the default statistics action from the Text bundle, but with the ‘detex’ utility added into the pipeline to remove all LaTeX control sequences.

Put this in a new command in the LaTeX bundle, with ‘Selected Text’ for input, and ‘Show as Tool Tip’ for output. I assigned Ctrl-Shift-N as the key equivalent.

Tagged | Comments closed

Apple iTunes Connect Trend/Transaction Report Processor

Process Transaction Reports

I’ve written a droplet which takes a transaction report, as downloaded from iTunes Connect and containing a summary of sales, and produces a single figure representing the total earnings, in a particular currency.

Because the report shows sales for each separate region, a bit of work is required to get a total earnings figure, involving multiplying royalties by number of sales for each region, and then converting each currency type and adding all results together. This droplet does it all for you – just drop the downloaded text file from iTunes Connect onto it and it’ll bring up a summary. A preferences window allows configuration of the currency.

Currency conversion information provided by timegenie.com.

<

p>Download it here: Process Transaction Reports droplet

Also tagged , , , | Comments closed

A OS X service to encode HTML characters

I find myself frequently writing HTML code in comment forms which support use of HTML formatting, which means that I have to encode the html entities if I want them to show up (as in representing ‘>’ with ‘&gt;’, for example).

This gets rather tiresome, particularly if there’s a fair chunk of text to encode by hand.

I used the always-useful ThisService app with a short PHP script which does a htmlspecialchars() on whatever’s passed to it, to create a OS X service called ‘Encode HTML‘. Put it in your Library/Services directory, possibly log out and back in again, and you’ll be set.

Select the text to encode, click the system menu, Services, Encode HTML, and it’ll be automatically encoded in place.

Also tagged , , | Comments closed

Keeping iChat and Adium status in sync with Twitter

I’ve been using Twitter for a while now, and I’ve just started doing ‘global’ status updates across Twitter, Facebook, and my instant messenger account statuses for iChat and Adium. Usually I use MoodBlast, a really nice application which lets me use a global keyboard shortcut to quickly enter a tweet and hit enter to update everything simultaneously.

However, if I want to update from, say, Twinkle on my iPhone (side-note: Wow, Tapulous need to do some serious SEO – their Twitter site isn’t even on the first page of Google hits. I’m on the first page of Google hits for it, ferchrissake) the sync won’t happen. This Ruby script will do the trick.

Read More »

Also tagged , , | Comments closed

Re-organising/assembling uploads for WordPress

Migrating from Serendipity, I’ve had a few hiccups in data migration. It doesn’t help that I’m extremely OCD when it comes to data, so everything’s gotta be perfect.

I had a problem with the way my uploads (the resources linked into the blog) were organised from the old Serendipity days – all in one big ol’ folder – and wanted to re-arrange them the way WordPress does it, which is to arrange them into folders by year and month.

This is also useful if you’re changing your domain, or splitting up one blog into two. The entries link to the old domain/blog, and thus the alternative is to do keep the old site around or muck around with clever redirects.

My way’s neater.

So, I put together a script which goes through all posts, pulls out links to uploaded files, and moves/copies them into a better arrangement, fixing the link in the process. If it can’t find the files, it’ll use a ‘find’ command to attempt to locate them.

In case it’s useful to others, the script is here: reorganise-wp-media.php.zip

It goes in the WordPress webroot; put it there, then edit it to apply your settings. Give it a ‘dry run’ test, make sure all is well, then go for it. Beware, although I used it and it worked okay, I offer no guarantee that it won’t mangle your data, delete random files or eat your dog.

Also tagged , , , | Comments closed

Convert text to iTunes audio book

200805071617.jpgAfter reading a hint on macosxhints on how to create an audio file from text, because I wanted to keep reading my book while I was driving, and figured that holding the book in front of me probably wasn’t the best option, I figured the process could probably be streamlined a bit.

So, I’ve made a service which appears in the Services menu and operates on selected text. So, select it in Safari, or from an eBook in Preview (or Textedit if it’s just plain text), and click ‘Speak to iTunes Audio Book‘ to speak the text into a track in iTunes that will appear in ‘Audiobooks’.

Read More »

Also tagged , | Comments closed