Skip to content

Instantly share code, notes, and snippets.

View bswinnerton's full-sized avatar

Brooks Swinnerton bswinnerton

View GitHub Profile
99.downto(1) do |i|
puts "#{i} #{i.between?(2,99) ? "bottles" : "bottle"} of beer on the wall"
puts "#{i} #{i.between?(2,99) ? "bottles" : "bottle"} bottles of beer!"
puts "You take one down and pass it around,"
puts "#{i} #{i.between?(2,99) ? "bottles" : "bottle"} bottles of beer on the wall!"
puts 'No more bottles of beer on the wall :-(' if i == 1
puts
end

Submitting homework

So we use Git to track different versions of code (what the code is doesn't really matter; homework, your web application, whatever). One way to accomplish this goal would just to make backups of a folder every day - but that's a huge pain and it's really easy to forget to do. Enter Git: it's a command line utility that allows you to "commit" code to a timeline. This is useful for a few reasons:

  • You can easily see who contributed what code and when
  • If something gets really messed up, you can simply revert your code to a different point in time
  • It allows you to branch out into different features, all while never breaking the core functionality
  • It allows people to collaborate on code

We're doing the same thing with homework, and specifically for this first homework, our "code" is just a file called blog.txt. To actually upload the homework, you'll want to follow these steps:

upstream app {
# Path to Unicorn SOCK file, as defined previously
server unix:/tmp/unicorn.babblings.sock fail_timeout=0;
}
server {
listen 80;
server_name ror-study-group-3;
# Application root, as defined previously
require 'rest-client'
require 'json'
require 'pry'
endpoint_url = 'http://www.reddit.com/r/all.json'
response = RestClient.get(endpoint_url)
parsed_response = JSON.parse(response)
posts = parsed_response["data"]["children"].each_with_object([]) do |post, array|
array << {
require 'pry'
class MySet
attr_accessor :objects
def initialize
@objects = []
end
def count
class Fixnum
def sam_prime?
return false if self == 1
2.upto(Math.sqrt(self).to_i) { |n| return false if self % n == 0 }
return true
end
def refactored_prime?
2.upto(Math.sqrt(self).to_i) { |n| return false if self % n == 0 }
self == 1 ? false : true
@bswinnerton
bswinnerton / array.rb
Last active January 2, 2016 06:39
Matrix Challenge
class Array
def spiral
array = []
array << self.shift
array << self.transpose.reverse.spiral unless self.empty?
array.flatten
end
end
require 'rspec'
describe 'fib(n)' do
it 'calculates a fibonacci number based on index' do
expect(fib(6)).to eq(8)
end
end
def fib(n)