Skip to content

Instantly share code, notes, and snippets.

@maxplomer
maxplomer / homework_solutions
Last active August 29, 2015 14:04
App academy learn_ruby homework solutions
#############################
#hello.rb
def hello
"Hello!"
end
def greet name
"Hello, " + name + "!"
end
@maxplomer
maxplomer / homework_uploader.rb
Last active August 29, 2015 14:04
This code combines many ruby files into one document, then uploads to your github account as a public gist
#Author: Max Plomer, maxplomer@gmail.com
#About the code: This code combines many ruby files into one document, does some formatting (such as: prints each file name, removing whitespace at bottom of each file), it either removes or keeps comments. Then uploads to your github account as a public gist. Also a file called combined.rb is created in the folder that is same file uploaded to gist. The public gist is opened in your web browser. Installation of the gist gem is necessary using command: $ gem install gist
#About the input.txt file: This code uses an input file input.txt in the same directory, with first line containing the gist name, 2nd line whether or not you want comments, and the rest of the lines are the paths of the ruby files you want to combine relative to the location of this code (or just write out the entire path)
######sample input.txt file#######
#gist_name: homework_solutions
#keep_comments: false
#learn_ruby/00_hello/hello.rb
@maxplomer
maxplomer / options_choices_list.rb
Last active August 29, 2015 14:04
options choices list - generate all the possible combinations of a given number of choices and options to choose from
def binarylist(choices)
list = Array.new(2**choices)
(2**choices).times do |x|
list[x]=[]
choices.times do |y|
if (x & 2**y)!=0
list[x] << 1
else
list[x] << 0
@maxplomer
maxplomer / marbles.rb
Last active August 29, 2015 14:05
how many combinations of n marbles of k colors?
def marbles(n, k)
free = n - k
if free == 0
return 1
end
combos = Array.new(k,1)
(free-1).times do
(k-1).downto(1) do |x|
combos[x] = combos[0..x].inject(:+)
end
@maxplomer
maxplomer / euler23.rb
Last active August 29, 2015 14:05
find the sum of all the positive integers which cannot be written as the sum of two abundant numbers
class Integer
def isabundant?
sum_of_proper_divisors(self) > self
end
end
def sum_of_proper_divisors(num) #borrowed from github user mlsimpson
orig = num
@maxplomer
maxplomer / proc_block.txt
Created September 10, 2014 22:18
proc block practice
[1] pry(main)> x = Proc.new {|i| puts i}
=> #<Proc:0x007fa46aa60188@(pry):1>
[2] pry(main)> [1,2,3].map(&x)
1
2
3
=> [nil, nil, nil]
@maxplomer
maxplomer / rails_tutorial_git
Last active August 29, 2015 14:06
git notes from rails tutorial
####### install Git ##########
Use install Git section of Pro Git
can install from graphical Git installer or Macports
http://sourceforge.net/projects/git-osx-installer/
Note: I'm fine with my Git version
@maxplomer
maxplomer / sum_of_pairs.rb
Created September 14, 2014 23:00
sum of pairs
def sum_of_pairs(arr)
max_length = 0 #max length of subset
#go through all subsets
for i in 0..(arr.size - 2)
for j in (i + 1)..(arr.size - 1)
sub_arr = arr[i..j]
sub_arr_length = sub_arr.length
if is_good?(sub_arr)
max_length = sub_arr_length if sub_arr_length > max_length
@maxplomer
maxplomer / argv_test.rb
Created September 15, 2014 20:41
need to use shift to get args from argv otherwise will mess up gets
def argv_test
filename = ARGV.shift
game_save = File.readlines(filename)
p game_save
x = gets.chomp
p x
end
argv_test
@maxplomer
maxplomer / business.rb
Created September 16, 2014 21:59
employee manager classes problem
class Employee
attr_accessor :name, :title, :salary, :boss
def initialize
@name
@title
@salary
@boss
end