Skip to content

Instantly share code, notes, and snippets.

@kylekeesling
kylekeesling / leap.rb
Created November 10, 2015 19:59
Leap Year Calculator
puts "Enter a starting year in the format YYYY"
starting = gets.chomp!.to_i
puts "Enter an ending year in the format YYYY"
ending = gets.chomp!.to_i
puts "LEAP YEARS between #{starting} and #{ending}"
starting.upto(ending) do |year|
divisible_by_4 = (year % 4) == 0
not_divisible_by_100 = (year % 100) != 0
divisible_by_400 = (year % 400) == 0
@kylekeesling
kylekeesling / 99_bottles.rb
Created November 10, 2015 20:06
99 Bottles of Beer...
num_bottles = 99
while num_bottles > 0
puts "#{num_bottles} bottles of beer on the wall,
#{num_bottles} bottles of beer, take one down, pass it
around, #{num_bottles - 1} bottles of beer on the wall!"
num_bottles = num_bottles - 1
end
@kylekeesling
kylekeesling / english_number.rb
Created November 12, 2015 21:08
Output numbers into english words
def englishNumber number
if number < 0 # No negative numbers.
return 'Please enter a number that isn\'t negative.'
end
if number == 0
return 'zero'
end
# No more special cases! No more returns!
@kylekeesling
kylekeesling / fancy_99_bottles.rb
Last active November 12, 2015 21:08
Output the 99 bottles of beer song with numbers in words rather than integers
require_relative 'english_number.rb' #https://gist.github.com/kylekeesling/4b73a984421f120312de
num_bottles = 999
while num_bottles > 0
puts "#{englishNumber(num_bottles)} bottles of beer on the wall,
#{englishNumber(num_bottles)} bottles of beer, take one down, pass it
around, #{englishNumber(num_bottles - 1)} bottles of beer on the wall!"
num_bottles = num_bottles - 1
end
@kylekeesling
kylekeesling / wedding_number.rb
Last active November 12, 2015 21:10
Outputs numbers as words with proper conjunctions - like you'd see on a wedding invite
def weddingNumber number
if number < 0 # No negative numbers.
return 'Please enter a number that isn\'t negative.'
end
if number == 0
return 'zero'
end
# No more special cases! No more returns!
@kylekeesling
kylekeesling / example.html
Created January 18, 2013 19:50
How to use the jQuery Cookie plugin
<!doctype html>
<html>
<head>
<title>Example</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<!-- Available here: https://github.com/carhartl/jquery-cookie -->
<script src="jquery.cookie.js"></script>
</head>
<body>
<script>
@kylekeesling
kylekeesling / kkees.plugin.zsh
Created November 15, 2013 17:32
An oh-my-zsh plugin that creates a terminal command to quickly get your rails project updated and ready to code. Assumes you're using Rails, git and Sublime Text. Also assumes your apps are stored in '~/sites', should be able to tweak this a little if your environment is a little different. Is really great if you use multiple machines for develo…
start_working() { cd ~/sites/$1; git pull; bundle install; rake db:migrate; subl .; }
@kylekeesling
kylekeesling / paginator.html
Created October 31, 2013 12:35
Simple Jekyll Paginator Logic I didn't like the pagination logic provided in the Jekyll Docs (http://jekyllrb.com/docs/pagination/) since it repeated the HTML for displaying the button, so I came up w/ this. It stores the proper previous page path into a liquid variable then plops it into the HREF so you only have to code your button once
{% if paginator.previous_page %}
{% if paginator.previous_page == 1 %}
{% capture previous_page %}/{% endcapture %}
{% else %}
{% capture previous_page %}/page{{ paginator.previous_page }}{% endcapture %}
{% endif %}
<a href="{{ previous_page }}" class="previous">&larr; Newer Posts</a>
{% endif %}
{% if paginator.next_page %}
@kylekeesling
kylekeesling / birth_date.rb
Created March 17, 2016 21:37
Birthday Calculator
puts "What year where you born? (Enter a 4 digit year, ie 1984)"
birth_year = gets.chomp
puts "What month where you born? (Enter the month number, ie June would be 6)"
birth_month = gets.chomp
puts "What day of the month where you born?"
birth_day = gets.chomp
@kylekeesling
kylekeesling / cookie.rb
Created March 18, 2016 00:07
Cookie example from the GDI Ruby Class 2016-03-17