Skip to content

Instantly share code, notes, and snippets.

@netzpirat
netzpirat / deploy.rb
Created May 14, 2009 10:06
Capistrano recipe to sync rails database and files within a multi stage environment
set :sync_directories, ["public/assets", "public/galleries"]
set :sync_backups, 3
require 'action_view'
require 'active_support'
require 'mustache'
class Mustache
# TODO - Think about allowing to overwrite layout methods in subclassing views
#
# http://github.com/defunkt/mustache/blob/master/lib/mustache/sinatra.rb#L79-82
# http://github.com/defunkt/mustache/blob/master/lib/mustache/sinatra.rb#L96-102
@Burgestrand
Burgestrand / download-progress.rb
Created June 27, 2010 13:55
Ruby HTTP file download with progress measurement
require 'net/http'
require 'uri'
def download(url)
Thread.new do
thread = Thread.current
body = thread[:body] = []
url = URI.parse url
Net::HTTP.new(url.host, url.port).request_get(url.path) do |response|
# How to re-use the menu partial for a submenu in Refinery CMS >= 0.9.8.5 and < 0.9.9.22
# header menu (main menu) which hides its children.
<%= render :partial => "/shared/menu",
:locals => {
:dom_id => 'menu',
:css => 'menu',
:collection => @menu_pages,
:hide_children => true
} -%>
@kakra
kakra / filter_payment_methods.rb
Created October 14, 2010 22:10
Filter payment methods in Spree depending on the shipping name
# Filter payment methods in Spree depending on the shipping name,
# use the following snippet within your activation method to
# make it work:
#
# CheckoutsController.class_eval { include FilterPaymentMethods }
#
# The magic happens within the InstanceMethods module, change the
# regexp to fit your needs.
#
# Kai Krakow, http://github.com/kakra
@cmaujean
cmaujean / spree-extension-cap-tasks.rb
Created October 17, 2010 00:29
A set of extension management related tasks for using Capistrano on a spreecommerce install. For spree-0-11-stable.
# Spree extension capistrano tasks
# --------------------------------
# by Christopher Maujean
#
# These tasks depend on the existence of the extensions hash.
# The key is name of the directory in vendor/extensions.
# The value is the git url of the extension.
#
# set :extensions, {
# 'my_site' => "git@github.com:/username/spree-my-site.git"
@schof
schof / ability_decorator.rb
Created October 29, 2010 03:15
Add custom cancan abilities on top of Spree
class AbilityDecorator
include CanCan::Ability
def initialize(user)
#############################
can :destroy, LineItem do |item|
item.order.user == user
end
#############################
can :read, Artwork do |artwork|
module CML2
# Includes to ProductCategory model
module ProductCategory
def import node_set
::ProductCategory.delete_all
::ProductCategory.import_categories \
node_set.xpath('/КоммерческаяИнформация/Классификатор/Группы')
end
@PanosJee
PanosJee / refinery_omniauth.rb
Created March 17, 2011 22:58
Login / Register to Refinery with Omniauth (facebook, twitter, openid, etc)
# Create a role user (no perms). Fire up the console rails c
$> Role.create(:title=>'User')
# In your Gemfile add
gem 'oa-oauth', :require => 'omniauth/oauth'
# At the beginning of devise.rb. You can also create a yaml file and instantiate when Rails begin
# For shake of simplicity I added the credentials at devise.rb
Facebook = Rails.env.development? ? {:app_id => 2621xxx, :secret => 'e81f33d042xxxxx'} :
{:app_id => 1749xxx9, :secret => '13c11be6628dc1xxxx'}
@johnthethird
johnthethird / cap_notify.rb
Created May 4, 2011 20:02 — forked from rtekie/cap_notify.rb
Capistrano deployment email notifier for Rails 3
=begin
Capistrano deployment email notifier for Rails 3
Do you need to send email notifications after application deployments?
Christopher Sexton developed a Simple Capistrano email notifier for rails. You can find details at http://www.codeography.com/2010/03/24/simple-capistrano-email-notifier-for-rails.html.
Here is Rails 3 port of the notifier.
The notifier sends an email after application deployment has been completed.