Skip to content

Instantly share code, notes, and snippets.

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
@carolineartz
carolineartz / SOLO_CHALLENGE:_Modeling_a_One_to_Many_Database_queries.sql
Last active August 29, 2015 13:56
Solution for SOLO CHALLENGE: Modeling a One to Many Database
-- 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);
@carolineartz
carolineartz / Database_Drills:_Designing_Schemas_solution.md
Last active August 29, 2015 13:56
Solution for Database Drills: Designing Schemas

Solution for Challenge: Database Drills: Designing Schemas. Started 2014-02-11T00:25:27+00:00

###Database Schema Diagrams student roster
student roster

One to many
one to many schema

# REVIEWING ASSERT STATEMENT
# ---------
def assert
raise "Assertion failed!" unless yield
end
name = "bettysue"
assert { name == "bettysue" }
assert { name == "billybob" }
@carolineartz
carolineartz / 1_ruby_quicksort.rb
Last active August 29, 2015 13:56
Here are some things you can do with Gists in GistBox.
class QuickSort
def self.sort!(keys)
quick(keys,0,keys.size-1)
end
private
def self.quick(keys, left, right)
if left < right
@carolineartz
carolineartz / method1_array#transpose.md
Last active August 29, 2015 13:56
Solution for Drill: Researching Array Methods

Solution for Challenge: Drill: Researching Array Methods. Started 2014-02-12T03:13:11+00:00

METHOD 1: Array#transpose

Array#transpose transposes an array matrix--that is, it flips the rows to columns and columns to rows.

Our boggle board challenge presents a good example for showcasing this method.

@carolineartz
carolineartz / Create_A_Car_Class_from_User_Stories_solution.rb
Last active August 29, 2015 13:56
Solution for Create A Car Class from User Stories
# 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
# ---------------------
@carolineartz
carolineartz / 0.3.2-refactoring_for_readability.rb
Last active August 29, 2015 13:56 — forked from dbc-challenges/0.3.2-readable_code_original_gist.rb
As a programmer, you should always strive to make your code as readable as possible. In this challenge, we'll focus on the hallmarks of good readable code and refactor a previous challenge using some guidelines.
# 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
<!-- 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
#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',