Remove iBook Citations With a Keyboard Shortcut

Whilst reading @AshFurrow’s excellent book on Functional Reactive Programming (do read it, it’s an refreshingly different way of going about writing Obj-C), I was finding that I was required to copy/paste a lot of code snippets from the e-book into AppCode.

This is not a nice process: if you’re reading it via the PDF, Preview.app doesn’t correctly OCR the line spaces and what you paste into your IDE is a horribly mangled form of the code which won’t compile and has to be tediously repaired. (it also unnecessarily copies the line numbers).

If you’re reading via the Kindle app, that flat-out prevents you from copying any text at all from the book (fuck you, Amazon).

So that leaves the iBooks for OS X app, which does a great job at copying the text, but encases it in a citation block like so:

“RAC(self.imageView, image) = [[RACObserve(self, photoModel.thumbnailData)  2     ignore:nil] map:^(NSData *data) { 3   return [UIImage imageWithData:data]; 4 }];”

Excerpt From: Ash Furrow. “Functional Reactive Programming on iOS.” iBooks.

This is a feature built into iBooks which cannot be turned off – doh, resulting in:

After a while of removing all that each time I wanted to paste a snippet, I relented and wrote an Automator script to strip this out whilst it’s in the PasteBoard:

Here is the script: https://gist.github.com/iandundas/7863c6c248f76e14a3a8

After you have saved the Automator script shown in the screenshot, then you can hook it up to a keyboard shortcut in System Preferences:

Now when I paste, I get:

RAC(self.imageView, image) = [[RACObserve(self, photoModel.thumbnailData) 
    ignore:nil] map:^(NSData *data) {
    return [UIImage imageWithData:data];
}];

Much better. It’s:

  • removed the line numbers
  • removed the surrounding quotation marks
  • removed the citation text

Now it’s clean enough to paste into your IDE.

Comments

Looking Back for Inspiration Part 1: Gigsniffr

Content mirrored from my dev-blog at Tacks.io

Perhaps my fondest memory in all my time spent coding was the all-out dash to build a complex PHP web-app for my undergrad dissertation. It was the biggest project I’d ever attempted, and was the starting-gun I’d been waiting for, the opportunity to really dig into something.

Prototype Homepage

Man, I was so psyched about my idea – it was a web-scraper named Gigsniffr which aggregated a set of concert ticket websites. The killer feature was that when it saw a ticket come onsale for a user’s favourite band, it alerted them via a tweet (back when Twitter was still conceived of as a computer-human API platform). At the time, nothing much like this yet existed (2007 was also when Songkick launched), and I knew for sure that it could be big if I could just get it launched.

This was before any of these music sites had a published API for me to use, so I had to really research how to put together a reliable web-scraping algorithm that could repeatedly spider the ticket sites.

The project was incredibly fun: I was developing into (for me) the complete unknown – I wasn’t amazing at PHP, I had no experience of managing a long-running web-scraper service, I had no permission to scrape these sites, I had a hard deadline to hit, and nothing to distract me.

There were many problems to solve: how can you work out the names of a user’s nearest cities, without Google’s Map API; how do you build an engine to accurately scrape many different websites, abstracting away from the quirks of each (answer: invent own XPath tricks); how do you diff the data collected with that taken an hour previously?

I soon found that the first pass of data gathering was easy – but updating and correcting this dataset was actually much harder: I was attempting to keep track of gig cancellations, date changes, and variances in band names (Red Hot Chili Peppers vs RHCP etc), and it was a rathole without end. Much fun to solve!

I did manage to get a prototype working in time for the deadline – an achievement which to this day I’m proud of. At the presentation were two local entrepreneurs who took an interest in my idea and took me out for lunch to discuss it.

Alas – I ground to a halt somewhere between finishing the proof-of-concept and launching a user-ready product. After I’d delivered the proof-of-concept and completed the course, the pressure was off and it was time to relax – I’d hit the deadline and could now continue developing Gigsniffr at my leisure, right after I’ve been to these music festivals and learned Ruby and started a job and…

.. and it was gradually forgotten. The would-be investors were interested only in funding marketing, and only once the app was finished – they were not interested in financing even the peanuts I’d need to sit down and complete it. I was also messed up after a nasty breakup. I found myself in a job that absorbed 10 hours of coding stamina per day, which I then quit to take a Masters – without any real gap after the undergrad. If I’m honest, I’d got what I wanted from the project, and was moving on – so Gigsniffr was shelved.

I’ve a profound admiration for those running startups which actually launch, especially those who succeed longterm – it’s an amazing feat. People say that ideas are cheap, and that building them is the hard bit. What they don’t mention is that building the interesting parts of a project is pretty easy, but FINISHING it is nearly impossible in comparison. Finishing a product really is hard. But the burst of real energy and creativity I summoned for Gigsniffr is something I’ve been chasing ever since.

Prototype Admin panel

Prototype scraping control panel

Introducing Tacks

There’s an app that I’ve been working on in my spare time, which I’ve actually been using personally for several months, but which I’ve not managed to pat together into an App store release.

