View parse_urls_from_sitemap.rb
require 'nokogiri'
response = get(sitemap_path)
doc = Nokogiri::XML(response.body)
namespace = 'http://www.sitemaps.org/schemas/sitemap/0.9'
locs = doc.xpath('//urlset:url//urlset:loc', 'urlset' => namespace)
urls = locs.map(&:text).map { |u| URI(u).path }.uniq
View ruby-dir-glob-returns-empty-array-when-too-many-open-files.txt
$ mkdir /tmp/ruby-dir-glob-returns-empty-array-when-too-many-open-files
$ cd /tmp/ruby-dir-glob-returns-empty-array-when-too-many-open-files
$ touch foo
$ ulimit -n 16
$ ruby -e "1.upto(16).map { |i| p [i, Dir.glob('*')]; File.new('foo') }"
[1, ["foo"]]
[2, ["foo"]]
[3, ["foo"]]
[4, ["foo"]]
[5, ["foo"]]
View remove_specialist_document_editions_with_non_manual_document_type_test.txt
vagrant@development:/var/govuk/manuals-publisher$ bin/document_types_report
## SpecialistDocumentEditions
* With non-manual document type: 23018
* With manual document type: 3688
## ManualRecord::Editions
* With mixed (manual vs non-manual) document types: []
* With only non-manual document types: []
View restore-govuk-content-development.sh
./replicate-data-local.sh -s -d backups/2017-02-23 -p -q -e -t -i "event_store transition backdrop support_contacts imminence content_store draft_content_store draft_router router authenticating_proxy admin test specialist_publisher_rebuild specialist_publisher_rebuild_standalone short_url_manager share_sale_publisher reviewomatic gov_delivery govuk_assets govuk_needs publisher panopticon maslow licence_finder govuk_delivery manuals_publisher"
View document_types_report_test.rb
def create_sd_edition_for(mr_edition, slug:, manual:)
id = BSON::ObjectId.new.to_s
type = manual ? 'manual' : 'aaib_report'
sd_edition = SpecialistDocumentEdition.create(document_id: id, slug: slug, document_type: type)
mr_edition.document_ids ||= []
mr_edition.document_ids << id
mr_edition.save!
sd_edition
end
View exception.txt
cannot load such file -- active_model/translation (LoadError)
$BUNDLE_DIR/gems/gems/activemodel-3.2.22.3/lib/active_model/validations.rb:49:in `block in <module:Validations>'
$BUNDLE_DIR/gems/gems/activesupport-3.2.22.3/lib/active_support/concern.rb:121:in `class_eval'
$BUNDLE_DIR/gems/gems/activesupport-3.2.22.3/lib/active_support/concern.rb:121:in `append_features'
$BUNDLE_DIR/gems/gems/activesupport-3.2.22.3/lib/active_support/concern.rb:113:in `include'
$BUNDLE_DIR/gems/gems/activesupport-3.2.22.3/lib/active_support/concern.rb:113:in `block in append_features'
$BUNDLE_DIR/gems/gems/activesupport-3.2.22.3/lib/active_support/concern.rb:113:in `each'
$BUNDLE_DIR/gems/gems/activesupport-3.2.22.3/lib/active_support/concern.rb:113:in `append_features'
$BUNDLE_DIR/gems/gems/activesupport-3.2.22.3/lib/active_support/concern.rb:113:in `include'
$BUNDLE_DIR/gems/gems/activesupport-3.2.22.3/lib/active_support/concern.rb:113:in `block in append_features'
View parse-sitemap.sh
$ brew install xmlstarlet
$ wget --output-document=- --quiet http://gofreerange.dev/sitemap.xml | xml sel --template --value-of "//*[local-name()='loc']/text()"
View foo.rb
module Foo
private
def foo
"foo"
end
end
class Bar
extend Foo
View tidy.conf
indent: auto
indent-attributes: no
vertical-space: yes
View index.html
Drag the following link to your browser bookmark toolbar:
<a href="javascript:(function()%7BArray.from(document.querySelector('body').querySelectorAll('.blob-code')).forEach(function(el)%20%7Bvar%20matches%20%3D%20el.textContent.match(%2Frender%20partial%5C%3A%20%5B'%22%5D(%5B%5E'%5D%2B)%5B'%22%5D%2F)%3Bif%20(matches)%20%7Bvar%20originalPath%20%3D%20matches%5B1%5D%3Bvar%20pathElements%20%3D%20originalPath.split('%2F')%3Bvar%20lastElement%20%3D%20'_'%20%2B%20pathElements.pop()%3Bif%20(pathElements%5B0%5D%20%3D%3D%20'shared')%20%7BpathElements%5B0%5D%20%3D%20'..%2F..%2Fshared'%3B%7D%3BpathElements.push(lastElement)%3Bvar%20path%20%3D%20pathElements.join('%2F')%3Bconsole.log(path)%3Bvar%20url%20%3D%20new%20URL(path%2C%20document.location).toString()%3Bvar%20anchor%20%3D%20document.createElement('a')%3Banchor.setAttribute('href'%2C%20url)%3Banchor.setAttribute('title'%2C%20lastElement)%3Banchor.setAttribute('style'%2C%20'color%3A%20hotpink')%3Banchor.textContent%20%3D%20originalPath%3Bel.querySelectorAll('*').fo