View gist:ca95af6f614086581a45
garage = Winker.devices.find{|d| d.name == "Garage Door"} | |
#i dont have a garage door to check this but I think this would be the correct update to send. | |
#assuming position is the correct attribute and a value between 0 and 1. and 0 is closed 1 is open. | |
if garage.position > 0 and garage.updated_at < 10.minutes.ago #check for position and last update time | |
garage.update(desired_state: {position: 0}) | |
end |
View gist:3699188
#something i learned today that I didn't know was possible in ruby. | |
array_of_long_pasted_in_strings = [<<FOO, <<BAR, <<BLATZ] | |
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore | |
magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo | |
consequat. | |
FOO | |
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur | |
sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum | |
View gist:1217726
# I came up with this code because I needed a queue system just like Resque but that would halt on the first error waiting for user intervention. | |
# It works well for what i need but I think it would be a great feature to have built into resque that could simplify what i've done. | |
class QueWorker | |
def self.start | |
loop do | |
begin | |
QueWorker.qloop | |
rescue Exception => e |
View gist:1187027
def create | |
@timesheet = Timesheet.new(params[:timesheet]) | |
@date = @timesheet.start_date | |
if @timesheet.update_attributes(params[:timesheet]) | |
flash[:notice] = 'Timesheet was successfully saved.' | |
redirect_to timesheets_path | |
else | |
redirect_to timesheets_path | |
end | |
end |
View gist:1186989
<%= form_for @timesheet do |f| %> | |
<% if @timesheet.errors.any? %> | |
<div class="error_messages"> | |
<h2>Form is invalid</h2> | |
<ul> | |
<% for message in @timesheet.errors.full_messages %> | |
<li><%= message %></li> | |
<% end %> | |
</ul> | |
</div> |