Skip to content

Instantly share code, notes, and snippets.

View dougc84's full-sized avatar

Doug Clark dougc84

View GitHub Profile
@dougc84
dougc84 / model.rb
Last active July 17, 2017 04:44
Ransack - Polymorphic Associations Search Ransacker
class MyModel < ActiveRecord::Base
belongs_to :owner, polymorphic: true
ransacker :owner_name, formatter: proc { |value|
# To use this, you have to know what all of the possible owner types can be.
# For this example, the #owner_type could be either Group or Advertiser.
# The fields we want to search on are:
# Group#name
# Advertiser#contact_name
#
@dougc84
dougc84 / m-h-stop.png
Last active December 31, 2015 21:39
Harvest Running Image
Replace Harvest.app/Resources/m-h-stop.png with this image
@dougc84
dougc84 / .pryrc
Last active December 28, 2015 11:09
.pryrc
# try requiring and including awesome_print
# if gem is not installed, will simply pass over this.
require "awesome_print"
AwesomePrint.pry! if defined?(AwesomePrint)
#
# output becomes:
#
# [1] app_folder_name development(main)> def something
# 1 > "hello"
@dougc84
dougc84 / 2.0.0-p247-mirror
Created July 11, 2013 04:48
ruby-build package to install Ruby 2.0.0-p247 from mirror
install_package "openssl-1.0.1e" "https://www.openssl.org/source/openssl-1.0.1e.tar.gz#66bf6f10f060d561929de96f9dfe5b8c" mac_openssl --if has_broken_mac_openssl
install_package "ruby-2.0.0-p247" "http://www.mirrorservice.org/sites/ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p247.tar.gz" standard verify_openssl
@dougc84
dougc84 / test_unit.rb
Created June 15, 2013 20:49
shoulda-matchers fix for Rails 4 RC 2
# :enddoc:
require 'test/unit/testcase'
if defined?(ActionController)
require 'shoulda/matchers/action_controller'
class ActionController::TestCase
include Shoulda::Matchers::ActionController
extend Shoulda::Matchers::ActionController
@dougc84
dougc84 / audited.rb
Last active December 10, 2015 06:08
Audited initializer to globally disable audits except when needed.
# Audited initializer to globally disable audits except when needed.
# https://gist.github.com/4392334
#
# Hacked from idea originally provided in issue:
# https://github.com/collectiveidea/audited/issues/18
# by Frost (github.com/Frost)
#
# Modified by Doug Clark (github.com/dougc84)
#
# Add this in an initializer (audited.rb)
@dougc84
dougc84 / home_controller.rb
Created December 13, 2012 23:13
before filter example
class HomeController < ApplicationController
layout 'login'
before_filter :actions_if_signed_in
def index
end
def blocked
end
@dougc84
dougc84 / flush_dns.sh
Created December 10, 2012 19:10
Flush DNS on Mac
#!/bin/bash
sudo killall -HUP mDNSResponder
@dougc84
dougc84 / benchmark_array_functions.rb
Created November 27, 2012 06:50
Array Benchmarking Tests
#!/usr/bin/env ruby
require 'benchmark'
require 'active_support/core_ext/array' # required for Array.wrap.
# by the way, did you know there is a "my_array.fourty_two()" method?
Benchmark.bm do |b|
language = []
100.times do
language << "8foanin"
@dougc84
dougc84 / useful regexes.txt
Last active October 12, 2015 01:27
Useful RegExs
Find HTML Entities
&[^\s]*;