Skip to content

Instantly share code, notes, and snippets.

View Veejay's full-sized avatar

Bertrand Chardon Veejay

View GitHub Profile
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
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])
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}
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
}
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
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:
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 '('
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;
}
class Array
def extract_options!
last.is_a?(::Hash) ? pop : {}
end
def tail
head, *tail = *self
tail
end
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