It’s a simple app based on something I needed each time I found myself in a new city when I was travelling: when you arrive, you constantly see lots of places you’d like to return to, and it would be super handy if you could just drop a pin there, add a short title and thus remember it for later. After a while, you’ll see a map studded with interesting places that you yourself have added, and it’s simple to find your way back later on. When you go to the next city, you start a new map, etc.

Inspired by Sam Soffes talking passionately about developing Cheddar on the Founders Talk podcast, I’m going to open-source this app and blog about its development too.

Without further ado, http://tacks.io.

Comments

‘Exposing NSMutableArray’ : Worth a Read

“let’s note that every Obj-C method is actually a C function with two additional parameters. The first one is self which is a pointer to the object being receiver of the method call. The second one is _cmd which represents the current selector.”

Even as a fairly experienced Obj-c developer I did not realise this, (though had often wondered where _cmd came from in a method’s scope – I assumed magic). This was a good read, and something a bit different, too (though I didn’t understand much when it dipped down into assembly).

Bartosz Ciechanowski: Exposing NSMutableArray

Comments

Ruby IMDB Script Will Order & Rate a List of Films

I should paste this short script that I’ve written for converting an unordered list of films into a list ordered by the IMDB score (and also tagged with the genres). It worked great for tidying up the 350+ list of “you must see this” films that people have recommended to me through the years..

It will take an unordered list (with optional bracketted year to improve matching accuracy), e.g.:

The East (2013)
Shutter island
Stephen Fry: The Secret Life of the Manic Depressive
The Departed
Alan Partridge: Alpha Papa
Only God Forgives
You've got mail
Withnail & I
The Draughtsman's Contract
The Deal
Winter's Bone
A World Apart (1988)
We need to talk about Kevin

and will return:

<<<< RESULTS >>>> 
The Departed:  8.5  #Crime #Drama #Thriller
Stephen Fry: The Secret Life of the Manic Depressive:  8.2  #Documentary
Shutter Island:  8.1  #Drama #Mystery #Thriller
We Need to Talk About Kevin:  7.5  #Drama #Thriller
The Draughtsman's Contract:  7.3  #Comedy #Drama #Mystery
Winter's Bone:  7.2  #Drama
A World Apart:  7.1  #Drama
Alan Partridge: Alpha Papa:  7.1  #Comedy
The East:  6.9  #Crime #Drama #Thriller
You've Got Mail:  6.5  #Comedy #Drama #Romance
Only God Forgives:  5.8  #Crime #Drama #Thriller
The Deal:  5.7  #Comedy #Romance


=== Not Found... ===
Withnail & I

You can then paste this list into something like Workflowy or TaskPaper and navigate via the hashtags to filter by genre.

It’s available as a Gist. To install, clone the gist, run bundle install, add your films to the provided film_list file, and run ruby IMDB.rb.

Comments

Mail.app Fix for Fastmail SMTP in Mavericks

I’ve been having intermittent issues with Fastmail’s SMTP service in Mavericks, where Mail.app will sometimes repeatedly reject the correct password (and thus refuse to send mail).

The fix is to force it to use port 587 for SMTP (it claims it’ll try 25, 465 and 587 by default, but this doesn’t seem to be reliable):

Preferences –> Accounts –> Fastmail –> Account Information –> Outgoing Mail Server –> Edit SMTP Server List –> Advanced –> Use custom port: 587

Comments

iOS 7 Custom Transitions - Basic Example

There’s really not much sample code knocking around for iOS 7 custom transitions yet (or else Google is broken..): I guess that NDA is still only freshly lifted.

I’ve put together a simple example of how to present a new UIModalPresentationCustom-style Modal UIViewController with a UIViewControllerTransitioningDelegate managing the show. Have a play with this, it’s simple enough to be self explanatory and useful for experimenting with – I hope it helps.

View the source on GitHub

Useful resources:

keywords: UIViewControllerTransitioningDelegate, UIViewControllerAnimatedTransitioning, UIModalPresentationCustom, transitioningDelegate

Comments

Careful Using the Motion-layout Gem

(for now, at least)

Although the motion-layout gem is what turned me onto the magic of Cocoa’s AutoLayout system in the first place (and it is magic – I eventually built Songdrop almost entirely using this new way of placing views), I discovered that trying to learn it using this Gem (which claims to simplify) was causing me more harm than good due to a number of inherent problems.

Read on →

Happy 40th Birthday, Dark Side of the Moon

"The best album by my favourite band ever"

Comments

Saharan Desert Rock. Black Keys Meet Manu Chao.

Bombino – Nomad

Fans of Manu Chao will love this new release from Tuareg guitarist Omara “Bombino” Moctar. It’s really fantastic.

That the lyrics are political in theme is not surprising, given the following (taken from Wikipedia):

Later in 2007, tensions grew again in Niger and ultimately erupted into another Tuareg Rebellion. The government, hoping to thwart the rebellion in all its forms, banned guitars for the Tuareg, as the instrument was seen as a symbol of rebellion. Additionally, two of Bombino’s fellow musicians were executed, thus forcing him into exile.

whoa.

Comments