Skip to content

Instantly share code, notes, and snippets.

View jsugarman's full-sized avatar

Joel Sugarman jsugarman

  • Digital Services
  • London
View GitHub Profile
require 'rspec/expectations'
module DelayedJobHelper
RSpec::Matchers.define :delay_method do |expected|
def supports_block_expectations?
true
end
match do |proc|
# A simple custom validator that validates the size attribute of
# the records specified file attribute.
#
# examples:
# - validates :image, file_size: { maximum: 3.megabytes }
# - validates :file, file_size: { range: 1.kilobyte..3.megabytes, message: 'not in 1KB to 3MB range' }
#
class FileSizeValidator < ActiveModel::EachValidator
attr_reader :size
require 'netaddr'
class IpAddressMatcher
def initialize(terms)
@cidrs = cidrs(terms)
end
def ===(other)
@cidrs.any? { |cidr| cidr.matches?(other) }
end
/* for versions below 10 */
<!--[if IE]>
<link rel="stylesheet" type="text/css" href="all-ie-only.css" />
<![endif]-->
@media all and (-ms-high-contrast: none), (-ms-high-contrast: active) {
/* IE10+ CSS styles go here */
}
module Capybara
module Node
module Actions
alias_method :old_check, :check
alias_method :old_uncheck, :uncheck
def check(locator, options = {})
Capybara.current_session.evaluate_script js_element_check(locator, true)
end
module Capybara
module Node
module Actions
alias_method :old_check, :check
alias_method :old_uncheck, :uncheck
def check locator
Capybara.current_session.evaluate_script js_element_check(locator, true)
end
@jsugarman
jsugarman / user_agent_helper.rb
Created April 21, 2017 19:57
Blacklist user agents controller concern
module UserAgentHelper
extend ActiveSupport::Concern
Browser = Struct.new(:browser, :version)
SUPPORTED_BROWSER_BLACKLIST = [
Browser.new(UserAgent::Browsers::InternetExplorer.new.browser, UserAgent::Version.new('7.0'))
].freeze
included do
@jsugarman
jsugarman / govuk_notify_queries.rb
Created October 3, 2017 15:29
Govuk notify API query to retrieve mail sent and failed
require 'notifications/client'
def client
@client ||= Notifications::Client.new(ENV['SETTINGS__GOVUK_NOTIFY__API_KEY'])
end
def notifications args
client.get_notifications(args)
end
@jsugarman
jsugarman / .pryrc
Created December 30, 2017 22:39
Pry byebug config
if defined?(PryByebug)
Pry.config.color = true
Pry.config.prompt_name = 'Pry:' + File.basename(Dir.pwd)
Pry.commands.alias_command 'c', 'continue'
Pry.commands.alias_command 's', 'step'
Pry.commands.alias_command 'n', 'next'
Pry.commands.alias_command 'f', 'finish'
end
@jsugarman
jsugarman / sublime-key-mappings
Created December 30, 2017 22:53
Sublime key bindings (user)
[
{ "keys": ["super+shift+["], "command": "prev_view" },
{ "keys": ["super+shift+]"], "command": "next_view" },
{ "keys": ["super+alt+left"], "command": "prev_view" },
{ "keys": ["super+alt+right"], "command": "next_view" },
{ "keys": ["ctrl+y"], "command": "show_overlay", "args": {"overlay": "command_palette", "text": "Snippet: "}},
{ "keys": ["super+i"], "command": "copy_path" }
]