Skip to content

Instantly share code, notes, and snippets.

class ApplicationDecorator < Draper::Base
def initialize(input, options={})
input = input.model if input.is_a?(self.class)
super input, options
end
end
# This is for an address book-like app.
# Do people ever associate nested objects with the very top object to
# Make sure that the nested object can never be seen by anybody besides
# the User/Owner? Basically, this is so I wouldn't have to go through
# person to find the owner of a piece of data.
class User < ActiveRecord::Base
has_many :people, foreign_key: :owner_id
has_many :addresses # thinking about adding this
end
It is deserializing "object: !ruby/object:Class Time" as Class instead of Time. I'm not sure if it is a serialization or deserialization error.
# Production
irb(main):016:0> YAML::ENGINE.yamler = 'syck'=> "syck"
irb(main):017:0> Delayed::PerformableMethod.new(Time, :now, {}).to_yaml
=> "--- !ruby/struct:Delayed::PerformableMethod \nobject: !ruby/object:Class Time\nmethod_name: :now\nargs: {}\n\n"
# Development
@r38y
r38y / circles_controller.rb
Created November 12, 2011 19:12
Wraps call to api endpoint for returning objects for a map based on some parameters.
class Api::CirclesController < ApplicationController
def index
circles_presenter = API::CirclesPresenter.new(params)
render :json => circles_presenter.to_json,
:callback => params[:callback]
end
end
@r38y
r38y / cunt.rb
Created October 31, 2011 19:59
Help prevent typos
class Object
def cunt
"I'm guessing you meant 'count'?"
end
end
@r38y
r38y / bsso.scss
Created October 28, 2011 19:25
Nested reset
@import "compass/reset/utilities";
@import "compass/css3";
@import "compass/utilities/general/clearfix";
#bsso-user-bar {
@include nested-reset;
@include reset-html5;
@include clearfix;
position: fixed;
top: 0;
@r38y
r38y / weigh_in.json
Created October 4, 2011 14:53
Weigh in json
{
"id": 3224,
"type": "WeeklyWeighIn",
"state": "successful",
"actual_weight": "220.4",
"goal_weight": "221.6",
"penalty": "0.0",
"comment": "",
"url": "https://loseitorloseit.com/r38y/weigh_ins/3224",
"weighed_in_at": "2011-10-04T13:21:44Z",
@r38y
r38y / ruby1.9.3-p0-times.md
Created September 29, 2011 18:07
Some boot/test times for some of my Rails apps

loseitorloseit.com (Rails 3.1.1)

➜  loseitorloseit.com git:(master) ✗ rvm use 1.9.2
Using /Users/r38y/.rvm/gems/ruby-1.9.2-p290
➜  loseitorloseit.com git:(master) ✗ time ./script/rails runner "puts 1234"
./script/rails runner "puts 1234"  18.56s user 1.86s system 98% cpu 20.738 total
➜  loseitorloseit.com git:(master) ✗ time be rspec spec
Finished in 179.54 seconds
1711 examples, 1 failure

bundle exec rspec spec 162.11s user 14.06s system 79% cpu 3:41.35 total

@r38y
r38y / loads_presenter.rb
Created September 27, 2011 22:03
Custom sorting rules and presenters
class LoadsPresenter
extend ActiveSupport::Memoizable
def loads; raise "Implement #loads in subclass"; end
memoize :loads
def each(&block)
loads.each(&block)
end
@r38y
r38y / gist:1181971
Created August 30, 2011 20:46 — forked from zorn/gist:1181949
Trouble with nested content_tag in rails 3
In my app I made a helper method to help me render form rows and DRY up my code.
def form_row(form, input_type, symbol)
# Need to generate HTML like this
# <div class="clearfix">
# <%= f.label :first_name %>
# <div class="input">
# <%= f.text_field :first_name, html_options = {:class => 'xlarge'} %>
# </div>
# </div><!-- /clearfix -->