Skip to content

Instantly share code, notes, and snippets.

@ZenCocoon
ZenCocoon / gist:703998
Created November 17, 2010 20:17 — forked from dhh/gist:29752
config.action_controller.asset_host = Proc.new do |source, request|
non_ssl_host = "http://asset#{source.hash % 4}.backpackit.com"
ssl_host = "https://asset1.backpackit.com"
if request.ssl?
case
when source =~ /\.js$/
ssl_host
when request.headers["USER_AGENT"] =~ /(Safari)/
non_ssl_host
@ZenCocoon
ZenCocoon / gist:724366
Created December 1, 2010 22:36
Handling French date format in Ruby
## Try 1
# How could I get the following working nicely
Date.strptime("Ven 13 Mai. 2011, 16h00", "%a %d %b %Y, %Hh%M")
# I've tried to update Date::ABBR_DAYNAMES as follow
I18n.locale = :fr
Date::ABBR_DAYNAMES = I18n.t('date.abbr_day_names')
Date::ABBR_MONTHNAMES = I18n.t('date.abbr_month_names')
@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
@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...
# 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 / 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 %>
@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:949592
Created April 30, 2011 10:45
InPlaceRichEditor with external control
new Ajax.InPlaceRichEditor($('EDITOR_ID'), 'URL', {
externalControl: 'EXTERNAL_CONTROL_ID'
});
@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: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),