This file contains 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 Array | |
def extract_options! | |
last.is_a?(::Hash) ? pop : {} | |
end | |
end | |
def assert_types *args, &block | |
options = args.extract_options! | |
# Check that the block has the proper arity | |
raise ArgumentError, "Expected #{options[:passed].count} arguments, got #{args.count}" unless options[:passed].count == args.count |
This file contains 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
render: (date_range, models) -> | |
# Grab data | |
data = _.sortBy (get_data date_range, models), (o) -> | |
parseInt o.id.split("-").join(""), 10 | |
# Scale | |
ratio = get_ratio @maxHeight, data | |
height = _.bind get_height, null, ratio | |
# Render | |
chart = d3.select(@el[0]) |
This file contains 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
1.9.3p0 :168 > WorkWeek.totals_for_project_and_date_range(Project.find(4), Date.today, 3.months.from_now(Date.today)) | |
Project Load (0.5ms) SELECT "projects".* FROM "projects" WHERE "projects"."id" = $1 ORDER BY client_id ASC, name ASC LIMIT 1 [["id", 4]] | |
WorkWeek Load (1.2ms) SELECT "work_weeks".* FROM "work_weeks" WHERE "work_weeks"."project_id" = 4 AND "work_weeks"."year" = 2012 AND ("work_weeks"."cweek" BETWEEN 18 AND 31) | |
=> {18=>84, 19=>84, 20=>84, 21=>84, 22=>84, 23=>4, 24=>0, 25=>0, 26=>0, 27=>0, 28=>0, 29=>0, 30=>0, 31=>0} |
This file contains 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
scope :for_project_and_date_range, lambda { |project, lower, upper| | |
if lower.cweek < upper.cweek | |
where(project_id: project.id, year: lower.year, cweek: Range.new(lower.cweek,upper.cweek)) | |
else # The date range spans over two years | |
query = "project_id = ? AND ((cweek > ? AND year = ?) OR (cweek < ? AND year = ?))" | |
where(query, project.id, lower.cweek, lower.year, upper.cweek, upper.year) | |
end | |
} |
This file contains 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 work_weeks_for_date_range(date_range) | |
{}.tap do |result| | |
date_range.each do |date| | |
result.store(date, WorkWeek.where(user_id: id, cweek: date.cweek, year: date.year, project_id: projects.for_company(current_company_id).map(&:id))) | |
end | |
end | |
end |
This file contains 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
Undefined symbols for architecture x86_64: | |
"_linked_list_put", referenced from: | |
_main in ccUFU1uN.o | |
"_print_linked_list", referenced from: | |
_main in ccUFU1uN.o | |
"_key_position", referenced from: | |
_main in ccUFU1uN.o | |
"_linked_list_get", referenced from: | |
_main in ccUFU1uN.o | |
"_linked_list_delete", referenced from: |
This file contains 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
hash_table.c:165:3: error: expected ')' | |
assert(code == LL_DELETE_OK); | |
^ | |
hash_table.c:165:18: note: instantiated from: | |
assert(code == LL_DELETE_OK); | |
^ | |
hash_table.c:7:23: note: instantiated from: | |
#define LL_DELETE_OK 0; | |
^ | |
hash_table.c:165:3: note: to match this '(' |
This file contains 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
char* format_time(time_t t) | |
{ | |
char formatted_time[64]; | |
struct tm *ts; | |
strftime(formatted_time, sizeof formatted_time, "%Y-%m-%d %H:%M:%S", ts); | |
return formatted_time; | |
} |
This file contains 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 Array | |
def extract_options! | |
last.is_a?(::Hash) ? pop : {} | |
end | |
def tail | |
head, *tail = *self | |
tail | |
end |
This file contains 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 pmap &block | |
if size > 0 | |
match self.shape, | |
head_tail: ->{ self.tail.pmap(&block).unshift yield(self.head) }, | |
head: ->{ [ yield(self.head) ] } | |
else | |
self | |
end | |
end | |
end |