Skip to content

Instantly share code, notes, and snippets.

View jtallant's full-sized avatar
:octocat:

Justin Tallant jtallant

:octocat:
View GitHub Profile
@jtallant
jtallant / footer-widget-height.js
Created February 23, 2012 06:55
Set height of Genesis Footer Widgets to equal height of tallest widget (Javascript)
@jtallant
jtallant / amazon.rb
Last active October 3, 2015 02:28
Code Academy Long Challenge 1: Shopping Cart
# Long challenge: Based on the following data,
# write code that prints out the customer's total, including estimated
# sales tax, based on the shipping address they entered.
# Your code should work even if the values of the data change.
# Your output should look like this: "Your total with tax is $4455.54."
shopping_cart = [
{:name => "iPad 2", :price => 499, :quantity => 2},
@jtallant
jtallant / tallant-awc.rb
Created April 24, 2012 08:49
Amazon Cart With Classes
class Cart
def initialize
@the_cart = []
end
def add(item, quantity)
@the_cart << { :item => item, :quantity => quantity }
end
def total
@jtallant
jtallant / pulling-and-pushing-to-git.md
Created June 14, 2012 20:39
Basic Unix + Pulling and Pushing to Git

UNIX Commands

pwd present working directory

ls list current directory contents

ls -la list current directory contents in long format and show hidden files

man <some unix command> Bring up the manual pages for a command. Type q to exit

@jtallant
jtallant / euler2.rb
Created June 25, 2012 13:51
Project Euler Problem 2
# Project Euler Problem 2
# Each new term in the Fibonacci sequence is generated by adding the previous two terms.
# By starting with 1 and 2, the first 10 terms will be:
# 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
# By considering the terms in the Fibonacci sequence whose values do not exceed four million,
# find the sum of the even-valued terms.
@jtallant
jtallant / euler1.rb
Created July 1, 2012 17:24
Project Euler Problem 1 Ruby
# If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
# Find the sum of all the multiples of 3 or 5 below 1000.
sum, i = 0, 0
while i < 1000
sum += i if i % 3 == 0 || i % 5 == 0
i += 1
end
puts sum # => 233168
@jtallant
jtallant / euler3.rb
Created July 2, 2012 01:00
Project Euler Problem 3 Ruby
# if n is 1, end the method and return empty array
# set var factor = first number in range 2..n
# that has a remainder of 0 when divided by x
# x being the current iteration of 2..n
# put factor var into an array and then call the
# method we are currently in again passing the
# value of n divided by the current value of factor
def prime_factors(n)
return [] if n == 1
@jtallant
jtallant / is_prime.rb
Created July 2, 2012 03:21
is_prime? ruby method
def is_prime?(n)
((2..(Math.sqrt(n)))).each do |i|
return false if n % i == 0
end
return true
end
@jtallant
jtallant / euler4.rb
Created July 7, 2012 05:31
Project Euler Problem 4 Ruby
# A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 99.
# Find the largest palindrome made from the product of two 3-digit numbers.
def looped_palindrome(num1,num2=num1)
product = 0
while num1 > 900
product = num1 * num2
return product if product.to_s == product.to_s.reverse
if num2 > 900
num2 -= 1
@jtallant
jtallant / getters-setters.rb
Created July 11, 2012 23:04
Ruby Getters and Setters
class Prescription
# setter for rx_name
def rx_name=(value)
@rx_name = value
end
# setter for patient name
def patient_name=(value)
@patient_name = value
end