Skip to content

Instantly share code, notes, and snippets.

@brycesenz
brycesenz / gist:6967780
Created October 13, 2013 21:50
DCI Controller example with delegators
# GET /user/password/edit?reset_password_token=abcdef
def edit
context = ResettingPassword.new
context.add_subscriber(EditDelegator.new(self))
context.find_for_reset(params[:reset_password_token])
end
class EditDelegator < ApplicationDelegator
def success(user)
render :action => :edit, :locals => { :user => user }
@brycesenz
brycesenz / 0_reuse_code.js
Created November 21, 2013 22:12
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@brycesenz
brycesenz / rails_resources.md
Created November 21, 2013 22:12 — forked from jookyboi/rails_resources.md
Rails-related Gems and guides to accelerate your web project.

Gems

  • Bundler - Bundler maintains a consistent environment for ruby applications. It tracks an application's code and the rubygems it needs to run, so that an application will always have the exact gems (and versions) that it needs to run.
  • rabl - General ruby templating with json, bson, xml, plist and msgpack support
  • Thin - Very fast and lightweight Ruby web server
  • Unicorn - Unicorn is an HTTP server for Rack applications designed to only serve fast clients on low-latency, high-bandwidth connections and take advantage of features in Unix/Unix-like kernels.
  • SimpleCov - SimpleCov is a code coverage analysis tool for Ruby 1.9.
  • Zeus - Zeus preloads your Rails app so that your normal development tasks such as console, server, generate, and specs/tests take less than one second.
  • [factory_girl](h
@brycesenz
brycesenz / css_resources.md
Created November 21, 2013 22:12 — forked from jookyboi/css_resources.md
CSS libraries and guides to bring some order to the chaos.

Libraries

  • 960 Grid System - An effort to streamline web development workflow by providing commonly used dimensions, based on a width of 960 pixels. There are two variants: 12 and 16 columns, which can be used separately or in tandem.
  • Compass - Open source CSS Authoring Framework.
  • Bootstrap - Sleek, intuitive, and powerful mobile first front-end framework for faster and easier web development.
  • Font Awesome - The iconic font designed for Bootstrap.
  • Zurb Foundation - Framework for writing responsive web sites.
  • SASS - CSS extension language which allows variables, mixins and rules nesting.
  • Skeleton - Boilerplate for responsive, mobile-friendly development.

Guides

@brycesenz
brycesenz / pokemon_decorator.rb
Created November 21, 2013 22:30
Shelby's Presenter example
class PokemonDecorator < Draper::Decorator
def squirtle_scope
h.select_tag("shell", colors(current), class: "squirtlicious")
end
def colors(current)
current = 1
h.options_for_select({
"Blue" => 1,
"Green" => 2,
@brycesenz
brycesenz / complex_form_save.rb
Created January 16, 2014 04:34
Example complex form saving for Daryl
#------------------------------------------------------------
# View
#------------------------------------------------------------
= form_for(claim...) do |f|
= text_field :user_lookup # An existing reference or data to create a new one
= text_field :provider_lookup # An existing reference or data to create a new one
= text_field :claim_name
= text_field :claim_amount
= text_area :claim_description
@brycesenz
brycesenz / customer_serializer.rb
Last active October 22, 2020 07:42
Rspec tests & helpers for ActiveModel::Serializers
# app/serializers/customer_serializer_spec.rb
class CustomerSerializer < ActiveModel::Serializer
attributes :customer_number, :email, :username
def customer_number
object.account_number
end
def merchant_id
@brycesenz
brycesenz / problem_statement.md
Last active August 29, 2015 13:56
Solving TimeLogger problem for chat user.

I have a time range, ex: ["02:15", "04:30"] which shows a session begin and end time.

I need to break that down by the hour. End result would be: 2: 2700 3: 3600 4: 1800

The way I thought about doing this was breaking this down into the following array: ["02:15", "03:00", "04:00", "04:15"] and getting the time difference between the elements.. ie difference between 03:00 and 02:15 which results in 2700s, etc.

Any suggestions on something better? more efficient?

This is a list of steps to:

  • Setup a new Rails app
  • Initialize a local repository using git
  • Create a new remote repository using GitHub
  • Change README.rdoc
  • Deploy to a cloud service - Heroku

Assumptions:

  • Ruby is installed (v 1.9.3)
  • Rails is installed (v 3.2.3)
@brycesenz
brycesenz / 1_models.rb
Created May 23, 2014 15:03
Forms for complexly nested models
class Person < ActiveRecord::Base
has_one :phone
has_many :dogs
attr_accessible :name
end
class Phone < ActiveRecord::Base
attr_accessible :phone_number
end