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
// A Sample Map JSON object.
{
"_links": {
"self": { "href": "/map" }
},
"_embedded": {
"locations": [{
"_links": {
"self": { "href": "/purchase/trip/texas" },
@gogogarrett
gogogarrett / persistance_trade.rb
Last active August 29, 2015 13:57
basic idea for implementing a state machine. Not tested or throught out in much detail.. but meh.
module Persistance
class Trade < ActiveRecord::Base
validates :item_id, :actor_id, presence: true
def state
super.to_s
end
end
end
config.to_prepare do
Dir.entries("app/extensions")
.select{ |f| !File.directory? f}
.each do |file_name|
array = file_name.split("_")
array.pop
klass_name = array.map(&:capitalize).join
klass = klass_name.constantize
# app/extensions/school_extensions.rb
module SchoolExtensions
extend ActiveSupport::Concern
included do
end
def address
[street, suburb, state, postcode, country].join(', ')
end
class School < ActiveRecord::Base
has_many :students
has_many :teachers
def to_param
"#{id}-#{name.parameterize}"
end
def to_s
name
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: {}
@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
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 / 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
@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)