Categories
blog

Creating a download click tracker in Rails 4 – Also, Run-ins with Turbolinks

A Friday lunchtime double feature for you.

The task: create a click tracker, to keep a rough (accuracy isn’t of core importance, but why skimp?) measure of the number of time s a link has been clicked by site users.

Here’s some sample code I used for the new version of GiantsLive which contains a digital downloads feature.

The task is a fairly simple one, it doesn’t even require a controller, but here we use a migration to create a stats table, and a model to provide a simple API.

The ‘object_key’ I’ve used refers to an AmazonS3 object’s unique name (within a bucket), this is because each ‘fixture’ has several video files available to download.

Migration

class CreateFixtureDownloadTrackers < ActiveRecord::Migration
def change
create_table :fixture_download_trackers do |t|
t.integer :fixture_id
t.string :object_key
t.integer :download_count, default: 0
t.timestamps
end
add_index :fixture_download_trackers, [ :fixture_id, :object_key ], :unique => true, :name => :tracker_index
end
end
view raw gistfile1.rb hosted with ❤ by GitHub

Model

class FixtureDownloadTracker < ActiveRecord::Base
belongs_to :fixture
def self.track(fixture, key)
FixtureDownloadTracker.find_or_create_by(fixture: fixture, object_key: key).incr
end
def self.counter(fixture, key)
FixtureDownloadTracker.find_or_create_by(fixture: fixture, object_key: key).download_count
end
def incr
self.download_count += 1
self.save
end
end
view raw gistfile1.rb hosted with ❤ by GitHub

Usage

#Find current status of the counter
FixtureDownloadTracker.counter(fixture, obj_key)
#Track a click on an item
FixtureDownloadTracker.track(fixture, obj_key)
view raw gistfile1.rb hosted with ❤ by GitHub

You could create a helper method to present the detail neatly, but that’s up to you. Hope that code is helpful, if you have any suggestions on how to clean it up any further do use the comments below.

Part 2: Turbolinks causing 403 problems

Or maybe just one. Rails 4.0 introduces a new feature called https://github.com/rails/turbolinks/ which is intended to reduce the amount of server requests caused by a page change, in very simple terms it means that instead of looking for CSS, JS and font files every time you click a link, it just asks for the HTML + images. I was getting a strange quirk in my tracking code whereby every click was creating two increment actions. I finally figured out the problem by looking my logs. An excerpt here:

Started GET "/fixtures/get/1/videofiledotext" for 127.0.0.1 at 2013-09-06 14:16:30 +0100
Processing by FixturesController#get_download_uri_for as HTML
Parameters: {"fixture_id"=>"1", "object_key"=>"videofiledotext"}
.....
Redirected to https://s3-eu-west-1.amazonaws.com/giantslivetv-video/videofiledotext?AWSAccessKeyId=xyz&Expires=123&Signature=ggy%3D
Completed 403 Forbidden in 54ms (ActiveRecord: 43.6ms)
Started GET "/fixtures/get/1/videofiledotext" for 127.0.0.1 at 2013-09-06 14:16:30 +0100
Processing by FixturesController#get_download_uri_for as HTML
Parameters: {"fixture_id"=>"1", "object_key"=>"videofiledotext"}
.....
Redirected to Redirected to https://s3-eu-west-1.amazonaws.com/giantslivetv-video/videofiledotext?AWSAccessKeyId=xyz&Expires=123&Signature=ggy%3D
Completed 302 Found in 50ms (ActiveRecord: 19.2ms)
view raw gistfile1.rb hosted with ❤ by GitHub

You’ll notice the “Complete 403 Forbidden” first, then “Completed 302 Found” second. Turbolinks appears to have been requesting the file, failing and then resorting to a page reload. This caused the tracker to be triggered twice, and the statistics to be incorrect.

There is an open ticket on github regarding this issue. [h/t @StuartGibson]

A fix

As per the Turbolinks documentation, adding the html data attribute data-no-turbolink on a parent tag will disable any turbolink action from occuring. So, in my case:

<ul data-no-turbolink="">...

Problem solved.

Categories
blog Music

New Music From Gungor: “Wayward & Torn”

The new album ‘I am Mountain’ is on its way, American Songwriter have a preview of a track. Sounding like a background hum from the set of Justified, it has a moody southern blues feel. While the track is supposedly set apart from the rest of the album, it paves a welcome path.

Listen to the track now

If you haven’t heard of [one of my favourite bands] Gungor… A little context, in the form of a video:

Updated
——-
iTunes pre-order & preview available here.

Categories
Friends

The Mechanics of Telegraphy | Pete Huey

Young Peter has been making the most of his (not so) new (anymore) job and this week got to take a group of young people around the Belfast Telegraph building on Royal Avenue, Belfast. He’s taken some great behind the scenes shots which you can see on his blog.

