Skip to content

Instantly share code, notes, and snippets.

View gist:ca95af6f614086581a45
garage = Winker.devices.find{|d| == "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})
KellyMahan / gist:3699188
Created Sep 11, 2012
What I learned today
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
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 / gist:1217726
Created Sep 14, 2011
I needed a queue system just like Resque but that would halt on the first error.
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
rescue Exception => e
View gist:1187027
def create
@timesheet =[:timesheet])
@date = @timesheet.start_date
if @timesheet.update_attributes(params[:timesheet])
flash[:notice] = 'Timesheet was successfully saved.'
redirect_to timesheets_path
redirect_to timesheets_path
View gist:1186989
<%= form_for @timesheet do |f| %>
<% if @timesheet.errors.any? %>
<div class="error_messages">
<h2>Form is invalid</h2>
<% for message in @timesheet.errors.full_messages %>
<li><%= message %></li>
<% end %>