Skip to content

Instantly share code, notes, and snippets.

View J-Scag's full-sized avatar

Josh Scaglione J-Scag

  • New York
View GitHub Profile
@J-Scag
J-Scag / grains.rb
Last active December 26, 2015 10:49
Grains TODO for Flatiron School day 23
# There once was a wise servant who saved the life of a prince. The king promised to pay whatever the servant could dream up. Knowing that the king loved chess, the servant told the king he would like to have grains of wheat. One grain on the first square of a chess board. Two grains on the next. Four on the third, and so on.
# There are 64 squares on a chessboard.
# Write a program that shows
# - how many grains were on each square, and
# - the total number of grains
# ## For bonus points
@J-Scag
J-Scag / serialize.rb
Last active December 25, 2015 14:29
Serialize TODO for Flatiron School day 16
RSpec.configure do |config|
# Use color in STDOUT
config.color_enabled = true
# Use color not only in STDOUT but also in pagers and files
config.tty = true
# Use the specified formatter
config.formatter = :progress # :progress, :html, :textmate
end
@J-Scag
J-Scag / prime.rb
Created October 11, 2013 15:38
Prime finder for Flatiron School day 7
def prime_slow?(number)
(2..number/2).each {|num| return false if number % num == 0}
true
end
puts prime_slow?(19)
puts prime_slow?(14)
puts prime_slow?(157)
puts prime_slow?(273)
@J-Scag
J-Scag / version_sort.rb
Created October 11, 2013 15:33
Version sort TODO for Flatiron School day 7
filenames = [
"foo-1.10.2.ext",
"foo-1.11.ext",
"foo-1.3.ext",
"foo-1.50.ext",
"foo-1.8.7.ext",
"foo-1.9.3.ext",
"foo-1.ext",
"foo-10.1.ext",
"foo-10.ext",
@J-Scag
J-Scag / ruby.basics.rb
Created October 11, 2013 15:03
Ruby Basics TODO for Flatiron School day 3
# Download this file:
# https://gist.github.com/aviflombaum/28534c5d69edd2439a7d/download
# Run it from your terminal with:
# ruby ruby.basics.rb
# (Just make sure you are in the right directory)
# ======================================
# Ignore All This Code
# ======================================
@J-Scag
J-Scag / roman_numerals.rb
Created October 11, 2013 14:12
Roman numerals TODO for Flatiron School day 15
# # Roman Numerals
# The Romans were a clever bunch. They conquered most of Europe and
# ruled it for hundreds of years. They invented concrete and straight
# roads and even bikinis. One thing they never discovered though was
# the number zero. This made writing and dating extensive histories
# of their exploits slightly more challenging, but the system of
# numbers they came up with is still in use today. For example the
# BBC uses Roman numerals to date their programmes.
@J-Scag
J-Scag / person.rb
Last active December 25, 2015 04:38
Mass-assignment TODO for Flatiron School day 14
class Person
def initialize(attribute_hash)
@attr_hash = attribute_hash
@attr_hash.each do |attribute, value|
self.metaclass.send(:define_method, "#{attribute}") do
@attr_hash[attribute]
end
end
end
@J-Scag
J-Scag / triangle.rb
Created October 9, 2013 13:07
Triangles TODO for Flatiron School day 13
class Triangle
attr_accessor :kind
def initialize(a, b, c)
raise TriangleError if a<=0 || b<=0 || c<=0
raise TriangleError if a+b<=c || b+c<=a || a+c<=b
if a == b && b == c
self.kind = :equilateral
elsif a == b || b == c || c == a
@J-Scag
J-Scag / jukebox.rb
Created October 8, 2013 23:25
100% coverage jukebox spec with simplecov
# A Jukebox filled with songs
# that responds to help, list, play, and exit
require_relative 'song'
class Jukebox
attr_accessor :songs
APPROVED_COMMANDS = [:list, :help, :exit]
def initialize(songs)
@songs = songs
@J-Scag
J-Scag / school_domain.rb
Created October 8, 2013 22:59
School domain homework for Flatiron School day 12
class School
attr_reader :name, :roster
def initialize(name)
@roster = {}
@name = name
end
def add_student(name, grade)