Skip to content

Instantly share code, notes, and snippets.

View ryenski's full-sized avatar
🎯
Focusing

Ryan Heneise ryenski

🎯
Focusing
  • Austin, TX
View GitHub Profile
@ryenski
ryenski / trackable_model.rb
Created April 27, 2017 14:39
Including the Trackable concern in our ActiveRecord model.
class Message < ApplicationRecord
include Trackable
# ...
end
@ryenski
ryenski / activity.rb
Created April 27, 2017 14:37
An ActiveRecord model that stores the tracked changes for our action auditor.
# == Schema Information
#
# Table name: activities
#
# id :uuid not null, primary key
# user_id :uuid
# tenant_id :uuid
# contact_id :uuid
# trackable_type :string
# trackable_id :uuid
@ryenski
ryenski / trackable.rb
Last active April 27, 2017 14:36
An ActiveSupport concern that adds commit hooks for action auditing.
module Trackable
extend ActiveSupport::Concern
included do
has_many :activities, -> {order("created_at DESC")}, as: :trackable, dependent: :nullify
after_commit :track_activity
before_destroy :track_destroy
end
def track_destroy
@ryenski
ryenski / activity_creator.rb
Last active April 27, 2017 15:18
A service object that takes a trackable object, action, and parameters, and creates an Activity record for action auditing.
class ActivityCreator
def initialize(action, trackable, contact, comment=nil)
@trackable = trackable # the affected object (could be the same as contact)
@action = action # what was done
@comment = comment
@changes = collect_changes
end
def call
@ryenski
ryenski / amount_cents.rb
Last active April 11, 2017 15:51
A simple way to deal with monetary amounts in cents, without using a library
# amount_cents :integer default("0")
def amount=(amount)
amount = amount.gsub(/[^\d\.]/, '').to_f if amount.is_a?(String)
self.amount_cents = amount * 100
end
def amount
amount_cents / 100.0
end
Verifying that "crispinheneise.id" is my Blockstack ID. https://onename.com/crispinheneise
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
rescue_from ActiveRecord::RecordNotFound, :with => :render_404
def render_404
raise "A Page was not found!"
end
end
@ryenski
ryenski / sermons
Created May 2, 2012 18:55
wpcajax.org Sermons
//<![CDATA[
//-----Classes-----
function SermonProperty(data)
{
this.data = data;
this.html = data;
this.compareTo = function(obj)
{
@ryenski
ryenski / gist:1120376
Created August 2, 2011 15:08
catch/throw
marble_jar = 0
count = 0
catch :jar_is_full do
1000000000000.times do |marble|
count += 1
# grab a random-sized marble
marble = rand(9)
<?php
class Push_Highrise{
var $highrise_url = ''; // your highrise url, e.g. http://yourcompany.highrisehq.com
var $api_token = ''; // your highrise api token; can be found under My Info
var $task_assignee_user_id = ''; // user id of the highrise user who gets the task assigned
var $category = ''; // the category where deals will be assigned to
var $errorMsg = "";