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
SlideShow =
current_image: 0,
max_images: 0,
init: ->
$slideshow = $('#slideshow > div ul')
$slideshow.find('li').hide().eq(0).show()
@max_images = $slideshow.find('li').length
@change_slide($slideshow)
[alias]
co = checkout
# Log display from screencast, with train tracks.
l = log --graph --pretty=format':%C(yellow)%h%Cblue%d%Creset %s %C(white) %an, %ar%Creset'
# Alternate log display from Scott Chacon
lol = log --pretty=oneline --abbrev-commit --graph --decorate
# Other useful aliases:
unstage = reset HEAD
staged = diff --cached
unstaged = diff
- edit ||= false
%label Search
%input#filter
%hr
%table.footable{"data-filter" => "#filter"}
%thead
%tr
%label Search
%input#filter
%hr
%table.footable{"data-filter" => "#filter"}
%thead
%tr
- if block
%th
class Forms::StudentWithProfileForm
extend ActiveModel::Naming
include ActiveModel::Conversion
include ActiveModel::Validations
def persisted?
false
end
ATTRIBUTES = [:first_name, :last_name, :email, :grade, :locale, :country]
@gogogarrett
gogogarrett / artist_controller.rb
Last active December 17, 2015 03:38
Using Reform with a Workflow object to allow the controller to be simpler.
class ArtistsController < ApplicationController
def create
@form = create_new_form
workflow = Workflows::ArtistWorkflow.new(@form, params[:artist])
workflow.process do |obj|
return respond_with obj
end
render :new
class PointLedger
attr_reader :user
def initialize(user)
@user = user
end
def add(amount, item)
user.point_transactions.build(amount: amount, item_type: item.class, item_name: item.name)
user.points += amount
@gogogarrett
gogogarrett / item.rb
Created May 13, 2013 22:37
Example of how you can use ruby classes to abstract away from using entirely active record objects.
module Purchase
class Item
attr_reader :student, :item
delegate :cost, to: :item
def initialize(student, item)
@student = student
@item = item
end
@gogogarrett
gogogarrett / point_ledger.rb
Created May 13, 2013 22:39
A very simplistic implementation of a point ledger class that adds and deducts by creating user point transactions.
class PointLedger
attr_reader :student
def initialize(student)
@student = student
end
def add(amount, item)
create_point_transaction(amount, item)
student.points += amount
class PurchasesController < ApplicationController
def create
purchase_service = service_lookup[params[:purchase_type]]
item_class = item_class_lookup[params[:purchase_type]]
item = item_class.find_by(name: params[:item_name])
purchase_service.new(current_student, item).purchase
redirect_to map_path
end