This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Around do |scenario, block| | |
Capybara.using_session(scenario.object_id) do | |
block.call | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# If you're using Rails, add this file to app/middleware/microsoft_hyperlink_library_middleware.rb | |
# And add the following to your config/application.rb (note the string class name): | |
# | |
# config.middleware.use "MicrosoftHyperlinkLibraryMiddleware" | |
# | |
# This will fix the awful bug described in https://support.microsoft.com/en-gb/kb/899927 where | |
# links from PowerPoint or Word that require an authenticated session continually go to your | |
# log in page even when a user is authenticated. | |
# | |
# The workaround is to rewrite any server-side HTTP redirects to client-side redirects |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<meta charset="utf-8"> | |
<input id="input" type="text"> <a href="#" id="scifi">Sci-Fi it!</a> | |
<p id="output"></p> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script> | |
<script> | |
function sampleWithFrequency(coll) { | |
var choice = Math.random(), | |
length = coll.length; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'will_paginate/active_record' | |
require 'fast_paginator' | |
module FastPagination | |
def paginate(per_page: 96, page: 1, total_entries: nil) | |
WillPaginate::Collection.create(page, per_page, total_entries) do |pager| | |
pivot = (pager.total_pages / 2.0).ceil | |
paginator = FastPaginator.new(self, pager) | |
if pager.current_page <= pivot |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Colour | |
attr_reader :red, :green, :blue | |
def initialize(red, green, blue) | |
@red = Float(red) | |
@green = Float(green) | |
@blue = Float(blue) | |
end | |
def to_hsl |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* See the bottom of this file for the specs which show how this definition of | |
* 10 and 13 digit ISBNs allows us to: | |
* | |
* - Convert ISBN-10 to ISBN-13 | |
* - Convert ISBN-13 to ISBN-10 | |
* - Automatically fill in missing digits from ISBN-13 | |
* - Automatically fill in missing digits from ISBN-10 | |
* | |
* Note that as Sentient does not have characters, an 'X' in an ISBN-10 is |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# isbns('978-0-80-506909-9 9780671879198 0-415-82102-9 3319217283') | |
# => ["9780805069099", "9780671879198", "9789780805067", "9789780671877", "9780415821025", "9783319217284"] | |
def isbns(text) | |
thirteen_digit_isbns(text) + ten_digit_isbns(text) | |
end | |
def thirteen_digit_isbns(text) | |
text.tr('-', '').scan(/\b97[89]\d{10}\b/) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Proc | |
def compose(g) | |
proc { |*args, &blk| call(g.call(*args, &blk)) } | |
end | |
end | |
symbolize = ->(x) { x.to_sym } | |
upcase = ->(x) { x.upcase } | |
symbolize_and_upcase = symbolize.compose(upcase) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Faraday.new(site, request: { timeout: 30 }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Maybe | |
include Enumerable | |
def initialize(value) | |
@value = value | |
end | |
def each | |
yield value unless value.nil? | |
end |