Skip to content

Instantly share code, notes, and snippets.

bottle_lyric = ->(count) { "#{count} #{count == 1 ? "bottle" : "bottles"} of beer" }
99.downto(2) do |c|
puts "#{bottle_lyric.call(c)} on the wall,"
puts "#{bottle_lyric.call(c)}!"
puts "Take one down, pass it around"
puts "#{bottle_lyric.call(c-1)} on the wall!"
puts
end
@octosteve
octosteve / upvote_calculator.rb
Created October 29, 2013 02:28
Solution from conditionals class
class UpvoteCalculator
attr_reader :story, :category
def initialize story, category
@story = story
@category = category
end
def upvotes
upvotes = 1
require 'minitest/autorun'
describe Toy do
it "has a name, description, and a player" do
bopit = Toy.new "Bop-it!", "A game for grabby people", "Steven"
bopit.welcome.must_equal "Welcome to Bop-it! Steven! A game for grabby people"
end
it "can have the player changed" do
bopit = Toy.new "Bop-it!", "A game for grabby people", "Steven"
@octosteve
octosteve / exercise_test.rb
Created October 24, 2013 01:06
Teaching tests
require 'minitest/autorun'
describe Person do
it "is initialized with a name and profession" do
person = Person.new "Steven", "Software Developer"
person.introduce.must_equal "Hi! My name is Steven. I'm a Software Developer"
person.introduce_from_across_the_room.must_equal "HI! MY NAME IS STEVEN. I'M A SOFTWARE DEVELOPER"
end
end
@octosteve
octosteve / toy.rb
Last active December 26, 2015 09:29
Toy = Class.new do
def initialize name, description, player
@name = name
@description = description
@player = player
end
def player player_name
@player = player_name
end
@octosteve
octosteve / githubintro.sh
Created October 17, 2013 14:16
Notes from the install fest. Anything that starts with a '#' sign is for you to read
# We created a folder to house our code for the class
mkdir code
# We changed into that directory
cd code
# We verified git was installed
which git
# After forking on github, we cloned OUR copy
git clone https://github.com/StevenNunez/BEWD_NYC_5.git
# We checked what folders are in our code folder. Cloning creates a folder named after the repository.
ls
@octosteve
octosteve / email.rb
Last active December 25, 2015 08:09 — forked from bjbatten/gist:6938812
require 'date'
class Email
attr_reader :email_text
def initialize(email_text)
@email_text = email_text
end
def date
@date ||= parsed_date.strftime('%a %d %b %Y')
end
# Cup
# You can ask if it's full or not
#
# You can fill it
# You can empty
# if You try to empty it and it's empty is says "I'm already empty"
# if You try to fill it and it's full is says "I'm already full"
class Cup
attr_accessor :owner
@octosteve
octosteve / ImperialMarch.ino
Created October 1, 2013 22:19
Imperial march played on an Arduino with a Piezo Element
int speakerPin = 9;
int length = 70;
String notes[] = {"G4","G4", "G4", "D#4/Eb4", "A#4/Bb4", "G4", "D#4/Eb4","A#4/Bb4", "G4", "D5", "D5", "D5", "D#5/Eb5", "A#4/Bb4", "F#4/Gb4", "D#4/Eb4","A#4/Bb4", "G4", "G5","G4","G4","G5","F#5/Gb5", "F5","E5","D#5/Eb5","E5", "rest", "G4", "rest","C#5/Db5","C5","B4","A#4/Bb4","A4","A#4/Bb4", "rest", "D#4/Eb4", "rest", "F#4/Gb4", "D#4/Eb4","A#4/Bb4", "G4" ,"D#4/Eb4","A#4/Bb4", "G4"};
int beats[] = { 8, 8, 8, 6, 2, 8, 6 , 2 ,16 , 8, 8, 8, 6, 2, 8, 6, 2, 16,8,6,2,8,6,2,2, 2, 2,6,2,2,8,6,2,2,2,2,6,2,2,9,6,2,8,6,2,16 };
int tempo = 50;
void playTone(int tone, int duration) {
for (long i = 0; i < duration * 1000L; i += tone * 2) {
digitalWrite(speakerPin, HIGH);
delayMicroseconds(tone);
@octosteve
octosteve / second_seeds.rb
Created May 14, 2013 02:15
More info, pass validation
# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
#
# Examples:
#
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel', city: cities.first)
#
puts "Adding a Whole bunch of movies"
Movie.create [