Skip to content

Instantly share code, notes, and snippets.

@egrueter-dev
egrueter-dev / deaf_grandma
Created December 20, 2014 21:10
Deaf Grandma
puts "Say Something to Grandma"
bye = 0
while bye < 3
reply = gets.chomp
if reply == "BYE"
bye += 1
elsif reply == reply.upcase #condition, not variable put ==
puts "No, not since #{rand(1930..1950)}" #string interpolation "#{variable}" #Use .. to do numbers inclusive (... exclusive
else
@egrueter-dev
egrueter-dev / 99bottles
Created December 24, 2014 20:56
99bottles
class Song
def booze (bottle, number)
@bottle = bottle
@number = number
end
def sing
while number != 0
puts "#{number} Bottles of #{bottle} on the wall, #{number} bottles of #{bottle}, you take one down, pass it around #{number-1} bottles of #{bottle} on the wall"
@egrueter-dev
egrueter-dev / Favorite_Movies
Last active August 29, 2015 14:14
Favorite_Movies - Launch Exercise
#Using the array of hashes above, output the titles, along with their year to achieve the following output.
# 1998: The Big Lebowski
# 1980: The Shining
# 1990: Troll 2
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 }
@egrueter-dev
egrueter-dev / gist:499ad013aac35e2b32c9
Last active August 29, 2015 14:15
Guess-the-number
class GuessingGame
def initialize(guess)
$user_choice = guess
$comp_selection = rand(1...1000)
end
def numeric?(user_choice)
true if Float(user_choice) rescue false
end
@egrueter-dev
egrueter-dev / quicksort.rb
Created February 24, 2015 22:41
Quick-sort Algorithm
def quick_sort(arr)
return arr if arr.length <= 1
pivot = arr.pop
less_than_pivot = arr.select { |x| x < pivot }
greater_than_pivot = arr.select { |x| x > pivot }
quick_sort(less_than_pivot) + [pivot] + quick_sort(greater_than_pivot)
end
print quick_sort([1,5,9,2,45,2,3,4,4545])
@egrueter-dev
egrueter-dev / 0_reuse_code.js
Last active August 29, 2015 14:17
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@egrueter-dev
egrueter-dev / Nested_Routes_Example.rb
Last active August 29, 2015 14:17
Handling Nested Routes - Categories/ Drinks Example
# This index handler lets you navigate to the following routes:
#category_drinks | GET | /categories/:category_id/drinks(.:format) | drinks#index
# drinks | GET | /drinks(.:format) | drinks#index
# and...
def index
if params.include?('category_id')
category = Category.find(params[:category_id])
@drinks = Drink.where(category: category).page(params[:page])
else
@egrueter-dev
egrueter-dev / new_gist_file.md
Created March 25, 2015 14:25
Ray's Algorithms and Interview Questions Cheat Sheet!

ALGORITHMS AND INTERVIEW QUESTIONS CHEAT SHEET

DATA STRUCTURES

A data structure is a group of data organized in the computer's memory by certain specific rules defining predictable relationships between the data. Arrays, hashes and relational databases are all examples of data structures.

@egrueter-dev
egrueter-dev / application.css.scss
Created April 10, 2015 14:45
Stick footer to bottom of page, this footer also responds to changes in page height.
.body-class {
min-height: 84%;
}
@egrueter-dev
egrueter-dev / time_conversion.js
Last active August 29, 2015 14:19
Javascript -> Ruby Datetime Conversion
var d = new Date(1394648309130.185)
d // Wed Mar 12 2014 11:18:29 GMT-0700 (Pacific Daylight Time)
d.getTime()
// 1394648309130 // Fractions of a millisecond are dropped