Skip to content

Instantly share code, notes, and snippets.

View amiel's full-sized avatar

Amiel Martin amiel

View GitHub Profile
@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
var Activity = (function() {
var count = 0;
var show = $.fancybox.showActivity;
var hide = $.fancybox.hideActivity;
var start = function() {
++count;
show();
};
require 'virtus'
class Foo
include Virtus
attribute :id, Integer
attribute :date, Date
attribute :foo, String
def initialize(attributes = {})
class Foo
extend AutoCoercions
coerce :date_gte, :date_lte, with: :to_date
coerce :trip_mode_eq, :trip_purpose_eq, :trip_count_gte, with: :to_i
coerce :select_random_winners, with: ->(v) { v == '1' }
coerce :random_winner_count, with: :to_i
def initialize(attributes = {})
@attributes = self.class.apply_coercions(attributes)
@amiel
amiel / foo.rb
Created November 8, 2012 21:55
ActiveAdmin icons
ActiveAdmin.register Foo do
collection_action :foo
end
@amiel
amiel / test.rb
Created November 7, 2012 18:26
Crazy not-parse-error failed like so
deliveries = ActionMailer::Base.deliveries. # <= note extra `.`
assert_equal I18n.t('user_mailer.bid_confirmation_email.subject'), deliveries.first.subject
# => NoMethodError: undefined method `first' for nil:NilClass
@amiel
amiel / en.yml
Created October 23, 2012 22:55
Using Stamp (https://github.com/jeremyw/stamp) with I18n.l
en:
date:
formats:
default: <%= Stamp.strftime_format("March 1, 1999") %>
short: <%= Stamp.strftime_format("Mon Jan 1") %>
ordinal: <%= Stamp.strftime_format("1st of Jan") %>
time:
formats:
default: etc...
controller do
def create
# Extend create to set the current user in your model here
create!
end
end
@amiel
amiel / engine.rb
Created October 10, 2012 21:37
Testing routes with Rails 3.2 mountable engines and RSpec 2
# your-engine/lib/magic/rails/engine.rb
module Magic
module Rails
module Engine
##
# Automatically append all of the current engine's routes to the main
# application's route set. This needs to be done for ALL functional tests that
# use engine routes, since the mounted routes don't work during tests.
#