Skip to content

Instantly share code, notes, and snippets.

View vgarro's full-sized avatar

Victor Garro vgarro

View GitHub Profile
# Given a string with key value pairs like this : "key=ABCD, age=68, key=AIAS, age=66",
# figure out which of the pairs has age grwater than 50
# Removes the key=anything first, then commas, then whitespaces leaving age=
# Then split age=[Number] in order to get the list of numbers
# count the ones greater than 50
def count_ages_greather_than(str, age_limit = 50)
@vgarro
vgarro / nfx.rb
Created June 2, 2022 00:20
NFX Coding challenge
# Use coderpad (https://coderpad.io/demo).
# This prompt can be done in any order
# Write a script that can be run in the terminal that can:
# -- Take in and validate data about an individual startup and store in memory in a list of startups.
# - Company name (Can’t be empty)
# - Founder first name (Can’t be empty)
# - Founder last name (Can’t be empty)
# - Fundraising stage (Allowed values: Pre-seed, Seed, Series A, Series B)
# - Fundraising target minimum (Can’t be a negative number or greater than Fundraising target maximum)
@vgarro
vgarro / dry.rb
Created June 2, 2022 00:18
DRY coding challenge
class MyReporting
def report(formatter:)
formatter.format(body)
end
end
class MyHtmlFormatter
def format(body)
remove_whitespaces(body).to_html
@vgarro
vgarro / interface_segregation.rb
Created June 2, 2022 00:17
Interface segregation coding challenge
class User
def generate_unique_id
@unique_id = Digest::MD5.hexdigest("#{name}-#{last_name}")
end
def confirm_email
EmailProcessor.send_email(@email, @unique_id)
end
end
@vgarro
vgarro / lizcov.rb
Created June 2, 2022 00:17
Lizcov Substitution Coding challenge
# Lizcov
class Payable
def pay(amount:, credit_card_details:)
payment_processor.charge!(amount: amount, credit_card_details: credit_card_details)
end
end
class Bill < Payable
def charge_credit_card(amount:, credit_card_details:)
pay(amount:, credit_card_details:)
@vgarro
vgarro / single_responsibility.rb
Created June 2, 2022 00:15
Single Responsibility coding challenge
class AritmeticCalculation
attr_reader :math_operation, :numbers
def initialize(math_operation:, numbers:)
math_operation = math_operation
numbers = numbers || []
end
def run_math
case math_operation
when "sum"
@vgarro
vgarro / search_coding_interview.rb
Created June 2, 2022 00:12
Coding Interview challenge.
# Create the algorithm to find words based on the following criteria:
# search_string = "word"
# 1. exact match
# 2. one of the words is exact match
# 3. starts with
# 4. rest, alphanumerically
ordered_results = ["Word", "Microsoft Word", "Wordpress", "1Password", "Google AdWords"]
results = ordered_results.shuffle
@vgarro
vgarro / keybase.md
Last active April 7, 2020 17:39
Keybase proof

Keybase proof

I hereby claim:

  • I am vgarro on github.
  • I am vgarroj (https://keybase.io/vgarroj) on keybase.
  • I have a public key ASDn3nXEl2Fg68fikG3oRt-fvG2Un1Ifh_-ci_r0w_RzYgo

To claim this, I am signing this object:

# https://dev.to/r0f1/write-a-simple-but-impactful-script-7ba
# Write a script that produces all possible 4-digit numbers (0000...9999),
# then put them into a random order and
# save the output into a text file
class ExcerciseOrquestrator
attr_reader :output_file_name
def initialize(output_file_name)
@vgarro
vgarro / env_variable_test.rb
Created April 6, 2017 22:30
Accessing ENV variables from ENV is slower than a constant in Ruby
class TestClass
def test
var = ENV['TEST_VAR']
var == 1
end
end
require 'benchmark'
Benchmark.bm do |x|
x.report { 1000000.times { TestClass.new.test } }