Skip to content

Instantly share code, notes, and snippets.

View westonganger's full-sized avatar

Weston Ganger westonganger

View GitHub Profile
npm_global_path = File.join(system("npm config get prefix"), "lib/node_modules")
file_name = File.join(npm_global_path, "ionic/lib/tasks/cliTasks.js")
File.open(file_name, 'r+') do |f|
orig_str = "'--splash|-s': {"
str = "'--ignore-cache|-c': { title: 'Ignoring cached resources', boolean: true },#{orig_str}"
f.write File.read(file_name).gsub(orig_str, str)
end
file_name = File.join(npm_global_path, "ionic/node_modules/ionic-app-lib/lib/resources.js")
@westonganger
westonganger / or_scopes.rb
Created May 27, 2016 01:19 — forked from craigweston/or_scopes.rb
OR'ing scopes
module ActiveRecord
module Querying
delegate :or, :to => :all
end
end
module ActiveRecord
module QueryMethods
# OrChain objects act as placeholder for queries in which #or does not have any parameter.
# In this case, #or must be chained with any other relation method to return a new relation.
@westonganger
westonganger / rbenv-install-system-wide.sh
Created June 8, 2016 16:41 — forked from jpfuentes2/rbenv-install-system-wide.sh
CentOS: rbenv install and system wide install
#!/bin/bash
# CentOS rbenv system wide installation script
# Forked from https://gist.github.com/1237417
# Installs rbenv system wide on CentOS 5/6, also allows single user installs.
# Install pre-requirements
yum install -y gcc-c++ patch readline readline-devel zlib zlib-devel libyaml-devel libffi-devel openssl-devel \
make bzip2 autoconf automake libtool bison iconv-devel git-core
@westonganger
westonganger / file_uploader
Created February 10, 2017 17:53
CarrierWave Uploader thats Compatible with Paperclip fields
class FileUploader < CarrierWave::Uploader::Base
### This uploader is setup for paperclip compatibility
include CarrierWave::MiniMagick
storage :file
def store_dir
"system/#{model.class.to_s.pluralize.underscore}/#{mounted_as.to_s.pluralize}/#{model_id_partition}"
end
@westonganger
westonganger / How to successfully Throttle or use ignore_if option for exception_notification gem for Rails
Last active August 30, 2021 17:36
How to successfully Throttle or use ignore_if option for exception_notification gem for Rails
### HOW TO IMPLEMENT EXCEPTION THROTTLING WITH EXCEPTION NOTIFIER FOR RAILS
###
### Documentation for Exception Notification: https://github.com/smartinez87/exception_notification
### SETUP VARIABLES
cache_key = "exception_times"
if ["development", "test"].include?(Rails.env.to_s)
throttle_interval = 0 ### no throttling for dev
else
@westonganger
westonganger / rails-async-job-toggler.rb
Created August 31, 2021 03:49
Rails Async Job Toggler
# if defined?(Sidekiq) || ["", "inline"].exclude?(Rails.application.config.active_job.queue_adapter.to_s)
if Rails.env.development?
ASYNC_JOBS = false ### change temporarily for testing
elsif Rails.env.test?
ASYNC_JOBS = false
else
ASYNC_JOBS = true
end
@westonganger
westonganger / fetch_hash.rb
Created August 31, 2021 03:51
Ruby FetchHash
################################################## FetchHash - ALL VALUE FETCHING OCCURS USING FETCH METHOD WHICH RAISES ERROR IF KEY NOT FOUND
class FetchHash < HashWithIndifferentAccess
def [](k)
self.fetch(k)
end
end
@westonganger
westonganger / ci_string.rb
Created August 31, 2021 03:53
Ruby Case-Insentive Strings
################################################## CIString (Case-Insensitive String) - HELPFUL FOR STRING COMPARISONS WHERE WE NEED TO IGNORE CASE ERRORS
class CIString < String
def initialize(*args)
if args[0].nil?
args[0] = ""
end
super
end
def ==(val)
val.is_a?(String) ? self.casecmp?(val) : false
@westonganger
westonganger / custom_i18n_exception_handler.rb
Created August 31, 2021 03:56
Rails I18n Exception Handler
### CUSTOM I18N EXCEPTION HANDLER
### 1. This exception handler enforces that an exception is raised whenever a translation is not found rather than showing "translation missing" to user
### 2. YOU CAN USE I18n.t(key, fallback: true) and it will now handle missing translations as follows:
###
### If a specific key is used ie. 'fisheries.locations.asd' and the translation is not found then it will look for:
### - 'common.asd'
###
module I18n
@westonganger
westonganger / spec_file_helpers.rb
Created August 31, 2021 03:58
Rails Test/Spec File Helpers
def create_tempfile(str_data, file_name: nil)
file_basename = file_name.to_s.split('.').first || "Example File"
file_ext = file_name.to_s.split('.').last || "csv"
### Must seperate basename and extension to array for tempfile new syntax
### https://ruby-doc.org/stdlib-3.0.2/libdoc/tempfile/rdoc/Tempfile.html#method-c-new
tmp_file = Tempfile.new([file_basename, ".#{file_ext}"], binmode: true)
tmp_file << str_data