Skip to content

Instantly share code, notes, and snippets.

View todlazarov's full-sized avatar

Tod Lazarov todlazarov

  • Toronto, ON, Canada
View GitHub Profile
todl@todl-System-Product-Name:~/Desktop/book_viewer_r20160201/book_viewer$ bundle install
Fetching gem metadata from https://rubygems.org/.........
Fetching version metadata from https://rubygems.org/..
Resolving dependencies...
Using addressable 2.4.0
Using backports 3.6.8
Using erubis 2.7.0
Using excon 0.48.0
Using multi_json 1.11.2
Using net-ssh 2.9.2
def times(number)
counter = 0
while counter < number do
yield(counter)
counter += 1
end
number
end
# This class represents a todo item and its associated
# data: name and description. There's also a "done"
# flag to show whether this todo item is done.
class Todo
DONE_MARKER = 'X'
UNDONE_MARKER = ' '
attr_accessor :title, :description, :done
# Tic Tac Toe is a 2 player board game played on a 3x3 grid. Players take turns
# making a square. The first player to mark 3 squares in a row wins.
# Nouns: board, player, square, grid
# Verbs: play, mark
# Board
# Square
# Player
# - mark
# Tic Tac Toe is a 2 player board game played on a 3x3 grid. Players take turns
# making a square. The first player to mark 3 squares in a row wins.
# Nouns: board, player, square, grid
# Verbs: play, mark
# Board
# Square
# Player
# - mark
# 1. We are working with a database and we need to create a comma separated list of facebook friend's IDs
users.select {|u| u.is_friend?}
.map {|u| u.facebook_id}
.compact
.join(',')
# Pseudocode
# We combine our methods by chaining them together for clarity and readibility.
# First we create a method that checks if the given user is our friend and call it "is_friend?".
# We use the select method to itterate over the users database and return an array containing
require 'pry'
# Constants
INITIAL_MARKER = " "
PLAYER_MARKER = "X"
COMPUTER_MARKER = "O"
WINNING_LINES = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] + # rows
[[1, 4, 7], [2, 5, 8], [3, 6, 9]] + # columns
[[1, 5, 9], [3, 5, 7]] # diagonals
require 'pry'
# Constants
INITIAL_MARKER = " "
PLAYER_MARKER = "X"
COMPUTER_MARKER = "O"
WINNING_LINES = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] + # rows
[[1, 4, 7], [2, 5, 8], [3, 6, 9]] + # columns
[[1, 5, 9], [3, 5, 7]] # diagonals
require 'pry'
INITIAL_MARKER = " "
PLAYER_MARKER = "X"
COMPUTER_MARKER = "O"
WINNING_LINES = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] + # rows
[[1, 4, 7], [2, 5, 8], [3, 6, 9]] + # columns
[[1, 5, 9], [3, 5, 7]] # diagonals
# Variables
# Given the munsters hash below
munsters = {
"Herman" => { "age" => 32, "gender" => "male" },
"Lily" => { "age" => 30, "gender" => "female" },
"Grandpa" => { "age" => 402, "gender" => "male" },
"Eddie" => { "age" => 10, "gender" => "male" },
"Marilyn" => { "age" => 23, "gender" => "female"}
}