This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Event < ApplicationRecord | |
# Before | |
def cateorized? | |
event.category.present? ? event.category.name != 'none' : false | |
end | |
# Refactor - simplify with Null test with AND operator | |
def categorized? | |
event.category && event.category != 'none' | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Before | |
class CustomQuery | |
def levels | |
@levels ||= { 'a' => :low, 'b' => :med, 'c' => :high } | |
end | |
def current(level) | |
levels.each_with_index { |avail_level, index| return avail_level[index] if level == avail_level[index] } | |
:low | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'barge' | |
require 'delegate' | |
class DigitalOcean | |
attr_reader :client, :droplets, :sizes | |
def initialize | |
@client = Barge::Client.new(access_token: ENV['DO_KEY']) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- Get gist XXXXX and add to clipboard. > | |
:Gist -c XXXXX | |
< |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# .inputrc | |
set editing-mode vi | |
# http://nocruft.com/post/22528784313/avoiding-the-esc-key-in-vim-and-readline | |
$if mode=vi | |
set keymap vi-command | |
"ii": vi-insertion-mode | |
set keymap vi-insert | |
"jk": vi-movement-mode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'descriptive-statistics' | |
class StdDev | |
attr_reader :stats | |
def initialize(dataset) | |
# comment | |
@stats = DescriptiveStatistics::Stats.new(dataset) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
spec_hits = [] | |
# Find the names of all the filenames in spec directory that have been (A)dded (C)opied or (M)odified | |
filenames = `git diff --cached --name-only --diff-filter=ACM`.split("\n") | |
filenames.each do |filename| | |
if filename.end_with? '_spec.rb' | |
results = `git diff --cached #{filename} | grep \^+\[\^+\] | grep focus` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ActsAsDtg | |
def acts_as_dtg(*attributes) | |
attributes.each do |attribute| | |
dtg_attribute = "#{attribute}_dtg" | |
attr_reader dtg_attribute | |
define_method("#{dtg_attribute}=") do |val| | |
instance_variable_set("@#{dtg_attribute}", val) | |
puts "#{dtg_attribute} was set" | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
spec_hits = [] | |
# Find the names of all the filenames in spec directory that have been (A)dded (C)opied or (M)odified | |
filenames = `git diff --cached --name-only --diff-filter=ACM spec`.split("\n") | |
filenames.each do |filename| | |
# Filter all the additions to this file, find if they contain `focus: true` or `:focus => true` and store these lines without the initial `+` and spaces | |
results = `git diff --cached #{filename} | grep \^+\[\^+\] | grep focus` |
NewerOlder