Skip to content

Instantly share code, notes, and snippets.

View gogogarrett's full-sized avatar

Garrett Heinlen gogogarrett

  • Netflix
  • San Francisco, CA
View GitHub Profile
require 'representable/json'
require 'representable/json/collection'
# representers
module StudentProgressRepresenter
include Representable::JSON
property :id
collection :precinct_progresses#, extend: PrecinctProgressRepresenter, class: PrecinctProgress
end
@gogogarrett
gogogarrett / chat.haml
Created January 22, 2015 06:52
A poor man's realtime chat application.. kinda :trollface:
#timeline.timeline-container
- @conversation.messages.each do |message|
%article.timeline-entry
%p= message.body
= form_for [@conversation, @form], html: { style: 'overflow: hidden' } do |f|
= f.text_area :body, placeholder: "Type your message here ...", rows: 5
= f.button "Send", type: :submit
class Bid < ActiveRecord::Base
class Create < Trailblazer::Operation
include CRUD
model Bid, :create
contract do
model Bid
property :approved
property :creator
@gogogarrett
gogogarrett / message.rb
Created January 11, 2015 22:19
Traillazer Operation
class Message < ActiveRecord::Base
class Create < Trailblazer::Operation
include CRUD
model Message, :create
builds do |params|
System if params[:conversation].messages.empty?
end
contract do
@gogogarrett
gogogarrett / after_signup_controller.rb
Created January 6, 2015 02:50
Reform + Wicked Integration
class AfterSignupController < ApplicationController
include Wicked::Wizard
steps :create_organization, :create_event, :create_tiers
def show
case step
when :create_organization
@form = Form::Organization.new(Organization.new)
when :create_event
@form = Form::Event.new(Event.new)
@gogogarrett
gogogarrett / event_controller.rb
Last active August 29, 2015 14:12
simple reform example
class EventsController < ApplicationController
def index
@events = Event.all
end
def show
@event = Event.find(params[:id])
end
def new
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
before_action :authorize_user!
protected
def authorize_user!
@gogogarrett
gogogarrett / file_system_adapter_test.rb
Created December 17, 2014 05:35
Lotus model - FileSystemAdapter - issue.
require 'test_helper'
describe Lotus::Model::Adapters::FileSystemAdapter do
before do
TestUser = Struct.new(:id, :name, :age) do
include Lotus::Entity
end
class TestUserRepository
include Lotus::Repository
module Api
module V1
class AnswerController < ApplicationController
respond_to :json
def create
lesson_session.process_attempts(params[:attempts].values)
API::ProcessAnswer.new(lesson_session, current_student).call if lesson_session.completed?
render json: {}
class School < ActiveRecord::Base
has_many :students
has_many :teachers
def to_param
"#{id}-#{name.parameterize}"
end
def to_s
name