Skip to content

Instantly share code, notes, and snippets.

View hpjaj's full-sized avatar

Harry Levine hpjaj

View GitHub Profile
@hpjaj
hpjaj / gist:f312ee899dc4d98213db
Last active August 29, 2015 14:10
Week 3 - 6e - Deaf Granny Part 1
def sonny_says
puts "Sonny says:"
print "> "
@what_sonny_says = gets.chomp
end
def random_year_generator(starting_year, ending_year)
@random_year = rand(starting_year..ending_year)
end
@hpjaj
hpjaj / gist:6f1b4cd93ede384be4f3
Last active August 29, 2015 14:11
Week 3 - 6e.v2 - Deaf Granny Part 1
def sonny_says
puts "Sonny says:"
print "> "
what_sonny_says = gets.chomp
end
def random_year(year_range)
year = rand(year_range)
end
@hpjaj
hpjaj / gist:40f2c8474ff244e8b17b
Created December 8, 2014 17:53
week 3 - 2e.v3 - inserted word
def find_and_replace(content, old_string, new_string)
@content_to_be_reset = content
if File.file?("#{content}")
@original_content = File.read("#{content}")
new_file_content = @original_content.gsub(old_string, new_string)
else
@original_content = content
new_file_content = @original_content.gsub!(old_string, new_string)
# gsub is better for testing purposes
# use gsub! if you want the string to retain its newly replaced content
@hpjaj
hpjaj / analyzer.rb
Last active August 29, 2015 14:11
week 3 - 7e - Document Stats
def reads_a_file(file)
files_content = File.read(file)
end
def character_count_with_spaces(file_string)
file_string.length
end
@hpjaj
hpjaj / analyzer_v2.rb
Last active August 29, 2015 14:11
week 3 7e.v2 - document statitics
def reads_a_file(file)
File.read(file)
end
def character_count_with_spaces(file_string)
file_string.length
end
@hpjaj
hpjaj / fizzBuzz.rb
Created December 8, 2014 21:51
week 3 - 8e - fizz buzz
def fizzBuzz(num_range)
(num_range).each do |num|
if ( num % 3 == 0 ) && ( num % 5 == 0 )
print 'FizzBuzz'
elsif num % 3 == 0
print 'Fizz'
elsif num % 5 == 0
print 'Buzz'
else
print num
@hpjaj
hpjaj / gist:df0f78b2a02da9f2fc49
Created December 8, 2014 22:14
week 3 - 9e - Reverse word order
def reverse_word_order(string)
string.split(" ").reverse.join(" ")
end
blah = "Hi there John"
puts reverse_word_order(blah)
@hpjaj
hpjaj / gist:0f30b7653a5429a33a52
Created December 8, 2014 22:27
week 3 - 10e - Sum of elements
def sums_an_array(arr)
sum = 0
arr.each do |num|
sum += num
end
sum
end
collection = [1, 2, 3, 4, 5]
puts sums_an_array(collection)
@hpjaj
hpjaj / gist:266f26422cb7470bba98
Created December 8, 2014 22:39
week 3 - 11e - Odd or even
def odd_or_even(arr)
arr.each do |num|
print num
puts num % 2 == 0 ? ' is even' : ' is odd'
end
end
collection = [12, 23, 456, 123, 4579]
odd_or_even(collection)
@hpjaj
hpjaj / gist:8b45551eeb81f3f101b9
Created December 8, 2014 23:00
week 3 - 12e - Who did not attempt quiz 1
def quiz_completion_numbers(arr)
incomplete = []
arr.each do |num|
( incomplete << num ) if ( num == 0 )
end
"The number of participants who did not attempt Quiz 1 is #{incomplete.length} out of #{arr.length} total participants."
end
quiz = [0,0,0,1,0,0,1,1,0,1]
puts quiz_completion_numbers(quiz)