Skip to content

Instantly share code, notes, and snippets.

View keithtom's full-sized avatar

Keith Tom keithtom

View GitHub Profile
@keithtom
keithtom / post_bad.rb
Created February 14, 2013 23:21
A mini program to find published posts from a sql db. post_bad.rb doesn't use sql sanitization and is vulnerable to sql injection attacks, where a user can see unpublished posts.
require 'sqlite3'
require_relative 'post_db' # Setup db table
# Open a database
db = SQLite3::Database.new "test.db"
while true
# Get book name
puts "Find post by name:"
post_name = gets.strip
@keithtom
keithtom / user_bad.rb
Created February 14, 2013 23:25
A mini app where users can 'signup' by adding their name to the database. user_bad.rb doesn't sanitize the sql properly so we can signup as an admin.
require 'sqlite3'
require_relative 'user_db' # Setup user table
# Open a database
db = SQLite3::Database.new "test.db"
while true
# Get user input.
puts "Add user:"
user_name = gets.strip
require_relative "rules"
# An object which represents the checkout process or cash register.
# It scans items, which are added to an internal list of items,
# which are then used to return the #total at any given moment.
# This total tries to use the rules which lead to the cheapest price.
class CheckOut < Struct.new(:rules)
attr_accessor :rules # list of available pricing rules (passed on initialization)
attr_accessor :items # hash of scanned items and quantities
# { "A" => 0, "B" => 1 } means we have scanned one "A" and zero "B"s

Dev Bootcamp Prep Pairing

What is pairing?

Pairing is when two programmers work together on a problem. We do it a lot at DBC.

Since we'll be pairing with you, if you don't know something, like some fact or detail, that's fine. You should really focus on how to think and talk about the challenge (the technical problem), ie. how to explain what you're thinking, follow what we do together and talk about it, and be able to recognize when we've succeeded!

Most of all just try to relax and enjoy working with us through this process.

Exercise: The Restaurant Wait Time

We have been contracted to write a piece of software for a restaurant. They want to easily be able to enter orders that come in, and be told how long the wait time will be for that order. That is, we are going to write a simple program for placing an order at a restaurant and it will print to the screen how long the wait is.

You can order the following items:

  • pizza
  • spaghetti
  • lasagna
  • salad
def leap_year?(year)
if year % 4 == 0
puts "I am divisible by 4!"
true
elsif year % 100 == 0
puts "I am divisible by 100!"
false
elsif year % 100 == 0 && year % 400 == 0
puts "I am divisible by 100 and 400!"
true
def valid_triangle?(a, b, c)
if ((a == 0 or b == 0 or c == 0) or (a == nil or b == nil or c == nil))
return false
end
if a + b > c
puts "case 1"
return true
@keithtom
keithtom / submit_application.rb
Last active October 6, 2017 01:55
An example command for submitting an application.
# A user submits their loan application
class SubmitApplication
# store any state that you'll need to do your action
def initialize(applicant, loan)
@applicant = applicant
@loan = loan
end
end
@keithtom
keithtom / submit_application.rb
Last active October 6, 2017 02:07
An example command for submitting an application. Raw
# A user submits their loan application
class SubmitApplication
def initialize(applicant, loan)
...
end
def execute
update_loan_workflow
charge_applicant_credit_card
check_applicant_fico_score

Keybase proof

I hereby claim:

  • I am keithtom on github.
  • I am keithtom (https://keybase.io/keithtom) on keybase.
  • I have a public key ASCvDQu_mbvktf1WOr11_QRDnSgOqxv1bbEPAhysEHLpVAo

To claim this, I am signing this object: