Skip to content

Instantly share code, notes, and snippets.

View zacclark's full-sized avatar

Zac Clark zacclark

View GitHub Profile
select
count(case when photos.created_at < trips.start_date then distinct(photos.id) end) as before,
count(case when photos.created_at >= trips.start_date and photos.created_at < trips.end_date then distinct(photos.id) end) as during,
count(case when photos.created_at >= trips.end_date then distinct(photos.id) end) as after
from trips
inner join trip_segments
on trip_segments.trip_id = trips.id
inner join trip_segment_photos
on trip_segment_photos.trip_segment_id = trip_segments.id
inner join photos
<% @person.current_employments.each do |emp| %>
<% f.fields_for :employments, emp do |em| %>
<%= em.hidden_field :id %>
<% em.fields_for :company, emp.company do |co| %>
<%= co.hidden_field :id %>
<% co.fields_for :special_dataset do |cd| %>
<%= cd.hidden_field :id %>
<% em.fields_for :postal_address do |pa| %>
<% em.fields_for :assistant, emp.assistant do |ast| %>

OO Analysis & Design, Homework #1, Zachary Clark (810876200)

Problem 1.

What is the difference between abstraction and encapsulation? Define both terms and then discuss the difference. Provide examples to support your definitions and discussion.

Encapsulation hides data, sealing it away from external use. This helps with loose coupling. It prevents data from "bleeding" from one part of the application into others, or being accessible in places it should not.

Abstraction defines what features a class provides and what services it can perform. Abstractions hide away how the code functions, so the programmer is only concerned with the results. If abstractions are used properly, the entire foundational data structure can be changed without affecting code relying on that class.

stacking_search = params[:search_modifier]
if stacking_search
original = session[:last_query]
fresh = query
join = "AND"
join = "OR" if params[:search_modifier] == "expand"
query = ["( #{original.shift} ) #{join} ( #{fresh.shift} )"] + (original + fresh)
# this is a useful spot for a debugger if we need to inspect the joined query
# debugger
end
@zacclark
zacclark / strategy.rb
Created March 30, 2011 03:31
A basic strategy pattern example in Ruby.
class Duck
def initialize(name = "Ducky")
set_quack
@name = name
end
def quack
@quack_behavior.quack
end
@zacclark
zacclark / xls.rb
Created March 30, 2011 04:12
Simple export to xls from Ruby.
# http://spreadsheet.rubyforge.org/file.GUIDE.html
require 'rubygems'
require 'spreadsheet'
book = Spreadsheet::Workbook.new
sheet1 = book.create_worksheet
sheet1.name = 'Testing Naming'
@zacclark
zacclark / weather.rb
Created April 10, 2011 21:56
An old attempt at getting todays weather data from Wunderground.
require "rexml/document"
# http://api.wunderground.com/auto/wui/geo/ForecastXML/index.xml?query=Boulder,CO
require 'net/http'
Net::HTTP.start("api.wunderground.com") do |http|
resp = http.get("/auto/wui/geo/ForecastXML/index.xml?query=Boulder,CO")
open("weather.xml", "wb") do |file|
file.write(resp.body)
end
@zacclark
zacclark / flat_person.rb
Created April 12, 2011 03:00
First attempt at a simplified middleground record for exporting.
class FlatPerson
def initialize(person)
raise TypeMismatch unless person.class == Person
person.attribute_names.each do |attr|
eval("@#{attr} = person.#{attr}")
end
end
class FlatPerson
def initialize(person)
raise TypeMismatch unless person.class == Person
emp = person.employments_to_edit[0] || Employment.new
emp.company ||= Company.new
comp = emp.company
comp.cisco_dataset ||= CiscoDataset.new
cd = comp.cisco_dataset
f = File.open("./theme")
waiting = true
f.each_line do |line|
if waiting
#puts line
waiting = false if line.to_s == "[default]\r\n"
else
arr = line.split(" ")
#puts arr.inspect
puts "<key>#{arr[0]}</key>"