This file contains 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_relative "domain.rb" | |
scanner = Scanner.new | |
scanner.batch_load "input.txt" | |
def get_valid_passwords_with_attributes_checks scanner, check_attributes=false | |
valid_passports = scanner.passports.inject([]) do |valid_passports, passport| | |
scanner.load(passport) | |
if scanner.is_current_passport_valid? check_attributes: check_attributes | |
valid_passports << passport |
This file contains 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 Passport | |
def initialize passport_string | |
@raw_passport = passport_string | |
@passport_hash = convert_passport_string_to_hash(passport_string) | |
end | |
def as_h | |
@passport_hash | |
end |
This file contains 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
Given('a passport where all eight fields are present') do | |
@passport = Passport.new("ecl:gry pid:860033327 eyr:2020 hcl:#fffffd byr:1937 iyr:2017 cid:147 hgt:183cm") | |
end | |
Given('a passport where more than one fields are missing') do | |
@passport = Passport.new("hcl:#cfa07d eyr:2025 pid:166559648 iyr:2011 ecl:brn hgt:59in") | |
end | |
Given('a valid North Pole credential') do | |
@passport = Passport.new("hcl:#ae17e1 iyr:2013 eyr:2024 ecl:brn pid:760753108 byr:1931 hgt:179cm") |
This file contains 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
Feature: Passport should have constraints on their attributes to be valid | |
Scenario Outline: Make sure attributes are valid | |
Given a passport with "<attribute>" set to "<value>" | |
When the passport is checked by the scanner | |
Then it considers all attributes as "<validity>" | |
Examples: | |
| attribute | value | validity | | |
| byr | 2002 | valid | |
This file contains 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
Feature: Load batch of passports | |
Passports are scanned in batch by the scanner. The input is a large text file | |
with several passports encoded seperated by an empty line. | |
Scenario: It should correctly identify each test passports, regardless of their type | |
Given a batch encoding of 4 test passports of different types | |
When the scanner loads the batch file | |
Then it should have extracted exactly 4 passports | |
Scenario: The scanner should correctly identify the example passports |
This file contains 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
Feature: Scan passports with proper ruleset | |
We want to make the passport detection faster | |
to avoid long queues at the airport security. | |
A valid passport should have eight fields present | |
(byr, iyr, eyr, hgt, hcl, ecl, pid, cid) to be valid. | |
However, due to the time constraints around Christmas, it | |
would be preferable to consider passport missing the cid field | |
as valid. Such passports are North Pole credentials. | |
Scenario: When all eight fields are present, the passport is valid |
This file contains 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
// Insert this script tag in your html, or require our js | |
// directly in your framework of choice | |
<script src="PATH_TO_DEPENDENCIES/connect-launcher.js"></script> | |
// Add a link somewhere in your app with a data-connect attribute | |
// you can style it the way you want | |
<a href="#" data-connect>Link account</a> | |
// Put this javascript somewhere in your app. The onSuccess | |
// callback needs to be provided, it's what we are calling to give |
This file contains 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
begin | |
# Your code | |
rescue Exception => e | |
# Do something or check what's in e | |
# Exception can be a specific class to make sure you don't catch all of them, only the one you need | |
end |
This file contains 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
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.3//EN" "http://www.puppycrawl.com/dtds/configuration_1_3.dtd"> | |
<module name="Checker"> | |
<module name="TreeWalker"> | |
<!-- Checks for uncommented main() methods (debugging leftovers). --> | |
<!-- See http://checkstyle.sourceforge.net/config_misc.html#UncommentedMain --> | |
<module name="UncommentedMain" /> | |
<!-- Checks that long constants are defined with an upper ell. --> | |
<!-- See http://checkstyle.sourceforge.net/config_misc.html#UpperEll --> |
This file contains 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
def initialize(environment, arguments) | |
@device = ENV['DEVICE'] || "iphone" | |
@sdk = ENV['SDK_VERSION'] || "5.1" | |
@target = ENV["TARGET"] || "project-cal" | |
@arguments = arguments | |
end | |
def build | |
puts "Launch XCode build!".green | |
build_output = `xcodebuild -workspace project.xcworkspace -scheme #{@target} -sdk #{@device}simulator#{@sdk} -configuration clean build 2>&1` |
NewerOlder