Skip to content

Instantly share code, notes, and snippets.

@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": [],
@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 / 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 / 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 / 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 / live-search.md
Created October 10, 2017 16:49
Review of live search and analytics javascript

Review of live search and analytics javascript

Summary

  • Both have a form, a result count, and a results block.
  • Both update the results and result count after ajax requests
  • Both use mustache to render parts of the page dynamically
  • Both track ajax updates as new page views
  • Both support the history API
  • Both have a fallback if the history API isn't available
@MatMoore
MatMoore / gist:5ac8232cb6d3089a30c0015af80ff7d9
Last active May 22, 2017 14:13
Publishing api editions with null public updated at
irb(main):015:0> pp Edition.where(public_updated_at: nil).group("DATE(updated_at)", "publishing_app").order('DATE(updated_at)').count; nil
{[Mon, 29 Feb 2016, "short-url-manager"]=>54,
[Mon, 29 Feb 2016, "hmrc-manuals-api"]=>16,
[Mon, 29 Feb 2016, "whitehall"]=>9,
[Mon, 29 Feb 2016, "service-manual-publisher"]=>48,
[Mon, 29 Feb 2016, "policy-publisher"]=>5,
[Mon, 29 Feb 2016, "contacts"]=>4,
[Tue, 08 Mar 2016, "collections-publisher"]=>1,
[Thu, 10 Mar 2016, "collections-publisher"]=>1096,
[Thu, 12 May 2016, "collections-publisher"]=>1097,
/hmrc-internal-manuals/double-taxation-relief/
/hmrc-internal-manuals/fraud-civil-investigation/
/hmrc-internal-manuals/tax-credits-manual/
/hmrc-internal-manuals/compliance-operational-guidance/
/hmrc-internal-manuals/cotax-manual/
/hmrc-internal-manuals/double-taxation-relief/
/hmrc-internal-manuals/labour-provider-operational-guidance/
/hmrc-internal-manuals/vat-small-and-medium-enterprises-assurance/
/hmrc-internal-manuals/compliance-handbook/
/hmrc-internal-manuals/machine-games-duty-manual/
@MatMoore
MatMoore / specialist_publisher.json
Last active May 22, 2017 10:08
Affected specialist publisher
// 20170522110859
// https://www.gov.uk/api/search.json?filter_public_timestamp=from:2017-05-18,to:2017-05-20&filter_publishing_app=specialist-publisher&filter_document_type=edition&fields[]=content_id&count=1000
{
"results": [
{
"content_id": "46fb4dec-d076-473a-8c42-f24d03e04b30",
"index": "mainstream",
"es_score": null,
"_id": "/drug-device-alerts/class-4-medicines-recall-sodium-cromoglicate-2-w-v-13-5-ml-eye-drops",
@MatMoore
MatMoore / gist:76aa1df81254bdca696b0d5ec3c4947f
Created May 19, 2017 15:31
Duplicate CMA Case 2017-05-19 16:31 BST
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 3,
"successful": 3,
"failed": 0
},
"hits": {
"total": 2,