Skip to content

Instantly share code, notes, and snippets.

View amiel's full-sized avatar

Amiel Martin amiel

View GitHub Profile
class MyException < StandardError
attr_reader :arbitrary_value
def initialize(message, arbitrary_value)
super(message)
@arbitrary_value = arbitrary_value
end
end
e = (raise MyException.new('this is the regular message', 'my value') rescue $!)
@amiel
amiel / README.md
Last active December 15, 2015 13:08

with_status

Use with_status to run commands and have your arduino let you know when they are done.

with_status starts by turning the LED off before running your command. Once your command completes, it will turn the LED on. Green if the command succeeded, and red if it failed.

I use this with long running commands (such as deploying to heroku), so I can start working on something else without forgetting about my process.

@amiel
amiel / README.md
Last active December 15, 2015 12:09
Hacks for digispark arduino notificationts for guard
class User < ActiveRecord::Base
# t.string :status, default: 'submitted'
# Contrived example
def self.status_options
%w[approved rejected submitted]
end
end
class ApplicationDecorator < Draper::Base
# See +ApplicationDecorator.humanize+
def humanize(attribute, key = model.send(attribute), default = key.to_s.humanize)
self.class.humanize attribute, key, default
end
# By default, humanize the attributes listed.
#
class Task < ActiveRecord::Base
belongs_to :project
validate do
if project.status != 'funded'
errors.add(:base, 'Project must be funded')
end
end
end
@amiel
amiel / gist:4639650
Created January 26, 2013 02:07
Attitude :)
2013-01-25 18:06:55.146 Stride[86479:c07] *** -[__NSCFCalendar components:fromDate:]: date cannot be nil
I mean really, what do you think that operation is supposed to mean with a nil date?
An exception has been avoided for now.
A few of these errors are going to be reported with this complaint, then further violations will simply silently do whatever random thing results from the nil.
Here is the backtrace where this occurred this time (some frames may be missing due to compiler optimizations):
(
0 CoreFoundation 0x02425a75 -[__NSCFCalendar components:fromDate:] + 85
@amiel
amiel / .vimrc
Created January 25, 2013 19:31
Sections from my .vimrc regarding simplecov.vim
function! SetupCoverage()
if filereadable("coverage.vim")
source coverage.vim
endif
endfunction
if has("autocmd")
autocmd FileType ruby call SetupCoverage()
endif
def possessivize(owner)
owner.ends_with?('s') ? owner + "&rsquo;" : owner + "&rsquo;s"
end
var Activity = (function() {
var count = 0;
var show = $.fancybox.showActivity;
var hide = $.fancybox.hideActivity;
var start = function() {
++count;
show();
};