Categories
blog

Sorry, I didn’t quite catch that? — Sally the sign language interpreter

A while ago I launched a new website for my friend Sally, who’s both a PhD candidate at Queen’s and a successful professional sign language interpreter for hire.

Check out the website at
http://signlanguageni.com

The simple site has two aspects: professional and academic. It’s somewhat adaptive (but perhaps not quite ‘responsive’?), has been developed to accommodate video content on each page if a video BSL interpretation is available and in future will allow Sally to receive feedback on various research projects.

Sally is a BSL/English interpreter and a first year PhD translation student. Through her research, she is exploring the demographics of the deaf signing population in Northern Ireland and the resources and opportunities available to this linguistic minority.

She adopts a balanced approach to practice and research, and is currently organising an academic conference on Sign Language and the Politics of Recognition in addition to her studies and interpreting work.

Freelance professional sign language interpretation services in Belfast, across Ireland and the UK.

Categories
blog Video editing

Converting HD Video for use in an SD DVD project

Why a DVD, why can’t everyone just go digital…?

Unfortunate as it is, real world clients’ requirements tend to rely on 1990s technology.

I’ve been putting together DVDs for the New Wine conference, which is generally consists of:

  • complete the edit…
  • export full quality
  • export to MPEG-2 in Compressor
  • drag into DVD Studio
  • burn the disk

This doesn’t work very well for projects which originate in high definition, partly because of your finely rendered type and partly because of the poor transcoding magic performed going directly from 1080 to 576 for DVD.

WHY ME?

Like me, plenty of people out there have learnt everything they know about videography from working on pet projects and tinkering with the tools they have to hand, and stuff like this just isn’t really “in the manual.”

I think I might’ve finally worked out a workflow that should work, should you need wish to put your beautiful HD Video onto a standard definition DVD.

Starting point:

Most of my video projects are in Apple ProRes — captured live or post-event using my Ninja device. The specific variety of ProRes doesn’t matter, frame rates (60i or 50i) and colour depth aren’t the problem here. We’re in 1080 and it looks pretty great. On the computer. And in whatever web format we tend to use.

Output from the edit:

Using your editing software typically you will typically output a full resolution copy of the edit, or a reference movie — just the audio and rendered parts, with pointers to all your other source video files, hidden in a file much smaller than your full copy.

What you would do for the web:

At this point, I usually drag the reference movie into MPEG Streamclip. Sometimes it misbehaves and doesn’t understand the reference pointers; so it might be best just to output a full QuickTime file for transcoding.

Vimeo (the discerning videographers publishing platform of choice?) has a helpful guide on good settings for upload, but basically I do this (my saved “Vimeo 720” preset):

  • Choose MPEG-4 export, using H.264
  • Bump the quality to 100% (no point compromising here)
  • Limit the data rate to 3500 or 5000Kbps depending on how good you want it to look (I tend to choose 5000 for final exports, 3500 for key drafts, 1000 for quick previews)
  • Do whatever you want with sound, AAC / Stereo / 44.1 / 256kbps
  • I tend to scale to 1280 x 720 for output
  • Choose the right frame right
  • Select “Interlaced Scaling” and “Deinterlace Video”
  • Everything else should be right

And a visual representation of the above, if it helps…

vimeo-720-hq-settingsThis creates a pretty good image and the interlaced/deinterlace couplet fixes most “why did my text go fuzzy” issues.

When creating DVDs:

MPEG Streamclip is not the tool for this job. iDVD is Disney. Toast does burn video DVDs but it [ignorant assumption] won’t give you the ability to make the type of interface that you actually want.

So you need to use Compressor + DVD Studio Pro. Nightmare. But they can do pretty much everything you want them to.

Bad assumption:

You can just use the source file, make it convert using one of the provided DVD formats (in Compressor) or just drop it into DVDSP directly and it will create a useable disk. It will, but it won’t look good. All your rendered images and text will be of very poor quality and while much less noticeable the video itself will not be as good.

Larry to the rescue:

Often you’ll find the answer to a video question is answered on Larry Jordan and this is no exception, though it took me a few days of casual searching to find a link to the article entitled Solving Video Compression Problems When Down-Sizing HD to SD — you may notice some similarity in the title of this article…

The basic solution here is this:

  • Pre-compression” — resize the HD movie to an SD frame size without compressing (transcode to ProRes HQ from 1080 to 1024×576 if you’re working in the PAL world) — full details of which settings to use are in the article
  • Then use that exported file as your DVD track source.

Obviously this will take a bit longer to output, but it will provide far cleaner images from which to produce your DVD. In practice it takes significantly longer: on a 2009 iMac, transcoding five 35 minute files took just over 14 hours. Fine if you’ve nothing else to do!

