Skip to content

Instantly share code, notes, and snippets.

View nthj's full-sized avatar

Nathaniel Jones nthj

  • Orlando, FL
View GitHub Profile
class VeryVeryBadException < RuntimeError
end
begin
raise VeryVeryBadException, "winter is coming"
def bouncer(name, age = 18)
if age < 21
puts "Go away, #{name}"
else
puts "OK"
end
end
# Quiz Exercise, Part One
#
# Quiz for a list of names & birthdays,
# then list out their ages
#
# For example:
#
# Hey there! Please enter a list of names:
# > John, Sam, Bob, Alisha, Henry
#
# Quiz Exercise, Part One
#
# Quiz for a name and birthday,
# then display the age
#
# For example:
#
# Hey there! Please enter your name:
# > John
#
# Quiz Exercise, Part One
#
# Quiz for a name and birthday,
# then display the age
#
# For example:
#
# Hey there! Please enter your name:
# > John
#
@nthj
nthj / exercise-2.rb
Last active December 30, 2015 19:39
# Quiz Exercise, Part One
#
# Quiz for a list of names & birthdays,
# then list out their ages
#
# For example:
#
# Hey there! Please enter a list of names:
# > John, Sam, Bob, Alisha, Henry
#
@nthj
nthj / car.rb
Created December 4, 2013 17:41
Class vs Instance
class Car
class << self
def advertise(model)
puts "BUY IT NOW! #{model}"
end
def manufacture(make)
def ask_for_age(name)
# We have to ask for this person's age
print "What is #{name}'s age? "
rand(100) # gets.chomp.to_i
end
# Roomful of People
@nthj
nthj / javascript_generator.rb
Created October 25, 2013 20:16
Add this to `lib/generators/javascript_generator.rb`
class JavascriptGenerator < Rails::Generators::NamedBase
def create_javascript_files
create_file "app/assets/javascripts/#{file_name}.coffee", "# New JavaScript File"
create_file "spec/javascripts/#{file_name}_spec.coffee", <<-SPEC
describe "test for #{file_name}", ->
$(document).ready(function(){
// Explicitly set the left positioning,
// based on the current position calculated by the Browser.
// This "locks" the sidebar to its current x-axis, even
// when we change the positioning strategy in a moment
$('#sidebar').css('left', $('#sidebar').offset().left + 'px');
$(window).scroll(function(){
// Has the visitor scrolled down past the headmast?
// If the headmast is 100 pixels tall, and