Skip to content

Instantly share code, notes, and snippets.

@kurbmedia
kurbmedia / Default Deploy.rb
Created May 4, 2010 04:30
Rails 3 Template
#
# This is a default deploy.rb
# it is included into the Rails 3 Basic Template by default.
#
require 'active_support'
DEPLOY_CONFIG = YAML::load(File.open("config/deploy.yml"))
default_run_options[:pty] = true
@kurbmedia
kurbmedia / HelperMethods.rb
Created May 5, 2010 03:20
Misc Helper Methods
# Miscellaneous helper methods to include into applications
# include into application_helper.rb
module HelperMethods
# Creates a navigation link (by default a list item) that has the class 'on' if we are on that particular page or a
# page beneath it.
# Example: nav_link_to('Blog', 'blog') will have the class of 'on' should we be on /blog or /blog/some_path
def nav_link_to(txt, path, attrs = {}, wrapper = :li, &block)
@kurbmedia
kurbmedia / fields_for_sortable.html.erb
Created August 3, 2010 17:39
.sortable nested_attributes
<%
# This works for sorting fields using jquery.sortable and fields_for / accepts_nested_attributes_for
# Tested with mongoid, haven't tried activerecord.
# object is the main object used in form_for (this is a partial in my case)
# content_fields is an embeds_many inside of that parent object.
# each content_field has a field "position" I'm using to position each item.
%>
<% object.content_fields.sort{ |x,y| x.position.to_i <=> y.position.to_i }.each_with_index do |cf, ind| %>
@kurbmedia
kurbmedia / fluffery.widget.js
Created August 4, 2010 20:50
Initial widget library for fluffery.js
(function($) {
var factory = {
init:function(opts){
var options = { load:true };
if(opts) $.extend(options, opts);
this.each(function(){
@kurbmedia
kurbmedia / forms.rb
Created October 13, 2010 20:25
Custom form builder to create more sensible defaults.
class CustomFormBuilder < ActionView::Helpers::FormBuilder
def label(method, text = nil, options = {})
options, text = text, nil if text.is_a?(Hash)
text ||= method.to_s.humanize
text = text.titleize if text.split(' ').size <= 3
if options.key?(:required)
@kurbmedia
kurbmedia / blueprint.scss
Created October 31, 2010 05:30
Default SCSS file for blueprint inclusion.
@import "blueprint/reset";
// Here is where you can define your constants for your application and to configure the blueprint framework.
// Feel free to delete these if you want keep the defaults:
$blueprint-grid-columns: 24;
$blueprint-container-size: 950px;
$blueprint-grid-margin: 10px;
// Use this to calculate the width based on the total width.
// Or you can set $blueprint-grid-width to a fixed value and unset $blueprint-container-size -- it will be calculated for you.
@kurbmedia
kurbmedia / multi_parameter_attributes.rb
Created November 1, 2010 01:04
Misc MongoMapper Plugins
module MultiParameterAttributes
module InstanceMethods
def attributes=(attrs)
multi_parameter_attributes = []
attrs.each do |name, value|
return if attrs.blank?
if name.to_s.include?("(")
multi_parameter_attributes << [ name, value ]
else
writer_method = "#{name}="
@kurbmedia
kurbmedia / default
Created November 6, 2010 19:39 — forked from mauricio/default
# as we’re going to use Unicorn as the application server
# we’re not going to use common sockets
# but Unix sockets for faster communication
upstream shop {
# fail_timeout=0 means we always retry an upstream even if it failed
# to return a good HTTP response (in case the Unicorn master nukes a
# single worker for timing out).
# for UNIX domain socket setups:
server unix:/tmp/shop.socket fail_timeout=0;
@kurbmedia
kurbmedia / deploy.rb
Created November 7, 2010 03:14
Config files for nginx and unicorn.
namespace :deploy do
# To avoid having to add a password for sudo, visudo and add
# deployusername ALL=(ALL) NOPASSWD: /etc/init.d/unicorn reload
task :start do
sudo "/etc/init.d/unicorn start"
end
task :stop do
sudo "/etc/init.d/unicorn stop"
@kurbmedia
kurbmedia / deploy.rb
Created November 12, 2010 06:11
Base deploy recipe set.
#
# This is a default deploy.rb
# it is included into the Rails 3 Basic Template by default.
#
require 'active_support'
require 'lib/deploy_helpers'
DEPLOY_CONFIG = YAML::load(File.open("#{Rails.root}/config/deploy.yml"))