Skip to content

Instantly share code, notes, and snippets.

View peteryates's full-sized avatar
🪶

Peter Yates peteryates

🪶
View GitHub Profile
# Original: https://gist.github.com/otaviomedeiros/1950961
# Updated for new RSpec syntax
RSpec::Matchers.define :alias_from do |alias_method|
match do |subject|
begin
subject.send(alias_method)
rescue NoMethodError
raise "expected alias_method from #{alias_method} to #{@original_method} but #{alias_method} is not defined"
end
@peteryates
peteryates / input.rb
Last active June 29, 2025 11:42
Words that add up to 100 (based on the character index)
alphabet = ('a'..'z').each_with_index.with_object({}) { |(letter, i), hash| hash[letter] = i+1 }
puts File
.open('/usr/share/dict/words')
.each_line
.map(&:chomp)
.reject { |word| word =~ /[^A-Za-z]/ }
.select { |word| word.downcase.chars.inject(0) { |n, char| n + alphabet[char] } == 100 }
@peteryates
peteryates / guide.md
Last active February 12, 2026 03:53
How to stop adverts appearing on your Samsung TV

I'm getting adverts in my TV's UI, help!

Samsung's otherwise excellent 2016 range of UHD TVs received an update that added advertisements to the UI. This has been complained about at great length on Samsung's forums and repeatedly, Samsung have refused to add an option to remove them.

The ads interrupt the clean UI of the TV and are invasive. Here's an example of how they look:

one two

This guide was originally posted on Samsung's TV forums but unfortunately, that site is a super-slow and barely accessible unusable mess.

@peteryates
peteryates / common_steps.rb
Last active February 8, 2019 10:05
Interacting with checkboxes and radio buttons
Given("I am on the {string} page") do |string|
path_for(string).tap do |p|
visit(p)
expect(page.current_path).to eql(p)
end
make_inputs_opaque if opaquify_inputs?
end
@peteryates
peteryates / govuk-ruby-lint.vim
Created September 24, 2019 12:47
A twist on the Rubocop linter customised to work with govuk-ruby-lint
" Author: ynonp - https://github.com/ynonp, Eddie Lebow https://github.com/elebow
" Description: RuboCop, a code style analyzer for Ruby files
call ale#Set('ruby_rubocop_executable', 'govuk-lint-ruby')
call ale#Set('ruby_rubocop_options', '')
function! ale_linters#ruby#rubocop#GetCommand(buffer) abort
let l:executable = ale#Var(a:buffer, 'ruby_rubocop_executable')
return ale#ruby#EscapeExecutable(l:executable, 'govuk-lint-ruby')
@peteryates
peteryates / _form.html.erb
Last active November 7, 2019 15:35
Form with acceptance validation
<%= form_with(model: account, local: true) do |form| %>
<%= form.govuk_error_summary %>
<%= form.govuk_email_field(:email) %>
<%= form.govuk_check_boxes_fieldset :terms_and_conditions,
legend: { text: 'Please accept our terms and conditions' } do %>
<%= form.hidden_field :terms_and_conditions, value: false %>
<%= form.govuk_check_box :terms_and_conditions, true, multiple: false, link_errors: true %>

Keybase proof

I hereby claim:

  • I am peteryates on github.
  • I am graphia (https://keybase.io/graphia) on keybase.
  • I have a public key ASBGOYvkY6lza046FbiAHWGsWDt_KhXRM0UPwvqLsEVUCQo

To claim this, I am signing this object:

@peteryates
peteryates / 0_wtf.md
Last active June 4, 2024 13:45
Calling Nunjucks from Ruby

Ever wanted to render nunjucks macros from Ruby? Neither have I, until half an hour ago.

Here's a quick approach using the excellent Schmooze from Shopify.

Screenshot from 2020-08-01 16-28-12

Try it yourself

Save nunjucks.rb in a new directory then:

@peteryates
peteryates / userContent.css
Created August 21, 2020 11:11
Make the docs wider
@-moz-document domain(design-system.service.gov.uk) {
.app-width-container {
max-width: 95% !important;
}
pre > code {
font-size: 12px !important;
}
}
@peteryates
peteryates / suggestion.patch
Created November 26, 2021 16:58
suggested simplification
diff --git a/lib/govuk_design_system_formbuilder/elements/date.rb b/lib/govuk_design_system_formbuilder/elements/date.rb
index 84430d1..b11bc4e 100644
--- a/lib/govuk_design_system_formbuilder/elements/date.rb
+++ b/lib/govuk_design_system_formbuilder/elements/date.rb
@@ -56,33 +56,21 @@ module GOVUKDesignSystemFormBuilder
def day
return if omit_day?
- if maxlength_enabled?
- date_part(:day, width: 2, link_errors: true, maxlength: 2)