Skip to content

Instantly share code, notes, and snippets.

View joekhoobyar's full-sized avatar

Joe Khoobyar joekhoobyar

View GitHub Profile
@joekhoobyar
joekhoobyar / keybase.md
Created January 26, 2020 23:31
joekhoobyar - keybase.md

Keybase proof

I hereby claim:

  • I am joekhoobyar on github.
  • I am joekhoobyar (https://keybase.io/joekhoobyar) on keybase.
  • I have a public key ASAsyVYPCONPYhLCkU8ZFlbu8QYqU27SO0qnUy49N0VeHAo

To claim this, I am signing this object:

@joekhoobyar
joekhoobyar / infrastructure.tf
Last active August 29, 2015 14:23
Terraform #2493 - Cannot delete due to cycles when using create_before_destroy
provider "aws" {
region = "${var.aws_region}"
}
resource "terraform_remote_state" "mobilecloud" {
backend = "s3"
config {
bucket = "devops-terraform-state"
key = "mobilecloud-deploy-${var.environment}"
region = "${var.aws_region}"
@joekhoobyar
joekhoobyar / model_decorator.rb
Created March 13, 2014 19:13
Dead simple model decorator base class
require 'delegate'
# A suitable base class for defining a model decorator that automatically defines a model_klass
# singleton method, on all subclasses, that returns the model's class.
#
# Caveat: Your subclass name *must* match the following template: <code>"#{model_klass.name}Decorator"</code>
#
# - Example 1: MyModelDecorator # will decorate MyModel
# - Example 2: MyNamespace::MyModelDecorator # will decorate MyNamespace::MyModel
#
require 'date'
# @see https://gist.github.com/joekhoobyar/9235260
class DateValidator < ActiveModel::EachValidator
DEFAULT_FORMAT = '%Y-%m-%d'
# For testing against the current date.
TESTS = [ :future, :past ]
# For comparing against another date.
@joekhoobyar
joekhoobyar / where_exists.rb
Last active August 29, 2015 13:55
ActiveRecord query extension: where_exists(related,*where_params)
module ActiveRecord
module FinderMethods
# This simple class acts as a "stand-in" for your association, enabling us to reuse logic
# in ::ActiveRecord::Associations::AssociationScope.
class ExistingAssociation < Struct.new(:klass, :owner, :reflection)
delegate :interpolate, to: :klass
def initialize klass, related
raise ArgumentError if Hash===related && related.length > 1
@joekhoobyar
joekhoobyar / date_extensions.rb
Last active December 18, 2015 02:08
Date/Time extensions calculating various permutations of dates.
require 'date'
module DateExtensions
WEEKDAYS = { :sunday => 0, :monday => 1, :tuesday => 2, :wednesday => 3,
:thursday => 4, :friday => 5, :saturday => 6 }
# Returns the first weekday of the month.
def first_wday
(wday - day + 1) % 7
@joekhoobyar
joekhoobyar / raw_attributes.rb
Last active December 17, 2015 21:49
A simple ActiveRecord extension for declaring raw attributes (not backed by a database column) that should work with composed_of, associations, etc.
class ActiveRecord::Base
# Defines a shorthand for declaring raw attributes that are not backed by a database column.
#
# Equivalent to manually defining getter/setter/query methods that call read/write/query_attribute,
# but also supports attribute names with characters that are not allowed in normal method names.
# Unlike +attr_accessor+, these attributes should work with +composed_of+, associations, etc.
#
def self.attribute(*names)
names.each do |name|