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 insertion_sort(array) | |
| sorted = false | |
| while sorted == false | |
| array.each_index do |i| | |
| next if i == 0 | |
| a = array[i] | |
| b = array[i - 1] | |
| if a < b | |
| sorted = false |
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
| if [ -s $@ ] | |
| then | |
| echo | |
| echo "Let's test to make sure you have all the software you need!" | |
| echo "You can pass this file as many items of software as you want" | |
| echo "to check, like so:" | |
| echo | |
| echo " ./software_tester ruby git sqlite3" | |
| echo | |
| echo "You should first try it out with the following items, because" |
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 bubble_sort(array) | |
| sorted = false | |
| while sorted == false | |
| array.each_index do |i| | |
| a = array[i] | |
| b = array[i + 1] | |
| if b == nil | |
| sorted = true | |
| break |
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 Adventure | |
| attr_reader :user, :gender | |
| def initialize(name) | |
| @user = name | |
| @gender = set_gender | |
| end | |
| def set_gender | |
| print "Art thou a she, a he, or sommat else? (she, he, else) " |
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 shorten_url(message) | |
| puts "Shortening links..." | |
| urls = Hash.new(0) | |
| url = message.split.select{|item| item.include?("http") || item.include?("www")} | |
| text = message.split.select{|item| !url.include?(item)}.join(" ") | |
| url.each do |item| | |
| url_index = message.split.index(item) |
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 'jumpstart_auth' | |
| require 'bitly' | |
| class MicroBlogger | |
| attr_reader :client | |
| def initialize | |
| @client = JumpstartAuth.twitter | |
| 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
| if __FILE__ == $PROGRAM_NAME | |
| blogger = MicroBlogger.new | |
| puts "\nWelcome to the JSL Twitter client!" | |
| puts "Available commands:" | |
| puts " q => quit" | |
| puts " dm => direct message " | |
| puts " t => tweet" | |
| puts " g => see all the latest tweets from friends\n\n" | |
| command = "" | |
| commands = {"dm" => "route_dm", "t"=>"tweet", "q"=>"quit", |
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 ToDoList | |
| attr_reader :list | |
| def initialize | |
| @list = [] | |
| end | |
| def get_the_items | |
| puts "Your to-do list!" | |
| puts "Enter each item. When you've put in your last item," |
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 ThoughtCounter | |
| attr_reader :thoughts | |
| def initialize | |
| @thoughts = {} | |
| end | |
| def translate_time(seconds) | |
| return "#{seconds} seconds" if seconds < 60 | |
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 quick_sort(array, pivot=-1) | |
| if array.empty? || array.length == 1 | |
| return array | |
| end | |
| slice_left = [] | |
| slice_right = [] | |
| pivot_slices = [] | |
| array.each_index do |j| |