Skip to content

Instantly share code, notes, and snippets.

@MatMoore
MatMoore / Export graph of GOV.UK
Last active January 12, 2018 16:50
Building a graph of GOV.UK
# Run in publishing_api_development
# These queries need reviewing to filter out links to non-live content
\copy (select l.target_content_id,coalesce(d.content_id, d2.content_id) as source_content_id, l.link_type, l.position, case when l.edition_id is null then 'document' else 'edition' end as link_scope from links l left outer join link_sets ls on l.link_set_id=ls.id left outer join documents d on ls.content_id=d.content_id left outer join editions e on e.id=l.edition_id left outer join documents d2 on d2.id=e.document_id) to 'content-links.csv' with csv header;
\copy (select d.content_id,d.locale,e.title,e.description,e.document_type,e.analytics_identifier,e.state from documents d join editions e on e.document_id=d.id and e.content_store='live') to 'content.csv' with csv header;
\copy (select d.content_id, d2.content_id as owning_content_id from documents d join documents d2 on d.owning_document_id=d2.id) to owning_documents.csv with csv header
@MatMoore
MatMoore / gist:1ec26d30f5ee34aceaa8cdb99abf839d
Created February 7, 2018 14:32
How to change the iteration number on a jenkins pipeline with multiple branches
Go to JENKINS_URL/script
Run this groovy:
item = Jenkins.instance.getItemByFullName("content-audit-tool/master")
item.updateNextBuildNumber(371)
We had to do this because we forked a project in github, and our release tags were based on the jenkins build number. So we wanted to start the numbering of the new CI builds where we left off.
@MatMoore
MatMoore / gist:d2eda41c8687c15487c1260d6eb61712
Created April 4, 2018 10:14
Making changes to GOV.UK frontend locally

1. Run a rendering app

  1. Checkout https://github.com/alphagov/government-frontend, install ruby, bundle etc
  2. Run ./startup.sh --live to point to the live content store
  3. Run PLEK_SERVICE_STATIC_URI=static.dev.gov.uk (or wherever static is running) to point to a local instance of static
  4. This will take a minute to render a page(?)

Shared templates are loaded from static via slimmer, which magically merges templates together using nokogiri.

Slimmer may cache templates (?) although I don't think it's supposed to in development mode

@MatMoore
MatMoore / rename_old_rubygems.sh
Last active June 11, 2018 12:50
Remove old bundles that aren't being used any more
#!/usr/bin/env bash
set -euo pipefail
for i in $( ls /data/vhost|grep -v 'lost+found'); do
echo $i
dir="/data/vhost/$i/shared/bundle/ruby"
versions=$(ls -1 $dir|grep -v '.backup');
in_use=$(cat /data/vhost/$i/releases/*/.ruby-version | sed 's/[0-9]\+$/0/' | sort | uniq);
echo -e "in use\n----\n$in_use\n"
@MatMoore
MatMoore / dashboard.json
Created June 12, 2018 16:24
Grafana dashboard for incidents
{
"annotations": {
"list": []
},
"editable": true,
"gnetId": null,
"graphTooltip": 0,
"hideControls": false,
"id": 93,
"links": [],
# Full code here:
# https://github.com/googleads/google-api-ads-ruby/blob/master/adwords_api/examples/solutions/conflicting_keywords/conflicting_keywords.rb
def compare_keywords(negatives, positive)
negatives.each do |negative|
match_type = negative.match_type.downcase
negative_text = negative.text.downcase
positive_text = positive.text.downcase
match = false
# If the negative keyword is more strict than the positive one, it cannot
#!/usr/bin/env ruby
require 'faraday'
require 'json'
response = Faraday.get 'https://www.gov.uk/api/content'
homepage = JSON.parse(response.body)
level_one = homepage['links']['level_one_taxons'].map do |item|
item["api_path"]
end
@MatMoore
MatMoore / registers_clients.csv
Created December 14, 2018 17:20
List of registers clients
URL Language
https://github.com/ministryofjustice/openregister-client Python
https://github.com/robmckinnon/openregister-ruby Ruby
https://github.com/nickcolley/registers.js Javascript
https://github.com/nacnudus/registr R
https://github.com/maxf/node-openregisters Javascript
https://github.com/benlaurie/gds-registers Go
https://www.nuget.org/packages/GovukRegistersApiClientNet/ .Net
@MatMoore
MatMoore / accessibility.md
Last active December 21, 2018 11:28
Notes from (visiting) speakers at GDS

People that can not distinguish colours can understand all information

avoid instruction that rely on colour don't communicate through colour alone People that have low vision are able to see content

default text size is not too small default colour contrast is good the appearance of online content can be overridden (with browser and operating system settings) - and guidance is provided on how to do this is easy to find This also helps people experiencing a situational impairment such as bright sunlight

@MatMoore
MatMoore / constraint-sorter.rb
Created April 1, 2019 16:26
Scripts for getting schema exports into liquibase format
#!/usr/bin/env ruby
current_statement_lines = []
primary_keys = []
other_constraints = []
current_statement = :unknown
lines = File.readlines(ARGV.first)
lines.each do |line|
current_statement_lines << line.gsub("\r", '')