Skip to content

Instantly share code, notes, and snippets.

RAILS_ROOT = File.dirname(File.dirname(__FILE__))
20.times do |num|
God.watch do |w|
w.name = "dj-#{num}"
w.group = 'dj'
w.interval = 30.seconds
w.start = "rake -f #{RAILS_ROOT}/Rakefile -I #{RAILS_ROOT} RAILS_ENV=production jobs:work"
w.uid = 'git'
@marclipovsky
marclipovsky / gist:1185772
Created September 1, 2011 09:14
Stack level too deep
activesupport (3.0.6) lib/active_support/inflector/methods.rb:52:in `underscore'
activesupport (3.0.6) lib/active_support/core_ext/string/inflections.rb:83:in `underscore'
activesupport (3.0.6) lib/active_support/dependencies.rb:482:in `load_missing_constant'
activesupport (3.0.6) lib/active_support/dependencies.rb:183:in `const_missing'
activesupport (3.0.6) lib/active_support/dependencies.rb:181:in `each'
activesupport (3.0.6) lib/active_support/dependencies.rb:181:in `const_missing'
activerecord (3.0.6) lib/active_record/relation.rb:370:in `send'
activerecord (3.0.6) lib/active_record/relation.rb:370:in `method_missing'
activerecord (3.0.6) lib/active_record/relation.rb:125:in `scoping'
activerecord (3.0.6) lib/active_record/relation.rb:370:in `method_missing'
class Category < ActiveRecord::Base
has_many :tickets
has_many :tasks, :dependent => :destroy
accepts_nested_attributes_for :tasks, :reject_if => lambda { |a| a[:name].blank? }, :allow_destroy => true
acts_as_tree
has_friendly_id :name, :use_slug => true
scope :parent, where({:parent_id => nil}, {})
scope :children, where({'parent_id > ?', 0}, {})
@marclipovsky
marclipovsky / gist:1186122
Created September 1, 2011 13:04
Scopes Causing undefined method `const_defined?'
activemodel (3.0.6) lib/active_model/attribute_methods.rb:367:in `method_missing'
activerecord (3.0.6) lib/active_record/attribute_methods.rb:46:in `method_missing'
activesupport (3.0.6) lib/active_support/dependencies.rb:372:in `local_const_defined?'
activesupport (3.0.6) lib/active_support/dependencies.rb:497:in `load_missing_constant'
activerecord (3.0.6) lib/active_record/relation.rb:98:in `any?'
activerecord (3.0.6) lib/active_record/attribute_methods/read.rb:72:in `any?'
activerecord (3.0.6) lib/active_record/relation.rb:98:in `each'
activerecord (3.0.6) lib/active_record/relation.rb:98:in `any?'
activerecord (3.0.6) lib/active_record/relation.rb:98:in `any?'
activesupport (3.0.6) lib/active_support/dependencies.rb:497:in `load_missing_constant'
@marclipovsky
marclipovsky / gist:1186408
Created September 1, 2011 15:22
nested_forms creating default tasks from category tasks
<!-- START category.rb -->
class Category < ActiveRecord::Base
has_many :tickets
has_many :tasks
accepts_nested_attributes_for :tasks, :allow_destroy => true, :reject_if => proc { |obj| obj.blank? }
end
<!-- END category.rb -->
<!-- START ticket.rb -->
class Ticket < ActiveRecord::Base
<div id="add_default_tasks">
<h2>Default Tasks</h2>
<div class="fields">
<input id="ticket_tasks_attributes_0_name" name="ticket[tasks_attributes][0][name]" size="30" type="text" value="Create Invite" />
<input id="ticket_tasks_attributes_0__destroy" name="ticket[tasks_attributes][0][_destroy]" type="hidden" value="false" /><a href="javascript:void(0)" class="remove_task remove_nested_fields">Remove this task</a>
<input id="ticket_tasks_attributes_0_name" name="ticket[tasks_attributes][0][name]" size="30" type="text" value="Name Tags" />
<input id="ticket_tasks_attributes_0__destroy" name="ticket[tasks_attributes][0][_destroy]" type="hidden" value="false" /><a href="javascript:void(0)" class="remove_task remove_nested_fields">Remove this task</a>
<input id="ticket_tasks_attributes_0_name" name="ticket[tasks_attributes][0][name]" size="30" type="text" value="Giveaways" />
<input id="ticket_tasks_attributes_0__destroy" name="ticket[tasks_attributes][0][_destroy]" type="hidden"
@marclipovsky
marclipovsky / gist:2241307
Created March 29, 2012 18:11
scope creating array rather than activerecord::relation
scope :for_account, lambda { |account|
find_by_sql("SELECT 'tickets'.* FROM 'tickets'
INNER JOIN 'groups' ON 'groups'.'id' = 'tickets'.'group_id'
INNER JOIN 'assignments' ON 'groups'.'id' = 'assignments'.'group_id'
INNER JOIN 'accounts' ON 'accounts'.'id' = 'assignments'.'account_id'
WHERE ('accounts'.'id' = #{account.id})
UNION
SELECT 'tickets'.* FROM 'tickets'
INNER JOIN 'tasks' ON 'tasks'.'ticket_id' = 'tickets'.'id'
INNER JOIN 'accounts' ON 'accounts'.'id' = 'tasks'.'account_id'
FFFFFFF
Failures:
1) Person merging two people should return the winner
Failure/Error: @result = Person.merge(@winner, @loser)
NoMethodError:
undefined method `merge' for #<Class:0x007f8c3c3fb888>
# /Users/macuser/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.3/lib/active_record/dynamic_matchers.rb:50:in `method_missing'
# /Users/macuser/Sites/forked gems/people/spec/models/person_spec.rb:15:in `block (3 levels) in <top (required)>'
@marclipovsky
marclipovsky / .bash_profile
Created September 6, 2012 19:10
Include branch name (and other info) in my bash prompt
# Get's the current git branch
function parse_git_branch
{
ref=$(git symbolic-ref HEAD 2> /dev/null) || return
echo "("${ref#refs/heads/}")"
}
# Checks to see if there are uncommitted files
function git_status
{
@marclipovsky
marclipovsky / scss.rb
Created October 22, 2012 03:52
SCSS HAML Filter
# encoding: UTF-8
module Haml::Filters
module Scss
include Base
lazy_require 'sass/plugin'
def render (text)
"<style>\n/*<![CDATA[*/\n" + ::Sass::Engine.new(text, ::Sass::Plugin.engine_options.merge(syntax: :scss)).render + "\n/*]]>*/\n</style>"
end