Skip to content

Instantly share code, notes, and snippets.

View amiel's full-sized avatar

Amiel Martin amiel

View GitHub Profile
@amiel
amiel / 1_fat_controller.rb
Last active December 16, 2015 00:48
An oversimplification of some rails best practices over time.
class WidgetsController < ApplicationController
def create
@widget = Widget.new(params[:widget])
if @widget.save
SpamMailer.widget_spam(@widget).deliver
redirect_to widget, notice: 'Widget created'
else
render 'new'
end
@amiel
amiel / gist:5320486
Created April 5, 2013 16:03
Hack to undecorate resource for forms. Regarding https://github.com/gregbell/active_admin/issues/2013
module ActiveAdmin
module ViewHelpers
module FormHelper
def active_admin_form_for(resource, options = {}, &block)
options = Marshal.load( Marshal.dump(options) )
options[:builder] ||= ActiveAdmin::FormBuilder
+ resource = resource.respond_to?(:model) ? resource.model : resource
semantic_form_for resource, options, &block
end
@amiel
amiel / RestKitManager.mm
Last active December 15, 2015 17:10
My RestKit mappings
// I have a RestKitManager.m that holds general methods to help set up mappings and routings
@implementation RestKitManager
- (void)initialize {
RKObjectManager *objectManager = [RKObjectManager managerWithBaseURL:[NSURL URLWithString:[AppDelegate appUrlForKey:BASE_URL_KEY]]];
[RKObjectManager setSharedManager:objectManager];
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