Skip to content

Instantly share code, notes, and snippets.

View caseyprovost's full-sized avatar
🏠
Working from home

Casey Provost caseyprovost

🏠
Working from home
View GitHub Profile
Thor::Base.shell = Thor::Shell::Color
require 'yaml'
require 'rails/version'
RAILS6 = Rails::VERSION::MAJOR == 6
def truthy?(statement)
val = ask(statement)
['y', 'yes', ''].include?(val)
end
class User < ApplicationRecord
has_many :todo_lists
def self.set_current_user(id)
@_current_user = find(id)
end
# Avoid a DB query each time we need the currently logged in user
def self.current_user
@_current_user
@caseyprovost
caseyprovost / simple_code.rb
Created July 31, 2019 00:01
An example of good code
def extract_emails_from_mailing_list(mailing_list)
mailing_list.entries.map(&:email).keep_if(&:present)
end
@caseyprovost
caseyprovost / income_report_query_spec.rb
Last active July 1, 2019 01:05
RSpec test for query object
require 'rails_helper'
RSpec.describe IncomeReportQuery do
let!(:user) { create(:user) }
describe '#resolve' do
let(:test_scope) { instance_double(ActiveRecord::Relation) }
let(:result) { query.resolve }
context 'filtering by nothing' do
class FamilyRegistrationForm
include ActiveModel::Model
attribute_reader :user
attribute_reader :relative
attribute :user_email, String
attribute :user_name, String
attribute :relative_email, String
attribute :relative_name, String
Verifying my Blockstack ID is secured with the address 12tucjxEQNZo8qZTFXsYir4CJuXXxVetio https://explorer.blockstack.org/address/12tucjxEQNZo8qZTFXsYir4CJuXXxVetio
class User < ApplicationRecord
attr_accessor :from_comic_con_campaign
validates :twitter_username, presence: true, if: -> { from_comic_con_campaign }
validates :d_and_d_handle, presence: true, if: -> { from_comic_con_campaign }
validates :password, presence: true, confirmation: true
validates :first_name, :last_name, :email, presence: true
validates :email, format: { with: /@/, message: "is invalid" }
end
def parse_token(token)
return nil if token.nil?
if token.match(/[2, 4, 6, 8]/)
1
else
0
end
end
sql_time_query_mapping = {
:hour => 'HOUR',
:day => 'DATE',
:week => 'YEARWEEK',
:moth => 'MONTH'
}