Solution for Challenge: Database Drills: Designing Schemas. Started 2014-02-11T00:25:27+00:00
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 'sqlite3' | |
| $db = SQLite3::Database.open 'congress_poll_results.db' | |
| def print_arizona_reps | |
| puts 'AZ REPRESENTATIVES' | |
| az_reps = $db.execute("SELECT name FROM congress_members WHERE location = 'AZ'") | |
| az_reps.each { |rep| puts rep } | |
| 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
| -- all the tweets for a certain user id | |
| SELECT tweet_id, tweet_text | |
| FROM tweets | |
| WHERE user_id = 123456678923402; | |
| -- the tweets for a certain user id that were made after last Wednesday | |
| SELECT tweet_id, tweet_text | |
| FROM tweets | |
| WHERE created_at >= date('2014-02-07') AND | |
| (user_id = 123456678923402); |
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
| # REVIEWING ASSERT STATEMENT | |
| # --------- | |
| def assert | |
| raise "Assertion failed!" unless yield | |
| end | |
| name = "bettysue" | |
| assert { name == "bettysue" } | |
| assert { name == "billybob" } |
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 QuickSort | |
| def self.sort!(keys) | |
| quick(keys,0,keys.size-1) | |
| end | |
| private | |
| def self.quick(keys, left, right) | |
| if left < right |
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
| # CREATE A CAR CLASS FROM USER STORIES | |
| # -------------------------------- | |
| # Caroline Artz | |
| # 2/15/2014 | |
| # Contents: class Car, class Pizza, class Trip, driver code, relfection | |
| # Class #1 - class Car | |
| # --------------------- |
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
| # Readable Code Refactoring Challenge | |
| # ----------------------------------- | |
| # Goals of readable code | |
| # 1. Elimination of repetition, using looping and branching wisely | |
| # 2. Complex operations are decomposed into constituent parts | |
| # 3. Descriptive names for methods, variables, classes, and modules | |
| # 4. Methods are small and behavior is obvious | |
| # 5. Minimizes need for comments because the code tells you what it is doing | |
| # 6. Code is formatted with proper indentation for optimal readability |
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
| <!-- Move into the repo directory --> | |
| $ cd workspace/CLI-Obstacle-Course/ | |
| Caroline-iMac@Carolines-iMac(1.41) 8:57:20pm ~/workspace/CLI-Obstacle-Course | |
| <!-- View the directories and files that are created--> | |
| $ ls | |
| Gemfile config lib | |
| Gemfile.lock config.ru log | |
| README.rdoc db public | |
| Rakefile delete_me script |
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
| #in_words(821_713) # => "eight hundred twenty one thousand seven hundred thirteen" | |
| #in_words(34_567_893) # => "thirty four million five hundred sixty seven thousand eight hundred ninety three" | |
| # pseudocode | |
| # | |
| class NumbersWords | |
| WORD_LOOKUP = {1 => 'one', 2 => 'two', 3 => 'three', 4 => 'four', 5 => 'five', 6 => 'six', 7 => 'seven', | |
| 8 => 'eight', 9 => 'nine', 10 => 'ten', 11 => 'eleven', 12 => 'twelve', 13 => 'thirteen', | |
| 14 => 'fourteen', 15 => 'fifteen', 16 => 'sixteen', 17 => 'seventeen', 18 => 'eighteen', | |
| 19 => 'nineteen', 20 => 'twenty', 30 => 'thirty', 40 => 'forty', 50 => 'fifty', 60 => 'sixty', |