Skip to content

Instantly share code, notes, and snippets.

View itzsaga's full-sized avatar
🍕

Seth itzsaga

🍕
View GitHub Profile
module Players
class Computer < Player
def move(board)
if board.cells.count{|square| square != " " } == 0
"1"
elsif board.cells.count{|square| square != " " } == 1
board.cells.find_index("X") == 4 ? "1" : "5"
else
possible_moves = ["1", "2", "3", "4", "5", "6", "7", "8", "9"]
valid_moves = []
<div class="social-icon-container">
<a href="https://twitter.com/empireofryan"><img class="social-icon" src="../assets/img/twitter-icon.png"></a>
<a href="https://www.linkedin.com/in/ryan-johnson-321629ab"><img class="social-icon" src="../assets/img/linkedin-icon.png"></a>
<a href="https://github.com/empireofryan"><img class="social-icon" src="../assets/img/github-icon.png"></a>
<a href="https://www.youtube.com/watch?v=C22ufOqDyaE"><img class="social-icon" src="../assets/img/rss-icon.png"></a>
</div>
social = doc.css(".social-icon-container a")
social.each do |link|
class MeetupsAround::CLI
attr_reader :todays_date
def call
@todays_date = "Saturday, March 25"
input_zipcode
input_radius
list_meetups
again?
end
meetups.each.with_index(1) do |meetup, i|
puts "#{i}. #{meetup.time} - #{meetup.group} - #{meetup.event} - #{meetup.attendees}"
end
@itzsaga
itzsaga / initialize_with_hash.rb
Created March 29, 2017 04:17
A way to initialize an object with a hash argument.
def initialize(h)
h.each {|k,v| public_send("#{k}=",v)}
end
Model View Controller
Logic Front-End Middleman
Brains HTML
CSS
Forms
ERB*
Chef Guest Waiter

Let's say we have a controller action:

get '/' do
 erb :index
end

>When the above controller action is triggered and the erb method is called, it looks to see if there is a view titled layout.erb. If that file exists, it loads that content around the desired erb file, in this case index.erb.

Failures:
1) App POST /teams submits the form
Failure/Error: click_button 'submit'
TypeError:
expected Hash (got String) for param `name'
<h1>Create a Team and Heroes!</h1>
<form action="/teams" method="POST">
<p>Team Name: <input type="text" name="team[name]"></p>
<p>Team Motto: <input type="text" name="team[motto]"></p>
<h2>Hero 1</h2>
<p>Hero's Name: <input id="member1_name" type="text" name="team[name][hero][][name]"></p>
<p>Hero's Power: <input id="member1_power" type="text" name="team[name][hero][][power]"></p>
<p>Hero's Biography: <input id="member1_bio" type="text" name="team[name][hero][][bio]"></p>
<h2>Hero 2</h2>
<p>Hero's Name: <input id="member2_name" type="text" name="team[name][hero][][name]"></p>