Skip to content

Instantly share code, notes, and snippets.

# Code to create a venue, without using a builder...
class Venue
attr_accessor :staff
attr_accessor :menu
attr_accessor :seating
def initialize(bar_size = :small, menu = Menu.new, staff =[])
@staff = staff
@menu = menu
@bar = bar
@LNA
LNA / refactoring_ar.rb
Last active January 1, 2016 06:59
Refactoring code smells. Refactoring an Active Record Relationship Model
module AR
class Guest < ActiveRecord::Base
has_many :orders, class_name: "Orders"
has_many :drinks, through: :orders, class_name: "Orders"
def drinks
drinks_array = []
AR::Orders.all.each do |relationship|
if relationship.guest_id == self.id
drinks_array << relationship.drink
end
@LNA
LNA / association_change.rb
Last active January 2, 2016 03:48
Association Change.
#First Pass:
module AR
class Guest < ActiveRecord::Base
has_and_belongs_to_many :drinks
end
end
module AR
class Drink < ActiveRecord::Base
@LNA
LNA / euler_4.rb
Last active January 4, 2016 14:49
Project Euler Problem 4: Find the largest palindrome made from the product of two 3-digit numbers.
def palindrome
palindromes = []
(999).downto(100).each do |number|
(number ..999).each do |range_of_numbers|
product = number * range_of_numbers
if product.to_s == product.to_s.reverse
palindromes << product
end
end
@LNA
LNA / test.rb
Created January 26, 2014 18:53
Multiplying A Range of Numbers Via Nested Iterations
def test
test_numbers = []
(5).downto(1).each do |number|
(number ..5).each do |range_of_numbers|
product = number * range_of_numbers
test_numbers << product
end
end
test_numbers
@LNA
LNA / java_basics.java
Last active August 29, 2015 13:56
Java Basics
// What is an instance variable?
// An instance variable is the variable declared inside of the class but outside of the method.
class Shoe {
// these are all instance variables:
public String shoeBrand;
public String[] shoeSeason;
public int shoeSize;
// getters and setters follow
@LNA
LNA / old_ttt_board.rb
Last active August 29, 2015 13:56
Bad TTT Board
<table class="board">
<tr>
<td>
<div id="0" class="square" >
<input type="submit" name="square" value="0">
</div>
</td>
<td>
<div id="1" class="square" >
<input type="submit" name="square" value="1">
@LNA
LNA / better_ttt_board.rb
Created February 13, 2014 20:36
Better TTT Board
<ul class="board clearfix">
<% count = 0 %>
<% 9.times do %>
<li id="<%= count %>" class="square">
<input type="submit" name="square" value="<%= count %>">
</li>
<% count += 1 %>
<% end %>
</ul>
@LNA
LNA / 0_reuse_code.js
Created February 14, 2014 21:51
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@LNA
LNA / clues.rb
Last active August 29, 2015 13:56
Clues In Test Driving Solutions
it “returns first n numbers” do
# I know there are a few ways to approach this. I could chose a while loop and use a counter to track how many indexes I have counted through. However, I would go for a range. It gets the job done with less code. Less code is good.
end
it “returns a portion of a given group in the form of an array if some condition is met” do
# use find_all.
end
it “returns two arrays: one for a false condition” and it “returns two arrays: one for a true condition” do
# use partition.