Skip to content

Instantly share code, notes, and snippets.

View digitalWestie's full-sized avatar

Rory digitalWestie

View GitHub Profile
@digitalWestie
digitalWestie / github-issue-scheduler.rb
Created August 26, 2015 13:34
This script uses the github api to take issues from repos and arrange them into an html-format work schedule ordered by number and milestone date.
require 'octokit'
def print_schedule(issues, start_date, end_date)
date = start_date
weeks = number_of_weeks(start_date, end_date)
issues_per_week = 3
issue_index = -1
le_text = ""
weeks.times do |i|
le_text << "<h3>Week starting #{date.strftime('%e %b %Y')}</h3>"
# USAGE (in ruby interpreter)
#
# require './tiree-data.rb'
# wind_speed = 5.0 #in m/s
# result = estimate(wind_speed)
#For estimating E-44 output
def estimate(windspeed)
#some rounding to make sure ranges are intact
windspeed = windspeed.round(3)
@digitalWestie
digitalWestie / worksheet1.md
Last active August 29, 2015 14:00
Worksheet 1 for BGT course

##Worksheet 1##

Models in greater detail

A model represents an entity which we want to persist. As you can see by opening files under /app/models/, models are classes which inherit from ActiveRecord::Base. ActiveRecord gives us vital functionality for communicating with our application's database e.g. for selecting, searching, and saving records. In rails, you can interact with your models (and by proxy, database) using the rails console. To start it, just run rails console or rails c for short. It's more or less just like using the ruby interpreter (irb) except you get access to all of your application's classes & modules.

Using rails console try:

  1. Select a collection of all stations from the database
  2. Save a new station to the database
@digitalWestie
digitalWestie / mod.rb
Created July 23, 2014 00:14
MoD open data spreadsheet to json enricher with latitudes and longitudes
require 'csv'
require 'json'
#take a csv of transactions e.g. http://data.gov.uk/dataset/financial-transactions-data-mod/resource/b8d720dc-d6b0-4875-b9fe-7d135cb1c14e
#compare with postcodes csv from: https://github.com/Gibbs/UK-Postcodes/raw/master/postcodes.csv
def extract_latlng(postcode)
unless postcode.nil? or postcode.size.eql?(0)
first_part = postcode.split.first
first_part = "M5" if first_part.eql?("M50")

Dearest Scotland,

In recent years it has brought me great joy witnessing you begin to realise yourself. You've begun to notice something's been missing from the picture this whole time... your people.

This new picture won't always be pretty. You will need to be strong. It will take courage not to hide your problems, or whitewash your past. The reward is indeed worth the effort. There is an abundance of opportunity that needs to be discovered.

Anyway, I'm sure you'll do fine on that journey. In the meantime, here are a few other things I'd like to ask you to do:

  • Understand we have a finite planet, yet we have an almost infinite human landscape of creativity, imagination, frustration, fulfilment, joy, and pain.
@digitalWestie
digitalWestie / catmap.html
Created December 8, 2014 16:05
Cateran Map
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="UTF-8">
<title>Fusion Tables and Google Maps API Example: Custom Markers</title>
<style>
body {
@digitalWestie
digitalWestie / d3clock.js
Last active December 23, 2015 06:29
How to draw a clock highlighting a duration of time using d3 js
var drawClock = function(selector, start_hour, start_minutes, duration_in_minutes){
var pi = Math.PI, width = 240, height = 240, radius = Math.min(width, height) / 2;
var hour = (2*pi) / 12.0;//12 hours or 360deg = 2 * pi;
var minute = hour/60;
var svg = d3.select(selector).append("svg") //Add svg element to selected element
.attr("width", width) //Set height and width of svg
.attr("height", height)
.append("g") //Add a g element to svg element
.attr("transform", "translate(" + width/2 + "," + height/2 + ")"); //Translate g element to centre of canvas
@digitalWestie
digitalWestie / withinTime.js
Created February 9, 2017 16:11
Momentjs function to check whether a time fits within a set time range, in hours and minutes, excluding dates.
/*
Dates are ignored, only tests moment objects are within a time range of hours and minutes.
Supports times past midnight e.g. 01:00 is in between 23:00 and 03:00 etc.
*/
var withinTime = function(start, end, t) {
//normalise year/month/day
var now = moment();
start.set({ year: now.year(), month: now.month(), day: now.day(), seconds: 0 });
@digitalWestie
digitalWestie / tweets_blob.js
Last active June 6, 2017 14:35
An example of using the Blob / createObjectURL web API: bundles tweets as a CSV and presents a download link;
var csvDownload = function(){
var t = $('p.TweetTextSize');
var CSV = [];
for (i = 0; i < t.length; i++) {
CSV.push('"' + t[i].innerText + '"');
}
CSV = CSV.join('\n');
@digitalWestie
digitalWestie / turnout.md
Last active June 7, 2017 22:16
Factors correlating with predicted turnout change in England & Wales

What matters in predicting voter turnout?

A few days ago I briefly got involved in The Bureau Local's Voterpower Hack. Participants were provided with demographic and political data sourced from the Office of National Statistics, the Cabinet Office and the British Election Study.

During the hack I got chatting to political journalist Emma Yeomans who was looking into drops in predicted voter turnout.

We were both interested in understanding what factors are linked to voter turnot. Using numpy, a scientific computing package for Python, I used the numpy.corrcoef method to output correlation coefficients for the features in the dataset of England & Wales constituencies.

Does single living cause low turnout?