Clickable Table Rows In HTML 2015-03-09

Tags: html, jquery

To make an entire row of a table clickable in HTML, as though you clicked a link in one of the columns, is pretty easy. I’ll be using jQuery to demonstrate but the general concepts don’t require it.

The first thing to do is to delegate a specific link as the action, in case there’s more than one link in the given row. The other links will still work as normal, but if you click elsewhere in the table row, it’ll use the delegated link. Just add a data attribute to specify this:

<tr>
  <td><a href="example.html" data-row-link>Click Me</a></td>
</tr>

And then a little JavaScript to tie up the action and change the cursor. Find all the links with our chosen attribute, walk up the DOM to find the containing table row, and then apply the style and click event to them.

$('a[data-row-link]').closest('tr').css('cursor', 'pointer').click(function(e) {
  $(this).find('a[data-row-link]')[0].click();
});

And that’s it! Now if someone clicks anywhere on that table row, it’ll execute the delegated link. If there’s more than one link marked with data-row-link, it’ll use the first one found. If no link is found with the attribute, the row behaves as a normal table row. An alternative way would be to find all the links in the current table row, and if there’s just a single link, use that as the row link, but that’s an exercise left for the reader.

Demo

UK Top 40 Chart Data 2015-03-06

Tags: ruby

I was looking for a way of getting the current chart data for the UK, but there don’t seem to be any data sources that provide JSON or XML feeds for it, for whatever reason. Fortunately though, the BBC provide a printable page with the data, which is dead simple to scrape. Here’s a Ruby script I wrote using Nokogiri:

require 'json'
require 'open-uri'
require 'nokogiri'

doc = Nokogiri::HTML(open('http://www.bbc.co.uk/radio1/chart/singles/print').read)

# Get the field names from the headings and symbolise them
keys = doc.css('th').map {|k| k.text.downcase.to_sym }

data = []
doc.css('tr')[1..-1].each do |row| # First row is headers
  x = row.css('td').map {|k| k.text}
  data << Hash[ [keys, x].transpose ]
end

puts data.to_json

Et voila, instant chart data to do with as you please. I put up a page with the data for singles and albums.

Signing Android Packages In Gradle 2015-02-21

Tags: android

The new gradle-based build system for Android makes it easy to configure APK signing for release builds, but separating the signing information from the build script makes it easier to keep the secret parts secret while still committing the build script to VCS.

One way to do this is to put the signing information, such as passwords, in a properties file and load that data in the build script. If the properties file is absent, it falls back to the default of leaving the APK unsigned, and can be manually signed after building. An example build script is as follows.

// APK signing
def signingPropFile = new File(project.rootDir, "signing.properties")
if(signingPropFile.exists()) {
    Properties props = new Properties()
    props.load(new FileInputStream(signingPropFile))

    android {
        signingConfigs {
            release {
                storeFile file(props['signing.keystore'])
                storePassword props['signing.keystore_password']
                keyAlias props['signing.alias']
                keyPassword props['signing.alias_password']
            }
        }

        buildTypes {
            release {
                signingConfig signingConfigs.release
            }
        }
    }

}

And in a file named signing.properties include the following:

signing.keystore=example.keystore
signing.keystore_password=my_password
signing.alias=release
signing.alias_password=my_password

Make sure to add signing.properties to your gitignore file (or equivalent) to prevent it being committed. You could also add a signing.properties.example file to explain how to configure the necessary variables.