Skip to content

Instantly share code, notes, and snippets.

How to customize the humanized :category symbol in the generated error message. Tested with Rails 4.1

class Listing < ActiveRecord::Base    
  validate :premium_category

  private

 def premium_category
sum = 0
[106.90, 106.90, 106.90, 106.90, 106.90, 106.90].each do |l|
sum += l
p sum
end
# Output
# 106.9
# 213.8
# 320.70000000000005
class MethodLogger
def log_method(klass, method_name)
klass.class_eval do
alias_method "#{method_name}_original", method_name
define_method method_name do |*args, &block|
puts "Called #{method_name}"
send "#{method_name}_original", *args, &block
end
end
end
@trev
trev / brain.md
Last active August 29, 2015 14:13
Brain

Linux (Ubuntu)

Commands/Actions

$ visudo
# This allows user to sudo but prompts for password
dog ALL=(ALL:ALL) ALL
@trev
trev / chruby_pow.md
Last active August 29, 2015 14:24
Starting a new Rails application on Mac OSX 10.10 using chruby + POW
source /usr/local/share/chruby/chruby.sh
chruby $(cat .ruby-version)
  • Generate the rails app skeleton: $ rails new my_billion_dollar_app
  • Link it up to pow: $ ln -s ~/Sites/my_billion_dollar_app ~/.pow/.
@trev
trev / WSO2.2.php
Created December 14, 2011 23:11
WSO 2.2
/*ef665ac560d2043d7dee9ac1f8907182ef665ac560d2043d7dee9ac1f8907182ef665ac560d2043d7dee9ac1f8907182ef665ac560d2043d7dee9ac1f8907182ef665ac560d2043d7dee9ac1f8907182ef665ac560d2043d7dee9ac1f8907182ef665ac560d2043d7dee9ac1f8907182ef665ac560d2043d7dee9ac1f8907182ef665ac560d2043d7dee9ac1f8907182ef665ac560d2043d7dee9ac1f8907182ef665ac560d2043d7dee9ac1f8907182ef665ac560d2043d7dee9ac1f8907182ef665ac560d2043d7dee9ac1f8907182ef665ac560d2043d7dee9ac1f8907182ef665ac560d2043d7dee9ac1f8907182ef665ac560d2043d7dee9ac1f8907182ef665ac560d2043d7dee9ac1f8907182ef665ac560d2043d7dee9ac1f8907182ef665ac560d2043d7dee9ac1f8907182ef665ac560d2043d7dee9ac1f8907182ef665ac560d2043d7dee9ac1f8907182ef665ac560d2043d7dee9ac1f8907182ef665ac560d2043d7dee9ac1f8907182ef665ac560d2043d7dee9ac1f8907182ef665ac560d2043d7dee9ac1f8907182ef665ac560d2043d7dee9ac1f8907182ef665ac560d2043d7dee9ac1f8907182ef665ac560d2043d7dee9ac1f8907182ef665ac560d2043d7dee9ac1f8907182ef665ac560d2043d7dee9ac1f8907182ef665ac560d2043d7dee9ac1f8907182ef665ac560d2043d7dee9ac1f89071
@trev
trev / prepdev.rb
Created January 19, 2012 05:00
Prepdev
#!/usr/bin/env ruby
# A script to setup a PHP dev. environment on a local MacOSX 10.6.8+ machine
require 'optparse'
# This hash will hold all of the options
# parsed from the command-line by
# OptionParser.
options = {}
optparse = OptionParser.new do |opts|
@trev
trev / filter.phtml
Created April 13, 2012 06:11
Magento Color Attribute Swatches Implementation
<ol>
<?php foreach ($this->getItems() as $_item): ?>
<li>
<?php if ($_item->getCount() > 0): ?>
// Add attribute option image before label
<?php if($_item->getName() == "Color") : ?>
<img src="<?php echo Mage::helper('attributeoptionimage')->getAttributeOptionImage($_item->getValue()); ?>" alt="" />
<?php endif; ?>
<a href="<?php echo $this->urlEscape($_item->getUrl()) ?>"><?php echo $_item->getLabel() ?></a>
<?php else: echo $_item->getLabel() ?>
@trev
trev / jquery_plugin_pattern.js
Created August 18, 2012 07:38
Lightweight jQuery Plugin Pattern
/*!
* jQuery lightweight plugin boilerplate
* Original author: @ajpiano
* Further changes, comments: @addyosmani
* Licensed under the MIT license
*/
// the semi-colon before the function invocation is a safety
// net against concatenated scripts and/or other plugins
@trev
trev / datecompare.js
Created September 4, 2012 04:50
Date comparison function
// How to refactor this bitch?
var dateCompare = function(date1, date2, operator) {
if(operator === ">") return date1.getTime() > date2.getTime();
if(operator === "<") return date1.getTime() < date2.getTime();
if(operator === "==") return date1.getTime() == date2.getTime();
//And so on and so forth with the other operators (>=, <=)
}
// Different approach but moves the conditional logic out