Skip to content

Instantly share code, notes, and snippets.

View xander-miller's full-sized avatar

Xander Miller xander-miller

View GitHub Profile
def add_two(array)
array.map { |item| "#{item} + 2 = #{ item+2 }" }
end
def merge_us(hash1, hash2)
hash1.merge(hash2)
end
def my_keys(hash)
hash.keys
end
def do_i_have?(h ={},keys)
h.keys.sort == keys.sort
class Title
attr_reader :string
def initialize(string)
@string = string
end
def fix
# A neat Ruby trick for making an array of strings
# Equivalent to: ['a', 'and', 'the', 'of']
def add_item!(item, list)
list << item unless list.include?(item)
list
end
def remove_item!(item, list)
list.delete(item)
list
end
@xander-miller
xander-miller / 1loopy.rb
Last active August 29, 2015 14:08
1loopy.rb
class ArrayModifier
attr_reader :array
def initialize(array)
@array = array
end
def exclaim
new_array = []
class President
attr_accessor :name, :age
def initialize(name, age)
@name, @age = name, age
end
def citizenship
self.class.citizenship
end
class ArrayModifier
attr_reader :array
def initialize(array)
@array = array
end
def exclaim
new_array = []
@xander-miller
xander-miller / sublime_setup.sh
Last active August 29, 2015 14:07
Setup Sublime Text 2 to work from the command line in OSX
mkdir ~/bin
touch ~/.bash_profile
echo 'export PATH="~/bin:$PATH"' >> ~/.bash_profile
echo "export EDITOR='subl -w'" >> ~/.bash_profile
ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" ~/bin/subl
source ~/.bash_profile
def save_with_initial_vote
ActiveRecord::Base.transaction do
saved = self.save
self.create_vote
saved
end
end
@xander-miller
xander-miller / guessing_game_after_solution.py
Last active August 29, 2015 14:06
I know this is very basic, but I'm super proud of my first python program in 5 years.
import random
def show_guesses():
guesses.append(guess)
print(str(guesses) + " {} more out of 5.".format(5 - len(guesses)))
def show_help():
print("Guess a number between '1' and '10'")
print("'DONE' quits and 'HELP' displays this help.")