This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getDateRanges($dates) { | |
$dates = array_unique($dates); | |
sort($dates); | |
$count = 0; | |
$ranges = []; | |
while ($count < count($dates)) { | |
$consecutive = true; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Enter the amount of items per page | |
$perPage = 20; | |
// Grab the current page (No hidden form required! This just works.) | |
$currentPage = Input::get('page') - 1; | |
// Slice your array | |
$pagedData = array_slice($yourArray, $currentPage * $perPage, $perPage); | |
// Paginate! | |
$paginatedArray = Paginator::make($pagedData, count($yourArray), $perPage); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
favorite_movies = [ | |
{ title: 'The Big Lebowski', year_released: 1998, director: 'Joel Coen', imdb_rating: 8.2 }, | |
{ title: 'The Shining', year_released: 1980, director: 'Stanley Kubrick', imdb_rating: 8.5 }, | |
{ title: 'Troll 2', year_released: 1990, directory: 'Claudio Fragasso', imdb_rating: 2.5 } | |
] | |
favorite_movies.each do |movie| | |
puts "#{movie[:year_released]}: #{movie[:title]}" | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def old_roman_numeral number | |
i = 0 | |
v = 0 | |
x = 0 | |
l = 0 | |
c = 0 | |
d = 0 | |
m = 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def ask question | |
while true | |
puts question | |
reply = gets.chomp.downcase | |
if (reply == "yes" || reply == "no") | |
if reply == "yes" | |
return true | |
#answer = true | |
else |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
line_width = 40 | |
contents = ["Table of Contents", "Chapter 1: Getting Started", "page 1 ", "Chapter 2: Numbers", "page 9 ", "Chapter 3: Letters", "page 13"] | |
puts contents[0].center(line_width) | |
puts nil | |
puts contents[1].ljust(line_width) + contents[2].rjust(line_width/3) | |
puts contents[3].ljust(line_width) + contents[4].rjust(line_width/3) | |
puts contents[5].ljust(line_width) + contents[6].rjust(line_width/3) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
puts "Enter as many words as you like." | |
puts "I\'ll sort them alphabetically for you!" | |
puts "Hit \"Enter\" on an empty line when you\'re done." | |
words = gets.chomp | |
words_array = [] | |
while words != "" | |
words_array << words.to_s.capitalize | |
words = gets.chomp |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
puts "What year would you like to start with?" | |
year1=gets.chomp | |
puts "And what year would you like to end with?" | |
year2=gets.chomp | |
puts nil | |
year1.to_i.step(year2.to_i,4) do |num| | |
if (num % 4 == 0 && !(num % 100 == 0 && num % 400 != 0)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
beer = 99 | |
while beer != 0 | |
#to be grammatically correct, I had to add multiple conditions | |
if beer > 2 | |
beer = beer - 1 | |
puts (beer + 1).to_s + " bottles of beer on the wall, " + (beer + 1).to_s + " bottles of beer!" | |
puts "Take one down, pass it around, " + beer.to_s + " bottles of beer on the wall!" | |
puts nil |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
line_width = 50 | |
puts "Table of Contents".center(line_width) | |
puts nil | |
puts "Chapter 1: Getting Started".ljust(line_width/2) + "page 1 ".rjust(line_width/2) | |
puts "Chapter 2: Numbers".ljust(line_width/2) + "page 9 ".rjust(line_width/2) | |
puts "Chapter 3: Letters".ljust(line_width/2) + "page 13".rjust(line_width/2) |
NewerOlder