May
5
Introducing Semaphorify.info
Filed Under 42 (Life the Universe & Everything), Computers & Tech, Software Development on May 5, 2014 | 1 Comment
Quite a few months ago I was joking with Guy Serle of the My Mac Podcast, and the topic somehow turned to flag semaphore. I think I’d sent the guy an iTunes review in mores code for a joke, and then Guy challenged me to do it in flag semaphore. I figured it would be easy to find a converter on the net, but, for the first time in a long time, the internet let me down! When I couldn’t find a converter I registered the domain www.semaphorify.info with every intention of getting a converter up and running in a few days. Then, real life got in the way, and the domain sat there for months, until yesterday, when I unexpectedly had a free afternoon, and I finally got my converter written!
You can now go to the site and convert text to flag semaphore, play a crude animation of the signal, and even share a link to the signal. E.g. this link takes you straight to the conversion of “I love semaphores” to semaphore.
Feb
25
Bad Habits are Dangerous – Always Code Defensively!
Filed Under Computers & Tech, Software Development, Security on February 25, 2014 | Leave a Comment
I sometimes take some stick for having a very defensive coding style. When ever I find myself making an assumption I throw in code to test it. “This function will only ever be called with a positive number”, OK, then add a test to throw an exception should a negative number be passed. You don’t want bad data ricocheting through your code because goodness knows what damage it will do! Similarly, my style is to always use explicit syntax, and, to avoid syntax shortcuts – sure, the ternary operator takes up less space on the screen, but there’s a price to pay for that terseness – it makes your code harder to read and hence to debug and maintain.
However, one of my very biggest bug-bears is the failure to brace control statements like conditionals and loops when they’re operating on a single line of code. This is the trap Apple fell into so spectacularly this week.
Jul
26
OS X Service – Word Count (and More)
Filed Under Computers & Tech, Software Development, My Projects on July 26, 2013 | 9 Comments
Inspired by a recent episode of The Mac Cast I decided to see if I could come up with a simple way of getting a word count of a PDF on OS X using only tools that come standard with the OS.
Because of OS X’s Unix underpinnings, all Macs have access to the Unix wc
command which calculates word counts on given input. OS X also has a handy built in Terminal command to access the contents of the clipboard (pbpaste
). This leads to an obvious simple manual solution:
- Open the PDF in Preview
- Select All Text
- Copy to clipboard
- Run the Terminal command:
pbpaste | wc -w
This is a bit cumbersome though, so I went on to create a simple OS X Service to calculate the word count of any selectable text in any app (the fact that this is even possible, let alone easy, is why I love OS X).
For those of you just looking for a copy of the Service, you can download it here:
To install the service simply extract the automator file from the ZIP archive and copy it into either the Library/Services
folder in your home directory, or the system-wide service folder /Library/Services
.
Once the Service is installed you can use it in almost any OS X app (specifically in any app written using the standard Cocoa libraries) by selecting some text, right-clicking on it, and selecting the Word Count service:
When done the results will look something like this:
Those of you who want to see how easy this Service was to write, read on and I’ll walk you through it.
May
24
Converting Unix Time Stamps to SQL Dates (ISO 8601) with Perl
Filed Under Software Development, Computers & Tech on May 24, 2013 | Leave a Comment
I spent quite some time this afternoon finding a reliable way of converting Unix Time Stamps (UTS) to the ISO 8601 format used in SQL databases like MySQL and PostgreSQL that does not get confused by timezones. In the end the final result is, as is so often the case with Perl, very short and simple, but since the Googles failed to find the answer for me today, I thought it would be worth sharing in case it’s of use to others in the future.
use DateTime; # Function to convert Unix Time Stamp to ISO 8601 Date # Arguments: # 1) The Unix Time Stamp to convert sub uts_to_iso8601{ my $uts = shift; my $date = DateTime->from_epoch(epoch => $uts, time_zone => 'UTC'); return $date->ymd().q{ }.$date->hms().'z'; }
The algorithm is very simple, use DateTime
‘s from_epoch
function to a DateTime
object in the UTC timezone (AKA Zulu). Then assemble the output as YYYY-MM-DD HH:MM:SS
, and append a z
for Zulu. MySQL and PostgreSQL can now use the string to populate Date
or Timestamp
columns.
As an example, the Unix Time Stamp 1369410796
converts to 2013-05-24 15:53:16z
.
Dec
29
OS X Service for Stripping Geotags from JPEG Images
Filed Under My Projects, Photography, Software Development, Computers & Tech on December 29, 2012 | 1 Comment
Back in 2011 I wrote a blog post explaining how to create an OS X Service for stripping keywords from image files. In this post we’ll use the same technique to create a Service for stripping geotags from JPEG images.
As with the keyword stripping service, there are two prerequisites for this action, one is required, one is optional. You absolutely MUST have install EXIFTool installed, and it would be good if you also had Growl installed, but it’s not essential.
Aug
6
Announcing XKpasswd.pm Version 0.2.1
Filed Under My Projects, Computers & Tech, Software Development, Security on August 6, 2012 | 1 Comment
This is a minor bug-fix update for XKpasswd (my Perl random password generation module). It squashes two minor bugs which came to light while updating www.xkpasswd.net to use version 2 of the module.
- When the
custom_separator
option was left blank, no separator was used, rather than the expected random separator. - When the
custom_separator
option was left blank or set toRANDOM
, and thepad_char
option toSEPARATOR
, the results were un-expected, different random character was used for each, rather than the same random character.
For documentation and detailed release notes on version 2 of the module, see the release notes for version 2.0.
Aug
4
Making an XKpasswd Automator Action
Filed Under Computers & Tech, Software Development, My Projects on August 4, 2012 | 2 Comments
A few weeks ago on the Chit Chat Across the Pond segment of the Nosillacast, I mentioned that I had an OS X service set up to generate a random password using my XKpasswd Perl module and copy it to the clipboard. Listeners enquired as to how they would go about doing that, so as promised, here’s a quick tutorial.
Obviously this tutorial is for Mac OS X users only, because OS-wide Services and Automator are OS X features. The screenshots are taken on 10.8 Mountain Lion, but this same technique definitely also works on OSX 10.7 Lion, and probably even on 10.6 Snow Leopard. This tutorial also assumes that you have downloaded the XKpasswd
module, and saved it somewhere on your computer, along with either the sample dictionary file included with the module or one of your own making, and that you know where on your computer those files have been saved. In other words, you need to have XKpasswd.pm
and a text file with one word per line somewhere on your hard drive. In my sample code I’m going to assume you’ve installed the Perl module to the suggested location, /usr/local/xkpasswd/XKpasswd.pm
, and that you have customised the sample dictionary a little (more secure that way), and saved it to /usr/local/xkpasswd/dict.txt
.
Jul
29
Announcing XKpasswd.pm Version 0.2
Filed Under Computers & Tech, Software Development, My Projects on July 29, 2012 | 2 Comments
I spent the weekend majorly re-factoring XKpasswd.pm
, my Perl random password generation library. V0.1 was the last thing I wrote before reading Perl Best Practices, and looking back on that code really illustrated the value of that book when used in combination with the perlcritic code analyser.
The new version of the module provides all the functionality the old one did, and more. The refactoring has made the module simpler to use from within scripts, as well as easier to modify and extend. Some new features have also been added, including the ability to use the www.random.org web service as the source of randomness for the library. A full list of bug fixes and new features is included below.
I had hoped to distribute this version as both a ZIP file and a .PKG file, but XCode 4.4 is not being cooperative on the new Mountain Lion, so that will probably have to wait until version 0.3.
Update – 6 August 2012: The link below has been updated to point to version 0.2.1 of the code. Details of the bugs fixed in the release notes.
Jun
17
WebifyImages.pm – My Image Editing Scripts (v0.2)
Filed Under Computers & Tech, Software Development, Photography on June 17, 2012 | 6 Comments
Yesterday I posted my thoughts on watermarking images for uploading to the web. This post formed the basis of myself and Allison Sheridan’s discussions in the Chit Chat Across the Pond segment on tonight’s Nosillacast Mac Podcast. During the discussion we talked a little about how I watermark my images, and I realised that I hadn’t released a version of my image processing scripts since 2008! I promised I’d remedy that, so today, after a little tidying up, I’m releasing the current snapshot of my scripts under the FreeBSD license.
I’m not releasing these scripts as a polished software package that’s ready to use, but rather, as a starting point for anyone who wants to create their own watermarking scripts. If you’re not prepared to get stuck into the command line and a little Perl (VERY little is needed mind), these scripts are of no use to you!
The scripts rely on the free and open source ImageMagick command line image editing tools, so you’ll need to install ImageMagick before you get stuck in. If you’re running OS X, I’d recommend installing ImageMagick via the free and open source MacPorts package manager.
Oct
3
Introducing www.xkpasswd.net & xkpasswd.pm
Filed Under Software Development, My Projects, Computers & Tech on October 3, 2011 | 6 Comments
Steve Gibson really set the cat among the pigeons with his Password Haystacks site a few months ago, and XKCD’s ‘Correct Horse Battery Staple’ web comic brought that message home to many many nerds and geeks. The basic idea is that you’re better off making your passwords long and memorable than short and complex. In the simplified XKCD example the password is simply made up of 4 common words, but Steve Gibson suggests you should add some padding around those words to make the passwords much harder to guess.
This is a lovely theory, but I’m not imaginative, and I need to invent a lot of passwords every week, so I wrote a Perl module to do it for me, and called it xkpasswd.pm
. The first thing I’m announcing today is that I’ve made this library available for free for both personal and commercial use (under the FreeBSD license), you can download it from www.bartb.ie/xkpasswd.
It’s great to have a library for nerds to play with, but what about everyone else? Well, that’s where my second announcement comes in, I’ve also created www.xkpasswd.net, a simple web front-end to the xkpasswd.pm
module.
In case anyone is wondering where the name comes from? It’s a mashing together of XKCD, and passwd
, the Linux/Unix command for changing passwords. Because I used to use Solaris, and hence the yppasswd
command, I liked the idea of keeping the prefix to just two letters, hence xkpasswd
, rather than xkcdpasswd
.
For any programmers interested in using the Perl module, it has no prerequisites other than base Perl, and all you need to get started is the module and a dictionary file to point it at. The download package contains the module, a sample dictionary, and a sample Perl script which invokes the module.
In the future I also plan to release a JavaScript-only version if the library so that others can embed xkpasswd-based password generators in their own sites without needing Perl CGI support on their servers. I’m also experimenting with creating an OS X Service to allow people to easily generate xkpasswd passwords from anywhere within OS X, and perhaps even a native OS X Application. So stay tuned!