Skip to content

Instantly share code, notes, and snippets.

@huezoaa
huezoaa / my_api.rb
Created Jan 30, 2015
Spell Check API
View my_api.rb
require 'httparty'
require 'json'
puts "Please enter the word to spell-check:"
##### Get word to spell check from the user
word = gets.chomp
address = "https://montanaflynn-spellcheck.p.mashape.com/check/?text=" + word
View curl_ruby.rb
require 'httparty'
# puts ARGV
# p ARGV
#### Hint: When you pass arguments to Ruby through the Command Line,
#### they get set into a Constant Array variable named ARGV.
case ARGV[0]
when "GET"
View stock_ticker_bonus.rb
require 'HTTParty'
require 'json'
require 'nokogiri'
### Obtain stock symbol:
puts "Please enter your Stock Symbol:"
stock_symbol = gets.chomp
address = "http://finance.yahoo.com/q?s=" + stock_symbol
# puts address
View stock_ticker.rb
require 'HTTParty'
require 'json'
require 'nokogiri'
### run a GET from Yahoo with HTTParty for Apple Stock, assign to response
response = HTTParty.get('http://finance.yahoo.com/q?s=AAPL')
### take response body and use Nokogiri to parse the HTML into a Ruby variable
ticker = Nokogiri::HTML(response.body)
View votersim_classes.rb
# Super Class Voter.
# Class variables:
#
module VoterSimClasses
class Voter
attr_accessor :name, :id, :type
def initialize
@huezoaa
huezoaa / votersim_main.rb
Created Jan 26, 2015
voter simulation main
View votersim_main.rb
require "./votersim_classes.rb"
include VoterSimClasses
def greet_and_choose
puts "\n\n\n\n\n\n\n\n\n\n"
puts "What would you like to do????"
puts "Create, List, Update, Vote, or Exit"
gets.chomp.downcase
end
@huezoaa
huezoaa / christmas_tree_class.rb
Last active Aug 29, 2015
Christmas Tree w/ Class
View christmas_tree_class.rb
# Dislays the specified character in the shape of a
# Christmas tree.
# Wyncode bootcamp. Ruby Classes and OOP
# Arguments for Christmas tree:
# size = number of lines (Fixnum)
# character = string character to use (String)
class ChristmasTree
def initialize(size=3, character="X")
@huezoaa
huezoaa / ah_lecture_notes.rb
Last active Sep 22, 2015
ah_lecture_notes_01-20-2015
View ah_lecture_notes.rb
require 'csv'
class ConfPanel < ActiveRecord::Base
validates :code, presence: true
validates :name, presence: true
def self.import_from_csv(csv_file)
ConfPanel.transaction do
ConfPanel.destroy_all
# Parse CSV content
View game_mo_memory.rb
mo = [] #The computer's sequence of lights.
#Does not clear through execution
your_entry = [] #The player's sequence of lights. Clears on every loop
level = 0 #Counter that increases with every loop.
#used to display level and add new index to mo array.
while mo == your_entry # Will run until player makes a mistake
print "\033c" # This clears the screen!
View max_refactor.rb
def max(num1, num2, *num)
num1 > num2 ? num1 : num2
end
def test # Assume all entries are numeric
p max(1,9,3,5,99,23,115,32,922,3983,38374,28474,10937134) == 9
p max(1,2) == 2 # (Fixnum, Fixnum)
p max(2,1) == 2 # (Fixnum, Fixnum)
p max(0.1, 0.2) == 0.2 # (Float, Float)
p max(0.2, 0.1) == 0.2 # (Float, Float)