Skip to content

Instantly share code, notes, and snippets.

Avatar

Charles Maresh zorab47

View GitHub Profile
View postgres_copy_csv.rb
module PostgresCopyCsv
extend ActiveSupport::Concern
module ClassMethods
# Performs a database query to copy results as CSV to an IO object.
#
# CSV is created directly in PostgreSQL with less overhead then written to
# the provided IO object.
#
# Example
@zorab47
zorab47 / active_record_eager_loading_issue_from_same_source.rb
Last active Oct 5, 2016
Reprodusable issue when eager loading relations from the same source
View active_record_eager_loading_issue_from_same_source.rb
begin
require "bundler/inline"
rescue LoadError => e
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
raise e
end
gemfile(true) do
source "https://rubygems.org"
gem "rails", github: "rails/rails"
@zorab47
zorab47 / cache_arbre.rb
Last active Mar 18, 2017
Arbre content caching for ActiveAdmin
View cache_arbre.rb
# Caches Arbre elements in the `Rails.cache`.
#
# Yielding the first time adds to the output buffer regardless of the
# returned value. A cache miss must be handled separately from a hit
# to avoid double rendering.
#
# Returns yielded Arbre on cache miss OR an HTML string wrapped in
# an text node on cache hit.
def cache_arbre(context, *args, &block)
if controller.perform_caching
@zorab47
zorab47 / active_admin_actions.rake
Last active Mar 12, 2016
Rake task to list ActiveAdmin resource and page actions
View active_admin_actions.rake
task :active_admin_actions => :environment do
skip_resources = [ 'Dashboard' ]
namespace = ActiveAdmin.application.namespace(:admin)
pages = namespace.resources.select { |r| r.is_a? ActiveAdmin::Page }
resources = namespace.resources.select { |r| r.respond_to? :resource_class }
resource_actions =
resources.each_with_object({}) do |resource, actions|
View fix-virtualbox-adapters.ps1
# Adaptation of the VMware adapters fix script by Oisin Grehan:
# http://www.nivot.org/post/2008/09/05/VMWareVMNETAdaptersTriggeringPublicProfileForWindowsFirewall.aspx
# see http://msdn2.microsoft.com/en-us/library/bb201634.aspx
#
# *NdisDeviceType
#
# The type of the device. The default value is zero, which indicates a standard
# networking device that connects to a network.
#
View abilities_matcher.rb
# RSpec CanCan matcher.
#
# When testing your user must have an id otherwise a nil foreign key will
# match on new records.
#
# Examples
#
# describe User do
# subject { User.create! }
#
@zorab47
zorab47 / resource_collection_spec.rb
Created Aug 29, 2013
Failing spec for ActiveAdmin::ResourceCollection
View resource_collection_spec.rb
require 'spec_helper'
describe ActiveAdmin::ResourceCollection do
let(:application) { ActiveAdmin::Application.new }
let(:namespace) { ActiveAdmin::Namespace.new(application, :admin) }
context ".add" do
let(:resource) { ActiveAdmin::Resource.new(namespace, AdminUser) }
let(:resource_renamed) { ActiveAdmin::Resource.new(namespace, AdminUser, as: "SuperAdminUser") }
@zorab47
zorab47 / deploy.rb
Created Oct 10, 2012
Capistrano task to precomile assets locally, if necessary
View deploy.rb
namespace :deploy do
namespace :assets do
task :precompile, :roles => :web, :except => { :no_release => true } do
assets_path = File.join(release_path, "public/assets")
assets_empty = capture("ls -x #{assets_path}").length == 0
has_current_release = capture("if [ -d #{current_path} ]; then echo -n \"yes\"; fi") == "yes"
compile_assets = false
@zorab47
zorab47 / offline_template.rb
Created Nov 22, 2011
Offline Template for Rails 2.3.x
View offline_template.rb
# Public: Template to render views outside the context of a controller.
#
# Useful for rendering Rails 2.3.x views in rake tasks or background jobs when a
# controller is unavailable.
#
# Examples
#
# template = OfflineTemplate.new(:users)
# template.render("users/index", :layout => false, :locals => { :users => users })
#
You can’t perform that action at this time.