This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Clean a previous install | |
| brew uninstall postgre | |
| rm -rf /usr/local/var/postgres/ | |
| # Install the database with brew package manager | |
| brew install postgres | |
| brew info postgresql | |
| # Initialize the database | |
| initdb /usr/local/var/postgres |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Card | |
| def initialize(term, definition) | |
| @term = term | |
| @definition = definition.chomp | |
| end | |
| attr_reader :term, :definition | |
| def to_s | |
| "Term: '#{term}', Definition: '#{definition}'" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class CsvIO | |
| def self.read_from_file(filename, class_type, storage_location) | |
| File.open(filename) do |f| | |
| f.each_line do |line| | |
| params = line.split(',') | |
| storage_location << Kernel.const_get(class_type).send(:new, *params) | |
| end | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def binary_search(obj, sorted_arr, search_index=0) | |
| arr_length = sorted_arr.length | |
| if sorted_arr[arr_length/2] == obj | |
| arr_length/2 + search_index | |
| elsif sorted_arr[arr_length/2] > obj | |
| binary_search(obj, sorted_arr[0..arr_length/2-1], search_index) | |
| else | |
| binary_search(obj, sorted_arr[arr_length/2+1..-1], search_index + arr_length/2+1) | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'benchmark' | |
| require_relative "linear_search" | |
| require_relative 'binary_search' | |
| one_thousand = (1..1000).to_a | |
| ten_thousand = (1..10_000).to_a | |
| one_million = (1..1_000_000).to_a | |
| test_cases = {1000 => one_thousand, 10000 => ten_thousand, 1000000 => one_million} | |
| test_cases.each do |int, test_array| |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Put your answers here! | |
| rvm rubies | |
| ruby-1.8.7-p370 [ i686 ] | |
| ruby-1.9.3-p125 [ x86_64 ] | |
| =* ruby-1.9.3-p194 [ x86_64 ] | |
| # => - current | |
| # =* - current && default | |
| # * - default |
NewerOlder