Skip to content

Instantly share code, notes, and snippets.

View jgaskins's full-sized avatar

Jamie Gaskins jgaskins

View GitHub Profile
@jgaskins
jgaskins / Gemfile
Created August 9, 2011 15:14
App config
gem 'rails', '3.1.0.rc5'
gem 'mongoid'
gem 'bson_ext'
gem 'paperclip' # Upload images for the gallery
gem 'devise' # Authentication
gem 'cancan' # Authorization
gem 'haml' # Markup
gem 'redcarpet' # Markdown templates
gem 'dalli' # Memcached interface
@jgaskins
jgaskins / application.rb
Created August 22, 2011 02:11
Checking for private beta in a Rails app
# Normal app setup
module AppName
class Application < Rails::Application
# Other stuff unnecessary to this
# Here's the money-maker
config.release_status = ENV['RELEASE_STATUS'].to_sym || :beta
end
end
@jgaskins
jgaskins / application.html.haml
Created September 8, 2011 14:37
Newsletter subscription form
=form_for :newsletter_subscription, method: 'post', class: 'subscribe clearfix' do |f|
=f.email_field :email, '', placeholder: 'Your e-mail address', class: 'subscribe-field'
=image_submit_tag 'mail-ico.png', class: 'subscribe-button', alt: 'Subscribe'
// I've never seen it written this way
myFunction(function() {
doSomethingJavascripty() })
@jgaskins
jgaskins / article_mapper.rb
Created February 26, 2012 06:17
Perpetuity ActiveModel wrapper
require 'article'
require 'user'
class ArticleMapper < Perpetuity::Mapper
include Perpetuity::ActiveModelWrapper
attribute :title, String
attribute :body, String
attribute :author, User
end
@jgaskins
jgaskins / articles_controller.rb
Created February 26, 2012 06:43
Perpetuity ActiveModel wrapper class
class ArticlesController < ApplicationController
def edit
@article = ArticleMapper.find(params[:id])
@article_model = Perpetuity::ActiveModel.new(article)
end
end
@jgaskins
jgaskins / gist:1957596
Created March 2, 2012 10:33
Experiment to allow users to use Enumerable-style select on mappers to retrieve the objects they want from the DB
# Attribute class would go into the DB layer
class Attribute
def initialize name
@name = name
end
# For attribute == value
# For demo purposes, I didn't feel like implementing other comparators
def == value
{ @name => value }
@jgaskins
jgaskins / _current_form.html.erb
Created March 27, 2012 01:08
Idea for Rails form helpers
<%= form_for @article do |f| %>
<div class="field">
<%= f.label :title %>
<%= f.text_field :title %>
</div>
<div class="field">
<%= f.label :body %>
<%= f.text_area :body %>
</div>
<% end %>
@jgaskins
jgaskins / thing_spec.rb
Created April 10, 2012 13:43
Keep your specs from needlessly hitting the database
describe ThingsController do
describe '#create' do
let(:thing_data) { { name: 'Name' } }
it 'creates a new Thing and hits the DB 3x' do
expect { post :create, thing: thing_data }.to change { Thing.count }.by 1
# other response-related expectations here
end
it 'creates a new Thing and hits the DB once' do
post :create, thing: thing_data
@jgaskins
jgaskins / text.html
Created May 2, 2012 11:41
Showing independent text-shadow color
<!DOCTYPE html>
<style>
p {
color: #f00;
font-size:48px;
text-shadow: #00f 0 0 10px;
}
</style>
<p>This is some text</p>