Skip to content

Instantly share code, notes, and snippets.

View hpjaj's full-sized avatar

Harry Levine hpjaj

View GitHub Profile
@hpjaj
hpjaj / gist:241699452a0b5cf3e0df
Created September 4, 2014 05:47
2c_convert_challenge.rb
# start prompt should prompt user to enter what they want to convert from and to
# prompt user for value to be converted
# display converted value
# display start prompt
@absolute_zero_in_celsius = -273.15
@absolute_zero_in_fahrenheit = -459.67
def quit
puts
@hpjaj
hpjaj / gist:978310a9ca9fb48a59e8
Last active August 29, 2015 14:06
Leap year calculator
puts "Enter a year and I will tell you TRUE or FALSE, if that year is or is not a leap year."
print "> "
@year_choice = gets.chomp.to_i
leap_year_calculator = case
when @year_choice % 400 == 0 then true
when @year_choice % 100 == 0 then false
else @year_choice % 4 == 0
end
@hpjaj
hpjaj / gist:33393c6a7160d1639c02
Created September 11, 2014 16:35
1e_split_a_string.rb
s = "Welcome to the forum.\nHere you can learn Ruby.\nAlong with other members.\n"
def string_processor(non_split_string)
line_number = 0
split_into_sentences = non_split_string.split(/\n/)
split_into_sentences.each do |sentence|
sentence.prepend("Line " + (line_number += 1).to_s + ": " )
end
end
@hpjaj
hpjaj / gist:f4ee70cf92a8c08637df
Last active August 29, 2015 14:06
week 3 - 6e def granny part 1
def start_program
puts "Soooo, what's new, sonny boy?"
gets_grandsons_input
end
def gets_grandsons_input
print "> "
@grandson_choice = gets.chomp
determines_if_grandma_heard
end
@hpjaj
hpjaj / gist:2bc581e93c671011dbd8
Created September 18, 2014 04:27
week 3 - 8e
(1..100).each do |num|
if num % 3 == 0 && num % 5 == 0
puts "FizzBuzz"
elsif num % 3 == 0
puts "Fizz"
elsif num % 5 == 0
puts "Buzz"
else
puts num
end
@hpjaj
hpjaj / gist:0d21e889d1a8a73ed604
Created December 6, 2014 21:12
week 3 - 1e - Ten for Fifty
def method
a = 50
puts a
end
a = 10
method
puts a
=begin
@hpjaj
hpjaj / gist:c4c922067867242f599f
Last active August 29, 2015 14:10
Week 3 - 2e - Inserted Word
def find_and_replace_files_existing_string_with_new_string(filename, old_string, new_string)
original_file_content = File.read("#{filename}")
new_file_content = original_file_content.gsub(old_string, new_string)
File.write("#{filename}", new_file_content)
end
=begin
Here is the existing sample file entitled 'plain_text.txt':
text text text text text
@hpjaj
hpjaj / gist:955320535f302e4172d9
Last active August 29, 2015 14:10
Week 3 - 3e - Directory Manipulation
# Returns the path to the current working directory,
# in the form of a string
Dir.getwd
# Creates a new working directory entitled 'tmp' within
# the current directory
Dir.mkdir("tmp")
@hpjaj
hpjaj / gist:01a71a19c8ca297e0fe8
Last active August 29, 2015 14:10
Week 3 - 2e.v2 - 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)
File.write("#{content}", new_file_content)
else
@original_content = content
new_file_content = @original_content.gsub(old_string, new_string)
# gsub is better for testing purposes
@hpjaj
hpjaj / gist:e74c97eb534a8df4e040
Created December 7, 2014 18:26
Week 3 - 5e - Key = Value
s = 'key=value'
# arr = s.split("=")
s1, s2 = s.split("=")[0], s.split("=")[1]
#s1, s2 = arr[0], arr[1]
puts s1 #=> key
puts s2 #=> value