Skip to content

Instantly share code, notes, and snippets.

@samueldowens
samueldowens / cli.rb
Created October 16, 2013 21:03
cli for playlister
require_relative '../config/environment'
class CLI
attr_accessor :songs
def initialize
@songs = Song.all
@on = true
call
end
@samueldowens
samueldowens / serialize.rb
Created October 15, 2013 13:33
Serialize Solution
class Song
attr_accessor :title, :artist
def serialize
File.new("#{self.title.gsub(" ", "_")}.txt", "w")
File.open("#{self.title.gsub(" ", "_")}.txt", "w") do |f|
f.print "#{self.artist.name} - #{self.title}"
end
end
@samueldowens
samueldowens / tweet_shortener.rb
Created October 11, 2013 15:47
tweet shortener
tweet1 = "Hey guys, can anyone teach me how to be cool? I really want to be the best at everything, you know what I mean? Tweeting is super fun you guys!!!!"
tweet2 = "OMG you guys, you won't believe how sweet my kitten is. My kitten is like super cuddly and too cute to be believed right?", "I'm running out of example tweets for you guys, which is weird, because I'm a writer and this is just writing and I tweet all day. For real, you guys. For real."
tweet3 = "GUISEEEEE this is so fun! I'm tweeting for you guys and this tweet is SOOOO long it's gonna be way more than you would think twitter can handle, so shorten it up you know what I mean? I just can never tell how long to keep typing!"
def shortener(tweet)
tweet.join(" ")
array = tweet.split(" ")
i = 0
array.each do |word|
@samueldowens
samueldowens / fizzbuzz.rb
Created October 11, 2013 15:34
fizz buzz
# assignment.rb
# FizzBuzz - The Programmer's Stairway to Heaven
# Define the fizzbuzz method to do the following: 10pts
# Use the modulo % method (divisible by)
# 2 % 2 #=> true
# 1 % 2 #=> false
# If a number is divisible by 3, puts "Fizz".
# If a number is divisible by 5, puts "Buzz".
# If a number is divisible by 3 and 5, puts "FizzBuzz"
@samueldowens
samueldowens / roman_numeral.rb
Created October 11, 2013 13:23
with a hash this time
class Integer
def to_roman
numeral = ""
number = self
hash = {1000 => "M", 900 => "CM", 500 => "D", 400 => "CD", 100 => "C", 90 => "XC", 50 => "L", 40 => "XL", 10 => "X", 9 => "IX", 5 => "V", 4 => "IV", 1 => "I"}
hash.each do |key, value|
until number < key
numeral << value
@samueldowens
samueldowens / roman_numerals.rb
Created October 11, 2013 13:06
made it work, going to compact it.
class Integer
def to_roman
numeral = ""
number = self
until number == 0 do
if number >= 1000
number -= 1000
numeral << "M"
elsif number >= 900
@samueldowens
samueldowens / jukebox_spec.rb
Created October 9, 2013 15:21
rspec file for the jukebox test suite
require 'simplecov'
SimpleCov.start
require 'json'
require 'rspec'
require_relative 'jukebox'
require_relative 'song'
describe Song do
it 'can have a name' do
@samueldowens
samueldowens / triangle.rb
Created October 9, 2013 13:24
triangle to_do
class Triangle
attr_accessor :side1, :side2, :side3
def initialize(side1, side2, side3)
@side1 = side1
@side2 = side2
@side3 = side3
end
@samueldowens
samueldowens / gist:6885748
Created October 8, 2013 14:38
jukebox_oo.rb
songs = [
"1. The Phoenix - 1901",
"2. Tokyo Police Club - Wait Up",
"3. Sufjan Stevens - Too Much",
"4. The Naked and the Famous - Young Blood",
"5. (Far From) Home - Tiga",
"6. The Cults - Abducted",
"7. The Phoenix - Consolation Prizes"
]
@samueldowens
samueldowens / gist:6868143
Last active December 24, 2015 21:49
anagrams.rb
class Anagram
def initialize(word)
@name = word
end
def match(array)
matched = []
array.each do |string|
if string.chars.sort == @name.chars.sort
matched << string