Skip to content

Instantly share code, notes, and snippets.

View KellyMahan's full-sized avatar

Kelly Mahan KellyMahan

View GitHub Profile
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
@KellyMahan
KellyMahan / gist:3699188
Created September 11, 2012 14:36
What I learned today
#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
@KellyMahan
KellyMahan / gist:1217726
Created September 14, 2011 20:40
I needed a queue system just like Resque but that would halt on the first error.
# 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
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
<%= 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>