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
# Solution for Challenge: P6. OO Terminology. Started 2013-07-11T03:30:13+00:00 | |
class Bicycle | |
attr_reader :color, :gears, :move, :brake, :wheels | |
def initialize(args={}) | |
@color = args[:color] || "silver" | |
@gears = args[:gears] || "single" | |
@wheels = 2 | |
@move = false | |
@brake = 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
class Cohort < Database::Model | |
self.attribute_names = [:id, :name, :created_at, :updated_at] | |
attr_reader :attributes, :old_attributes | |
# e.g., Cohort.new(:id => 1, :name => 'Alpha', :created_at => '2012-12-01 05:54:30') | |
def initialize(attributes = {}) | |
attributes.symbolize_keys! |
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 Cohort < Database::Model | |
# def self.all | |
# Database::Model.execute("SELECT * FROM cohorts").map do |row| | |
# Cohort.new(row) | |
# end | |
# end | |
def self.create(attributes) | |
record = self.new(attributes) | |
record.save |
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 'csv' | |
require 'sqlite3' | |
class PoliticianDB | |
@@politicians_stats =[] | |
def self.setup | |
system('rm politicians.db') | |
$db = SQLite3::Database.new "politicians.db" |
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
# Solution for Challenge: DB Drill: Address Book Schema. Started 2013-07-09T21:32:24+00:00 | |
http://min.us/l0GieGZ7cxACS | |
<?xml version="1.0" encoding="utf-8" ?> | |
<!-- SQL XML created by WWW SQL Designer, http://code.google.com/p/wwwsqldesigner/ --> | |
<!-- Active URL: http://socrates.devbootcamp.com/sql.html --> | |
<sql> | |
<datatypes db="mysql"> | |
<group label="Numeric" color="rgb(238,238,170)"> | |
<type label="Integer" length="0" sql="INTEGER" re="INT" quote=""/> |
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
# Solution for Challenge: University Course Database Design. Started 2013-07-09T21:19:57+00:00 | |
http://min.us/lbpNuNnFYBkAQJ | |
<?xml version="1.0" encoding="utf-8" ?> | |
<!-- SQL XML created by WWW SQL Designer, http://code.google.com/p/wwwsqldesigner/ --> | |
<!-- Active URL: http://socrates.devbootcamp.com/sql.html --> | |
<sql> | |
<datatypes db="mysql"> | |
<group label="Numeric" color="rgb(238,238,170)"> | |
<type label="Integer" length="0" sql="INTEGER" re="INT" quote=""/> |
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
# Solution for Challenge: Student Roster DB from Schema. Started 2013-07-09T19:29:26+00:00 | |
require 'sqlite3' | |
# If you want to overwrite your database you will need | |
# to delete it before running this file | |
$db = SQLite3::Database.new "students.db" | |
module StudentDB | |
def self.setup | |
$db.execute( |
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
# Solution for Challenge: Poll DB 1: Queries. Started 2013-07-08T21:40:24+00:00 | |
SELECT * FROM congress_members; | |
SELECT sql FROM (SELECT sql sql, type type, tbl_name tbl_name, name name, rowid x FROM sqlite_master UNION ALL SELECT sql, type, tbl_name, name, rowid FROM sqlite_temp_master) WHERE type!='meta' AND sql NOTNULL AND name NOT LIKE 'sqlite_%'ORDER BY substr(type,2,1), CASE type WHEN 'view' THEN rowid ELSE name END | |
SELECT * FROM congress_members | |
WHERE id='524'; | |
SELECT * FROM votes | |
WHERE politician_id = '524'; | |
SELECT count(id) FROM votes |
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 'csv' | |
class Recipe | |
attr_reader :id, :name, :description, :ingredients, :directions | |
def initialize(data={}) | |
@id = data[:id] | |
@name = data[:name] | |
@description = data[:description] |
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
#Solution for Challenge: Scraping HN 1: Building Objects. Started 2013-07-03T22:33:29+00:00 | |
require 'nokogiri' | |
require 'pry' | |
class Post | |
attr_accessor :title, :url, :points, :comments_array #, :item_id | |
def initialize(args) | |
@title = args[:title] | |
@url = args[:url] |
NewerOlder