Skip to content

Instantly share code, notes, and snippets.

View colemanfoley's full-sized avatar

Coleman Foley colemanfoley

View GitHub Profile
@colemanfoley
colemanfoley / gist:3725822
Created September 15, 2012 00:37
Dictionary class
class Dictionary
attr_accessor :entries
attr_accessor :keywords
def initialize
@entries = Hash.new
end
def add(entry)
if entry.is_a? Hash
@colemanfoley
colemanfoley / Pig Latin
Created September 17, 2012 02:31
Translates English word to Pig Latin
#The main method, it takes a string that is an English word and returns that word in Pig Latin.
#All words have "ay" appended to them in the line just before the return statement. If the word
#begins with a vowel, it is sent to the << "ay" line unmodified.
#If it is exactly three letters long, the second two characters of english_word are made the first
#two of pig_latin_word, then the first letter of english_word is made the third character of
#pig_latin_word. Then the word is ready to get the << "ay" treatment.
def translate(english_word)
if is_vowel?(english_word[0])
pig_latin_word = english_word
@colemanfoley
colemanfoley / gist:3747574
Created September 19, 2012 03:48
Pig Latin translator
#The main method, it takes a string that is an English word and returns that word in Pig Latin.
#All words have "ay" appended to them in the line just before the return statement. If the word
#begins with a vowel, it is sent to the << "ay" line unmodified.
#If it is exactly three letters long, the second two characters of english_word are made the first
#two of pig_latin_word, then the first letter of english_word is made the third character of
#pig_latin_word. Then the word is ready to get the << "ay" treatment.
def translate(english_word)
if is_vowel?(english_word[0])
pig_latin_word = english_word
@colemanfoley
colemanfoley / gist:3747578
Created September 19, 2012 03:50
Numbers into Words
module InWords
#The method for turning integers 1-19 into the appropriate strings.
def under20
array_small_numbers = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"]
return array_small_numbers[self]
end
#The method for turning integers 20-99 into the appropriate strings.
def under100
@colemanfoley
colemanfoley / Book class.rb
Created September 20, 2012 22:09
Book class
class Book
attr_accessor :title
def initialize
@title = ""
end
def title=(new_title)
fixed_title = ""
title_array = new_title.split
title_array.each do |word|
@colemanfoley
colemanfoley / gist:3783235
Created September 25, 2012 17:17
Numbers into Words recursively
module InWords
#The method for turning integers 1-19 into the appropriate strings.
def under20
array_under20 = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"]
return array_under20[self]
end
#The method for turning integers 20-99 into the appropriate strings.
def under100
@colemanfoley
colemanfoley / gist:3836436
Created October 4, 2012 21:02
Print grid method
def print_grid(x = 5, y =5)
row_0 = "00000"
row_1 = "00000"
row_2 = "00000"
row_3 = "00000"
row_4 = "00000"
if y == 0
row_0[x] = "X"
@colemanfoley
colemanfoley / gist:3856313
Created October 9, 2012 02:57
Shape classes
class Shape
def get_color
return color
end
def set_color(color)
@color = color
end
def can_fit?(shape)
@colemanfoley
colemanfoley / gist:4029325
Created November 7, 2012 02:55
Weather app
#!/usr/bin/env ruby
require 'open-uri'
require 'json'
raw = open('http://api.wunderground.com/api/59431618fd2e7dae/geolookup/conditions/q/CA/Yuba_City.json').read
processed = JSON.parse(raw)
yuba_city = processed['current_observation']
puts "Yuba City is " + yuba_city['feelslike_string']
@colemanfoley
colemanfoley / gist:5218525
Created March 22, 2013 02:34
jitsu deploy error output
info: Welcome to Nodejitsu coleman
info: jitsu v0.12.8, node v0.8.21
info: It worked if it ends with Nodejitsu ok
info: Executing command deploy
info: Analyzing application dependencies in node server.js
warn: Local package version appears to be old
warn: The package.json version will be incremented automatically
warn: About to write /Users/colemanfoley/code/playlist-me/public/playlist-me-helper/package.json
data:
data: {