Skip to content

Instantly share code, notes, and snippets.

@trev
trev / config.yml
Created May 25, 2018 01:23
CircleCI 2.0 with parallelism & simplecov for Rails
# Ruby CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-ruby/ for more details
defaults: &defaults
working_directory: ~/split_app
parallelism: 2
docker:
- image: circleci/ruby:2.5.0-node-browsers
class Server
class << self
delegate :dl_private_key!, to: Figaro.env
SSH_KEY = {
key_data: [ dl_private_key! ],
keys: [], # Required or Net:SSH will search for machine keys
keys_only: true,
}
@trev
trev / line_item.rb
Last active February 5, 2016 05:11
OptimisePrime
class LineItem < ActiveRecord::Base
belongs_to :order
has_many :passengers
end
= simple_form_for @form, wrapper: :booking do |f|
.simple-group
%h3.small-title Your Personal Information
= f.simple_fields_for :line_items do |li|
= li.simple_fields_for :passengers do |pax|
.row
.col-md-12
%h4= "Trip: #{Product.find(li.object.product_id).title}"
%h5= "Tell us about dude ##{pax.index + 1}"
= pax.input :first_name, placeholder: 'Big'
@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 / 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
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
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
@trev
trev / keybase.md
Last active February 13, 2018 03:02

Keybase proof

I hereby claim:

  • I am trev on github.
  • I am trevw (https://keybase.io/trevw) on keybase.
  • I have a public key ASA_MrVzdOD_P5Av12r3MHZGLp63eH1Hgdvld9THynOmaQo

To claim this, I am signing this object:

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