Skip to content

Instantly share code, notes, and snippets.

View jamiecobbett's full-sized avatar

Jamie Cobbett jamiecobbett

View GitHub Profile
content_ids = Document.where("slug like 'deleted-%'").pluck(:content_id); nil
File.open('/tmp/whitehall-deleted-content-ids.txt', 'w') { |f| f.write content_ids.join("\n") }
@jamiecobbett
jamiecobbett / dependency_checker.rb
Last active November 24, 2015 11:45
Scan govuk app Gemfile.locks for a named gem dependency
require 'open-uri'
apps = %w{
asset-manager
bouncer
business-support-api
business-support-finder
calculators
calendars
collections
We can't make this file beautiful and searchable because it's too large.
/14-19prospectus,https://www.gov.uk/courses-qualifications
/16-19bursary,https://www.gov.uk/1619-bursary-fund
/16to19transport,https://www.gov.uk/subsidised-college-transport-16-19
/2007budget,""
/a-z,""
/about,""
/accessibility,http://www.direct.gov.uk/en/hl1/help/accessibility/index.htm
/accesstowork,https://www.gov.uk/access-to-work
/actonc02,""
/actonco2,""
@jamiecobbett
jamiecobbett / gist:4016699
Created November 5, 2012 11:15
List GOV.UK content slugs by section
require 'json'
require 'open-uri'
require 'cgi'
def subsection_uris
uri = URI.parse("https://contentapi.production.alphagov.co.uk/tags.json?type=section")
json = JSON.parse(uri.open.read)
subsections = json["results"].select do |section_tag|
! section_tag["parent"].nil?
end
@jamiecobbett
jamiecobbett / dub_be_good_to_me.rb
Created March 16, 2012 18:00
Do you feel the need to hear the memorable intro from Beats International's "Dub Be Good To Me", but don't want to use YouTube or a silly MP3?
require 'rubygems'
require 'nokogiri'
require 'open-uri'
doc = Nokogiri::HTML.parse(open("http://www.songmeanings.net/songs/view/101453/"))
doc.css('script').remove
song_text_node = doc.at("#songText2")
lines_by_paragraph = song_text_node.inner_html.gsub(/\n/, "").split(/<br><br>/).map do |paragraph|
paragraph.split(/<br>/)
end
action: "show"
backtrace: undefined
baseUrl: "<CENSORED>"
cgi_data: undefined
component: "campaigns"
data: undefined
error: Object
action: "show"
component: "campaigns"
message: jQuery.Event
@jamiecobbett
jamiecobbett / notifier.js
Created August 2, 2011 11:12
Patched Hoptoad/Airbrake notifier.js to avoid an error when jQuery.Event hits window.onerror
var Hoptoad = {
VERSION : '0.1.0',
NOTICE_XML : '<?xml version="1.0" encoding="UTF-8"?><notice version="2.0"><api-key></api-key><notifier><name>hoptoad_notifier_js</name><version>0.1.0</version><url>http://hoptoadapp.com</url></notifier><error><class>EXCEPTION_CLASS</class><message>EXCEPTION_MESSAGE</message><backtrace>BACKTRACE_LINES</backtrace></error><request><url>REQUEST_URL</url><component>REQUEST_COMPONENT</component><action>REQUEST_ACTION</action></request><server-environment><project-root>PROJECT_ROOT</project-root><environment-name>production</environment-name></server-environment></notice>',
ROOT : window.location.protocol + '//' + window.location.host,
BACKTRACE_MATCHER : /^(.*)\@(.*)\:(\d+)$/,
backtrace_filters : [/notifier\.js/],
notify: function(error) {
var xml = escape(Hoptoad.generateXML(error));
var host = Hoptoad.host || 'hoptoadapp.com';
@jamiecobbett
jamiecobbett / gist:964343
Created May 10, 2011 12:00
Capistrano: prompt to confirm branch if not on master
def current_git_branch
`git symbolic-ref HEAD`.gsub("refs/heads/", "")
end
def prompt_with_default(message, default)
response = Capistrano::CLI.ui.ask "#{message} Default is: [#{default}] : "
response.empty? ? default : response
end
def set_branch
@jamiecobbett
jamiecobbett / ios-update-availability
Created November 22, 2010 15:26
Checks for iOS 4.2
#! /bin/csh
# Adapted from: http://www.tuaw.com/2010/06/21/ios-4-0-firmware-release-expected-momentarily-quick-terminal-ti/
curl -s -L http://phobos.apple.com/version | grep -i Restore | grep -i iPhone | grep -i "\_4\.2\_"
if ($? == 1) then
echo "Nothing yet..."
else
say "FOUR POINT TWO FIRMWARE IS NOW AVAILABLE"
endif
sleep 30
@jamiecobbett
jamiecobbett / Pukka Ruby Daemon
Created April 21, 2010 07:28
Pukka Ruby Daemon
# http://stackoverflow.com/questions/1740308/create-a-daemon-with-double-fork-in-ruby
# Example double-forking Unix daemon initializer.
raise 'Must run as root' if Process.euid != 0
raise 'First fork failed' if (pid = fork) == -1
exit unless pid.nil?
Process.setsid
raise 'Second fork failed' if (pid = fork) == -1