Dir.chdir("/home/matt/food")
Dir.glob("*.txt")
.collect { |f| f.chomp(".txt") }
.sample(7)
.each { |file| puts [file, File.open("#{file}.txt").read(), ""] }
# block notation for 1 line
3.times {|i| puts i}
# block notation for multiple lines
100.times do |i|
if (i % 3==1) && (i % 2==1)
puts i
end
end
# prints the values 2, 4, 6
puts [1,2,3].collect {|i| i * 2}
#prints the values 2, 4, 6
arr = [1,2,3]
arr.collect!{|i| i * 2}
puts arr
I really hate having to think of meals to cook every night of the week. It's like one of my absolute least favorite things to do. So, bless you Ruby, for you have given me a random weekly menu in only 12 lines of code. I dump text files named as recipes into a folder that contain my ingredient list and cooking directions. A PHP shell exec (all I know, sorry, I'm a PHP idiot too!) lets me run it via my browser to my LAN server. F5 and a whole 'nother week is presented :)
Any other cool little niche projects to make home life easier?
Sample output:
Just need to add some more meals to my folder and finish writing up the ones I did add :) Simple formatting gives me a 2-3pg long list to print, shop, then cook directly from each week now!