Skip to content

Instantly share code, notes, and snippets.

@sjwats
sjwats / 0_reuse_code.js
Created December 30, 2013 15:54
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
@sjwats
sjwats / tdd_word_analytics.rb
Created December 14, 2013 22:17
TDD Word Analytics - Given a long string or set of paragraphs, perform some analysis that provides the following: Number of each word Number of each letter Number of each symbol (any non-letter and non-digit character, excluding white space) Top three most common words Top three most common letters
class WordAnalytics
def initialize(stringed_words)
@stringed_words = stringed_words
end
def separate_words
@words = []
split_words = []
split_words = @stringed_words.split(' ')
split_words.each do |word|
@sjwats
sjwats / anagram.rb
Created December 11, 2013 15:57
Campaign Charlie - Anagram TDD
class AnagramGenerator
attr_reader :word
def initialize(word)
@word = word.downcase
end
def separate_word
@separate_words = @word.split('')
end
@sjwats
sjwats / tdd_word_count.rb
Created December 10, 2013 02:25
TDD Word Count - Create an object that takes a long string and returns the frequency of each word in it.
class WordTracker
attr_reader :string
def initialize(string)
@string = string
@word_hash = {}
end
def log_lowercase_words
@words_in_string = @string.split.map.each {|word| word.downcase.to_s}
end
@sjwats
sjwats / recipe_database.txt
Created December 9, 2013 23:12
SQL Challenge - Movie queries and recipe database
CREATE TABLE recipes (
id serial,
name varchar(255),
serving_size varchar(200),
total_time varchar(40),
created_at timestamp NOT NULL,
directions text NOT NULL,
);
CREATE TABLE ingredients (
@sjwats
sjwats / circle.rb
Last active December 30, 2015 18:19
Campaign Bravo Checkpoint - TDD - Your engineering team is working on a product that teaches students Geometry. You are tasked with coming up with a library of geometric shape classes that know how to calculate their area and perimeter. You must use TDD to drive your development.
class Circle
attr_reader :radius
def initialize(radius)
if radius <= 0
raise "The supplied value #{radius} cannot be used. Supply a positive Float or Integer."
return nil
end
@radius = radius.abs
end
@sjwats
sjwats / pig_latin.rb
Created December 6, 2013 21:04
Pig Latin TDD Style
class PigLatinTranslation
def initialize(phrase)
@phrase = phrase
@vowels = ["a", "e", "i", "o", "u"]
@translation_array = []
end
def translate
words_array = words
index = 0
@sjwats
sjwats / pig_practice.rb
Last active December 30, 2015 04:19
OOPII - Pig Latin
class PigLatinTranslation
def initialize(phrase)
@phrase = phrase
@vowels = ["a", "e", "i", "o", "u"]
@translation_array = []
end
def translate
words_array = words
index = 0
@sjwats
sjwats / inheritance.rb
Created December 3, 2013 02:24
OOPII - Inheritance - Quick Challenge - write a set of classes that represent a set of animals. There should be a Duck, Cat, and Dog instance that all implement an emote (**hint**: what sound does a duck make?) and a eat method. A constructor that takes a name as an argument should be defined elsewhere.
class Animal
attr_reader :name
def initialize(name)
@name = name
end
def eat
["Stuff in nature"]
end
@sjwats
sjwats / class_methods_variables
Last active December 30, 2015 02:19
OOPII Class Methods and Variables Quick Challenge: Can you use a hash with arrays as values to validate both the make and model? For example, we can have a Volkswagen Jetta but we can't have a Ford Jetta. Modify the latest Car implementation so that it takes a hash of data.
class Car
@@makes = []
def self.add_make(make, *models)
@@makes << {make => models}
end
def self.valid_makes(make, model)
index = 0
match = false