Skip to content

Instantly share code, notes, and snippets.

View SergioETrillo's full-sized avatar

Sergio Enrech Trillo SergioETrillo

View GitHub Profile
@SergioETrillo
SergioETrillo / setaudience.cs
Created June 15, 2018 14:51
Set audience with OpenId connect Client
// options already generated above
_oidcClient = new OidcClient(options);
var audienceApi = "http://localhost:7071/api/SayMyName/";
var audience = new Dictionary<string, string>
{
{ "audience", audienceApi }
};
@SergioETrillo
SergioETrillo / day7.rb
Last active July 29, 2016 13:08
Advent of Code, Day 7
class LogicCalculator
attr_accessor :lines
def initialize
data = File.read("lib/input.txt")
@lines = data.split("\n")
end
def calculate_result
@SergioETrillo
SergioETrillo / day7_feature_spec.rb
Last active July 29, 2016 13:07
Advent of Code, Day 7, integration test
require 'logic_calculator'
describe "Integration Test" do
subject(:logic_calculator) { LogicCalculator.new }
before(:each) do
@file_challenge1 = File.read("lib/input.txt")
@file_challenge2 = File.read("lib/input2.txt")
@RESULT1 = 16076
@RESULT2 = 2797
end
@SergioETrillo
SergioETrillo / day7_spec.rb
Last active July 29, 2016 13:10
Advent of Code, Day 7, unit test
require 'logic_calculator'
describe LogicCalculator do
subject(:logic_calculator) { described_class.new }
before(:each) do
@f = File.read("lib/input.txt")
@lines = @f.split("\n")
end
context "File management" do
@SergioETrillo
SergioETrillo / day6-2.rb
Created July 25, 2016 11:01
Advent of Code, Day 6, part 2
def process_command2(command,i,j)
case command
when "toggle"
@grid[i][j] += 2
when "on"
@grid[i][j] += 1
when "off"
@grid[i][j] >=1 ? @grid[i][j]-= 1 : 0
else
raise "command error"
@SergioETrillo
SergioETrillo / day6.rb
Last active July 25, 2016 10:59
Advent of Code, Day 6
class Day6
attr_reader = :lighted
def initialize
@grid = Array.new(1000) {Array.new(1000,0)}
@lighted = 0
end
def get_raw_data
@SergioETrillo
SergioETrillo / irb-text.rb
Created July 22, 2016 16:18
checkout irb test
sergio@linux ~/Ronin/Tech-tests/babylon (wip *)
$ irb
2.3.1 :001 > item1 = Item.new(code: :"001", name: "Lavender heart", price: 9.25)
=> #<Item:0x00000001c81468 @code=:"001", @name="Lavender heart", @price=9.25>
2.3.1 :002 > item2 = Item.new(code: :"002", name: "Personalised cufflinks", price: 45)
=> #<Item:0x00000001c64548 @code=:"002", @name="Personalised cufflinks", @price=45>
2.3.1 :003 > item3 = Item.new(code: :"003", name: "Kids T-shirt", price: 19.95)
=> #<Item:0x00000001c16ed8 @code=:"003", @name="Kids T-shirt", @price=19.95>
2.3.1 :004 > promo1 = Promotion.new(id: :promo1, type: :"multiple_buy", params: { code: :"001", quantity: 2, promo_price: 8.50 })
=> #<Promotion:0x00000001a802e0 @id=:promo1, @type=:multiple_buy, @params={:code=>:"001", :quantity=>2, :promo_price=>8.5}>
@SergioETrillo
SergioETrillo / day5.rb
Created July 14, 2016 17:24
Advent of Code, Day 5
class CheckNiceWords
FILE = "day5/day5.txt"
THREE_VOWELS = /[aeiou].*?[aeiou].*?[aeiou]/
REPEATED_CHARS = /(.)\1+/
NOT_AB = /^((?!ab).)*$/
NOT_CD = /^((?!cd).)*$/
NOT_PQ = /^((?!pq).)*$/
NOT_XY = /^((?!xy).)*$/
@SergioETrillo
SergioETrillo / day4-2.rb
Created July 13, 2016 18:03
Advent of Code, Day 4 part 2
require 'digest/md5'
class Miner
ZEROS = 6
def mine(secret)
result = ""
i = 0
loop do
@SergioETrillo
SergioETrillo / day4-1.rb
Created July 13, 2016 17:57
Advent of Code, Day 4, part 1
require 'digest/md5'
class Miner
def mine(secret)
result = ""
i = 0
loop do
i+=1
result = Digest::MD5.hexdigest(secret + i.to_s)