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 / Get Previous Route in Rails
Last active March 30, 2023 05:06
Get Previous Route in Rails 3/4+ App
ApplicationController < ActionController::Base
after_filter :set_route_info
def set_route_info
session[:return_to] = request.url
prev_route = Rails.application.routes.recognize_path(URI(session[:return_to]).path)
session[:previous_controller] = prev_route[:action]
@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 / 1 static_rails.rb
Last active March 30, 2023 05:03 — forked from WattsInABox/.gitignore
Generate Static HTML Website Using Ruby on Rails
# config/environments/static.rb
require File.expand_path('../development', __FILE__)
# environment for serving static pages like error pages to upload to S3
MyApp::Application.configure do
config.serve_static_assets = true
# Compress JavaScripts and CSS
config.assets.compress = true
@westonganger
westonganger / postgresql_fdw_with_activerecord_and_rails.md
Last active November 16, 2023 04:25
Postgresql FDW with ActiveRecord and Rails

Source Article (See for latest changes): https://westonganger.com/posts/using-postgresql-fdw-with-activerecord-and-rails

If you want to do some cross database joins or includes across postgresql databases regardless of local or remote databases you can use Postgres FDW. Its an awesome tool for the job when you want to avoid data replication.

Base Postgresql FDW Model:

class PostgresFdwBase < ApplicationRecord

  ### Article to familiarize with concepts in this models methods - https://thoughtbot.com/blog/postgres-foreign-data-wrapper
@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