Skip to content

Instantly share code, notes, and snippets.

@MaxDavila
Last active August 29, 2015 14:05
Show Gist options
  • Save MaxDavila/130304903201f871593d to your computer and use it in GitHub Desktop.
Save MaxDavila/130304903201f871593d to your computer and use it in GitHub Desktop.
Interview questions ruby/rails
# Open ended
# - What's your style of working. Pair programming vs solo
# - What's your favortite pattern. Do you use any?
# - If you accidentally pushed your branch to origin master, how would you restore
# to a clean master?
# - What have you been working on Sinatra and Node? Coffescript? APIs? how was it
# architectured
# Loading only one columsn and handling sum back in SQL
# rails/activerecord.
# difficulty: 3
class Customer < ActiveRecord::Base
has_many :loans
end
class Loan < ActiveRecord::Base
belongs_to :campaign
end
# Tentative answer:
class Customer < ActiveRecord::Base
def funds_raised
loans.sum(:amount)
end
end
# Middleware question:
# How would you fix this to return a more descriptive error
# rails/sinatra.
# difficulty: 7
curl -H "Accept: application/json" \
-H "Content-type: application/json" \
'http://localhost:3000/posts' \
-d '{ i am broken'
{"status":"400","error":"Bad Request"}%
# Enumerables questions:
# ruby
# difficulty: 5
class Signer < Struct.new(:key_id, :uid)
def signed_by?(receiver)
!rand(2).zero?
end
end
signers = [ #<Struct Signer>, #<Struct Signer>, #<Struct Signer>]
# build an array of all uids => inject < flatmap
# build a hash from an array of signers
# return a boolean from signers to determine if all have been signed by signer
# OOD/ Refactoring question:
# Build a parser class that can handle different types :xml, :html, :css, :json, etc.
# Ruby. Difficulty: 7
class Parser
def parse(type)
switch type
....
end
end
---
class XmlParser
def parse
puts "Xml parsing"
end
end
class HtmlParser
def parse
puts "html parsing"
end
end
class GenericParser
TYPES = { :xml => XmlParser, :html => HtmlParser }
def initialize(type)
@parser = initialize_parser(type)
end
def parse
@parser.parse
end
def initialize_parser(type)
if TYPES[type].present?
TYPES[type].new
else
raise TypeError, "No such a parser exists"
end
end
end
parsed = GenericParser.new(:xml)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment