Skip to content

Instantly share code, notes, and snippets.

Trevor trev

Block or report user

Report or block trev

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@trev
trev / config.yml
Created May 25, 2018
CircleCI 2.0 with parallelism & simplecov for Rails
View config.yml
# 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
View delegate_singleton.rb
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 Feb 5, 2016
OptimisePrime
View line_item.rb
class LineItem < ActiveRecord::Base
belongs_to :order
has_many :passengers
end
View stuff.haml
= 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 Aug 29, 2015
Starting a new Rails application on Mac OSX 10.10 using chruby + POW
View chruby_pow.md
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/.
View brain.md

Linux (Ubuntu)

Commands/Actions

$ visudo
# This allows user to sudo but prompts for password
dog     ALL=(ALL:ALL) ALL
View method_logger.rb
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
View float_precision.rb
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
View keybase.md

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:

View custom_error_messages.markdown

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
You can’t perform that action at this time.