Skip to content

Instantly share code, notes, and snippets.

@jessieay
jessieay / RPN FTW
Created June 17, 2012 17:23
RPN that passes rspec
class RPNCalculator
attr_accessor :calculator, :result, :subtotal, :mini_array
def initialize
@calculator = []
@mini_array = []
@result = 0
@subtotal = 0
end
@jessieay
jessieay / New Collect
Created June 18, 2012 01:07
Practicing procs, still not sure why this works
class Array
def new_collect
self.collect do |n|
yield n
end
end
end
RSPEC:
@jessieay
jessieay / New-inject
Created June 18, 2012 22:17
Redefinition of inject
class Array
def new_inject
result = 0
(1..self.length).each do |i|
result = yield(result, self[i-1])
end
result
@jessieay
jessieay / RPS contest
Created June 19, 2012 00:23
Tournament of RPS contest
def game(match)
if match[0][1].upcase =="R"
if match[1][1].upcase == "P"
match[1]
elsif match[1][1].upcase == "S"
match[0]
else
"It's a Tie!"
end
@jessieay
jessieay / Event Manager
Created June 20, 2012 23:55
Event manager ruby project created in week 2 at DBC
# Dependencies
require "csv"
require 'sunlight'
# Class Definition
class EventManager
INVALID_ZIPCODE = "00000"
INVALID_PHONE_NUMBER = "0000000000"
Sunlight::Base.api_key = "e179a6973728c4dd3fb1204283aaccb5"
def initialize(filename)
@jessieay
jessieay / Array#collect rewrite
Created June 25, 2012 19:57
Redefinition of array.collect
class Array
def new_collect
result = []
self.each do |index|
result << yield(index)
end
result
end
@jessieay
jessieay / Sudoku v1, incomplete
Created June 26, 2012 16:53
Sudoku solver with everything but final solve method working
class Board
def initialize(board_input)
@board_array = []
board_input.split(//).each_with_index do |cell, index|
@board_array << Cell.new(cell, index)
end
end
def find_box(cell_id)
@jessieay
jessieay / Madlibs funtimes
Created June 28, 2012 04:15
Madlibs funtimes!
puts "Welcome to console mad libs! First you'll enter 21 words, then you'll get a fun story, made by you!"
puts
goodAnswer = false
while (not goodAnswer)
puts "Are you ready to play? Type in 'yes' to begin."
ready = gets.chomp.downcase
if (ready == 'yes')
goodAnswer = true
else
@jessieay
jessieay / First Twilio app
Created June 29, 2012 04:21
sends text messages using twilio gem
require 'twilio-ruby'
class Texter
def initialize
@account_sid = 'xxx'
@auth_token = 'xxx'
@client = Twilio::REST::Client.new(@account_sid, @auth_token)
@from = 'xxx'
end
@jessieay
jessieay / gist:3042429
Created July 3, 2012 19:44
ex university- DB
<?xml version="1.0" encoding="utf-8" ?>
<!-- SQL XML created by WWW SQL Designer, http://code.google.com/p/wwwsqldesigner/ -->
<!-- Active URL: http://socrates.devbootcamp.com/sql.html -->
<sql>
<datatypes db="mysql">
<group label="Numeric" color="rgb(238,238,170)">
<type label="Integer" length="0" sql="INTEGER" re="INT" quote=""/>
<type label="Decimal" length="1" sql="DECIMAL" re="DEC" quote=""/>
<type label="Single precision" length="0" sql="FLOAT" quote=""/>
<type label="Double precision" length="0" sql="DOUBLE" re="DOUBLE" quote=""/>