Skip to content

Instantly share code, notes, and snippets.

@ZenCocoon
ZenCocoon / gist:1014996
Created June 8, 2011 18:23 — forked from dhh/gist:1014971
Use concerns to keep your models manageable
# autoload concerns
module YourApp
class Application < Rails::Application
config.autoload_paths += %W(
#{config.root}/app/controllers/concerns
#{config.root}/app/models/concerns
)
end
end
@ZenCocoon
ZenCocoon / css3_background_patterns.css.scss.erb
Created May 24, 2011 18:36
CSS3 Carbon Background Patterns
<% vendor_prefixes = ['-moz-', '-webkit-', '-o-', '-ms-', ''] %>
@mixin carbon {
<% vendor_prefixes.each do |prefix| %>
<%= "background:
#{prefix}linear-gradient(63deg, #151515 5px, transparent 5px) 0 5px,
#{prefix}linear-gradient(243deg, #151515 5px, transparent 5px) 10px 0px,
#{prefix}linear-gradient(63deg, #222 5px, transparent 5px) 0px 10px,
#{prefix}linear-gradient(243deg, #222 5px, transparent 5px) 10px 5px,
#{prefix}linear-gradient(0deg, #1b1b1b 10px, transparent 10px),
@ZenCocoon
ZenCocoon / gist:950118
Created May 1, 2011 00:08
CSS3 Carbon Pattern inspired from subtlepatterns's Atle Mo, Micro Carbon
/* First Draft */
background-size: 20px 20px;
background-position: 0px 5px, 10px 0px, 0px 10px, 10px 5px,
0px 15px, 10px 10px, 0px 20px, 10px 15px,
10px 5px, 0px 0px, 10px 10px, 0px 5px,
10px 15px, 0px 10px, 10px 20px, 0px 15px;
background-image:
linear-gradient(63deg, #131313 5px, transparent 5px),
@ZenCocoon
ZenCocoon / gist:950006
Created April 30, 2011 21:25
Do not edit on blank for a single instance.
<p>
<span id="editable"></span>
<a href="#" id="externalcontrol">click to edit</a>
</p>
<script>
// <![CDATA[
new Ajax.InPlaceRichEditor($('editable'), URL, {
editOnBlank: false,
externalControl: $('externalcontrol')},
TINYMCE_OPTIONS
@ZenCocoon
ZenCocoon / gist:949592
Created April 30, 2011 10:45
InPlaceRichEditor with external control
new Ajax.InPlaceRichEditor($('EDITOR_ID'), 'URL', {
externalControl: 'EXTERNAL_CONTROL_ID'
});
@ZenCocoon
ZenCocoon / gist:866703
Created March 11, 2011 22:32
wkhtmltopdf chef recipe
package "app-misc/wkhtmltopdf-bin" do
version "0.10.0_beta5"
action :install
end
@ZenCocoon
ZenCocoon / gist:866561
Created March 11, 2011 20:56
Delayed Job chef template
check process <%= @worker_name %>
with pidfile /data/<%= @app_name %>/shared/pids/delayed_job.<%= @worker_count %>.pid
start program = "/bin/bash -c 'cd /data/<%= @app_name %>/current/;RAILS_ENV=<%= @framework_env %> script/delayed_job start -i <%= @worker_count %>'" with uid deploy and gid deploy with timeout 65 seconds
stop program = "/bin/bash -c 'export RAILS_ENV=<%= @framework_env %>;cd /data/<%= @app_name %>/current/;script/delayed_job stop -i <%= @worker_count %>'"
if totalmem is greater than 240 MB for 2 cycles then restart # eating up memory?
group dj_<%= @app_name %>
# Helper : app/helpers/bookings_helper.rb
module BookingsHelper
def booking_price(booking)
"something"
end
end
# Helper spec : spec/helpers/bookings_helper_spec.rb
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
@ZenCocoon
ZenCocoon / admin_controller_spec.rb
Created February 20, 2011 19:05
RSpec2, Rails3 and testing your generic controller like admin_controller.rb
#
# # What's the problem
#
# I wanna test a before filter that render errors in XML and JSON if failing
# When testing it from a classic controller it works fine, when testing from
# the ApplicationController directly it fails
#
#
# # Some code please...
@ZenCocoon
ZenCocoon / Scope issue with Rails 2.3.10 upgrade to Rails 3.0.3
Created February 7, 2011 08:30
scope issue under Rails 3.0.3 after upgrade from 2.3.10
#
# FIXED: Was due to a validates_inclusion_of having :within instead of :in
#
# Weird issue after upgrading from Rails 2.3.10 to Rails 3.0.3
# The scope doesn't work. It works with a new sample app but
# NOT from the upgraded one.
#
# Models
class User < ActiveRecord::Base