Skip to content

Instantly share code, notes, and snippets.

View Pcushing's full-sized avatar

Patrick Cushing Pcushing

View GitHub Profile
@Pcushing
Pcushing / NumbersInWords.rb
Created June 12, 2012 22:53
Jacquie & Patrick tackle Numbers in Words
module InWords
def in_words
num_digits = self.to_s.length
num_string = self.to_s
under_ten = { 0 => "zero", 1 => "one", 2 => "two", 3 => "three",
4 => "four", 5 => "five", 6 => "six",
7 => "seven", 8 => "eight", 9 => "nine" }
teens = { 10 => "ten", 11 => "eleven", 12 => "twelve", 13 => "thirteen",
14 => "fourteen", 15 => "fifteen", 16 => "sixteen",
@Pcushing
Pcushing / JavascriptPlay.html
Created June 13, 2012 00:09
Javascript play with Matt Nguyen
<!DOCTYPE html>
<html>
<head>
<title></title>
<script type="text/javascript">
var message = {
user: "bob",
text: "aldfkja"
};
@Pcushing
Pcushing / PigLatin.rb
Created June 13, 2012 19:31
Pig Latin with Two Methods
def translate(word)
start_point = vowels_start(word)
end_point = word.length - 1
if start_point == 0
word + "ay"
else
word[start_point, end_point] + word[0, start_point] + "ay"
end
end
@Pcushing
Pcushing / numbers_in_words_recursion.rb
Created June 14, 2012 02:29
Numbers in Words with recursion up to 1 trillion
class Fixnum
def in_words
ten = 10
hundred = 100
thousand = 1_000
million = 1_000_000
billion = 1_000_000_000
trillion = 1_000_000_000_000
@Pcushing
Pcushing / DictionaryClass.rb
Created June 15, 2012 00:31
Andrew & Patrick tackle the Dictionary (class)
class Dictionary
def initialize
@my_hash = {}
end
def add(word_hash)
if word_hash.is_a?Hash
@my_hash.merge!(word_hash)
else
@my_hash[word_hash] = nil
@Pcushing
Pcushing / book_class.rb
Created June 15, 2012 00:54
Andrew and Patrick crushing it on books
class Book
attr_accessor :title
def initialize
@title = ""
end
def title=(name)
arr = name.split
no_caps = ["the", "an", "a", "and", "in"]
@Pcushing
Pcushing / RPNCalculator.rb
Created June 15, 2012 03:25
RPNCalculator with Andrew... crushing it
class RPNCalculator
def initialize
@rpn = []
end
def push(num)
@rpn << num
end
@Pcushing
Pcushing / redefining_count.rb
Created June 16, 2012 00:09
Redefining count, but there's got to be a better way...
class Array
def new_count
count = 0
(1..self.length).each do |i|
count += 1 if yield(self[i-1])
end
count
end
end
@Pcushing
Pcushing / TwitterFollower.rb
Created June 18, 2012 06:51
Login to Twitter, follow a single user and print all twitter client methods for future reference
require 'rubygems'
require 'oauth'
require 'twitter'
consumer_key = 'HIDDEN'
consumer_secret = 'HIDDEN'
@consumer = OAuth::Consumer.new(
consumer_key,
consumer_secret,
@Pcushing
Pcushing / gist:2950678
Created June 18, 2012 21:02
Delete soon
# Create a Red Sox class that represents the starting line-up of the Red Sox in a recent game. The line-up at the start of the game, 1 through 9, is given below with the pitcher indicated at 0 as he doesn't bat (sorry, NL fans):
#
# * 1, Aviles, SS
# * 2, Pedroia, 2B
# * 3, Youkilis, 1B
# * 4, Ortiz, DH
# * 5, Middlebrooks, 3B
# * 6, Gonzalez, OF
# * 7, Saltalamacchia, C
# * 8, McDonald, OF