P.S. If you spot any flaws, or have any suggestions or additions to this article please leave a comment below and I’ll consider updating it.

Mastered DVDs

Categories
blog

NI Design Alliance: The Anatomy of Design #002

Just published, here’s part two of the Design Alliance’s series “The Anatomy of Design.”

In this, Matt’s first ever public talk, he discusses the processes involved in creating, managing and implementing design systems in complex products and large organisations; covering mistakes made and how good design makes everything look easy.

Filmed (with young Pete) and edited by yours truly, you can read more about it here.

Categories
blog

A Vidiot’s Summer Travels

There’s a busy summer ahead!

(c) 2012 Chris Nelson/New Wine Ireland

First off: sleeping in field Thursday to Tuesday! The Summer Madness festival returns to Glenarm castle, and I’ll be heading up the volunteer technical team and running the on-screen visuals on the main stage. A circus tent. With the pros from Box42 (recurring theme?) we’ll be providing a bit of camera and vision mixer training to use on live screens; recording about 30 seminars; and finally mastering a take-home DVD on the final night, hoping to have a few hundred copies ready to sell to the campers and group leaders on their way home. All of that and hoping to get a few hours sleep each night.

Next step: I’ll be spending a week in [London*]Derry* (* delete where applicable) filming a practical youth service week on the streets of the city. The ‘On The Move’ project is a reimagination of the original ‘StreetReach’ concept and this year is being supported by the festival itself. Looking forward to using some new lighting gear and having loads of time to get good footage and create a cool promo for next year’s event.

Then: off to Sligo town for another big christian summer festival. This time we’ll be setting up projectors + screens, plasma and LCD TVs, cameras and mixers, sound gear and audio recording devices; both in the main meeting hall and around the event’s campus. Looking forward again to the craic and ‘holiday’ and getting to visit places that feel a lifetime away from Belfast!

The rest of July should be filled with video and audio editing. I’ve some available time in August (so if you have any need for a web developer or video bod get in touch!), but whatever’s spare will hopefully be used putting together a little video + community voting mashup website I’ve been plotting for some time.

Categories
blog

Sage 50 Accounting Import CSVs

TL;DR Download Excel files provided for Sage 50 Accounting Import *

Trying to say nice things: Sage clearly love money. Any time I’ve had reason to get in touch with their cousins at Sagepay, they have always proved to be very courteous and helpful. Not so with Sage 50 Accounting.

I’m building an import tool to manage the flow between a client’s website and their office software. I tried calling Sage for some data documentation or advice. They took details of me and my client, but said no: you need to pay for the annual support and maintenance package for us to talk to you. Talk!

The annual package which costs over £1000.

You’ll want to provide a file in CSV (comma separated value) or Excel format for import but what, I hear you ask, is the specification? Click File > Import on the software package’s menu and you’ll see a recommendation to backup but no samples. However there’s a little green question mark button to the right hand side – if you click it, it will suggest sample files are available in the Program Files folder.

You can hunt for those or you can download the nine Excel files here. *

The hard part comes next – working out what each file is actually for and doing the import. Have fun.

* This zip file and the files it contains are provided as is, without any instruction or warranty, nor claim of ownership or copyright. They are merely provided to help fellow developers out, in the belief that developers are a software company’s best friend — they can sell your product for you to new clients, suggest improvements and give informed feedback.

Categories
linkblog

Linkblog: “Things to Bring on a Trip Around the World”


Things to Bring on a Trip Around the World — Roaming the Earth — Medium.

Three days before my trip, I panicked—I hadn’t packed a single thing. I had procrastinated, hoping my backpack would magically pack itself. What do you bring on a long trip across multiple continents and climates? After much thought and research, I narrowed my belongings down to a select few. It was a painful process.

There’s something delightful about the idea of packing a bag and getting on a plane as Keegan is doing… where to go this summer…?

Categories
blog meaningful labor Video editing

NI Design Alliance: The Anatomy of Design #001

Post updated with video — 10.6.2013 

Last night I attended the Northern Ireland Design Alliance’s first lecture of 2013 and the first in a new series called “The Anatomy of Design.” As I often say I’m not a ‘designer’, but this event had much broader appeal than just to the pixel pusher or crayon merchant.

Stephen McCarthy, a native of Dublin and graphic/print designer by trade, spoke on the acclaimed work of the UK’s Government Digital Services. Focusing on the 10 design principles of the GDS and the launch of GOV.UK (or boring.com as everyone’s favourite doom merchants would have you believe).

NIDA GDS Stephen McCarthy GOV.UK
NIDA GDS Stephen McCarthy GOV.UK

The video is now live on youtube. For updates on upcoming Design Alliance events follow @gooddesignni. The next scheduled event is on June 20th and Matt Coyne will be speaking.

Thanks to Richard and Sarah from CC Skills for hosting it and having us along!