Skip to content

Instantly share code, notes, and snippets.

View bigfive's full-sized avatar

Jonathan Williams (jdub) bigfive

  • Envato
  • Perth, Australia
View GitHub Profile
@bigfive
bigfive / _manifest.html.erb
Created December 1, 2014 04:52
Rails 3 javascript asset path method
<script>
<% if File.exists? Rails.root.join('public/assets/manifest.yml') %>
window.railsAssetManifest = <%= raw YAML.load_file(Rails.root.join('public/assets/manifest.yml')).to_json %>;
<% else %>
window.railsAssetManifest = {};
<% end %>
window.railsAssetPath = function(assetName){
result = (!!window.railsAssetManifest[assetName] ? window.railsAssetManifest[assetName] : assetName);
return ('/assets/' + result);
@bigfive
bigfive / gist:68719b29456213e5d244
Last active August 29, 2015 14:07
Push release/hotfix branch to origin remote. Checks if any orphan commits on target
function fpushrel () {
# Assertion: At least one arg
if [ -z $1 ]; then
echo "ERROR: Please provide a branch to push (eg staging/production)"; return
fi
# Assertion: No uncommited changes
if ! [ $(git status -s | wc -l) -eq 0 ]; then
echo "ERROR: You have changes that have not been committed"; return
fi
@bigfive
bigfive / scss_color_extractor.rb
Last active August 29, 2015 14:03
Genreate report on possible duplicate and missing scss color vars
require 'scss_lint'
module SassExtractor
mattr_accessor :color_var_nodes
mattr_accessor :color_nodes
self.color_var_nodes = []
self.color_nodes = []
module Vistors
class VariableGatherer < SCSSLint::Linter
@bigfive
bigfive / database.yml
Created April 1, 2014 03:53
Magnum CI example db config
core: &core
adapter: postgresql
host: 127.0.0.1
username: postgres
database: magnum<%= ENV['TEST_ENV_NUMBER'] %>
development:
<<: *core
test:
<<: *core
@bigfive
bigfive / deploy_local_assets.rb
Last active August 29, 2015 13:56
Capistrano local asset precompile
set :local_path, Dir.pwd
namespace :deploy do
namespace :assets do
desc 'Run asset procompilation locally'
task :precompile_locally, :roles => :web, :except => {:no_release => true} do
run_locally("bundle exec rake assets:precompile")
end
@bigfive
bigfive / deploy.rb
Last active August 29, 2015 13:56
Remove Digests from rails 4 assets
namespace :deploy do
namespace :assets do
task :remove_digests do
run %( cd #{latest_release} && bundle exec rake assets:remove_digests RAILS_ENV=#{rails_env}), :once => true
end
end
end
after 'deploy:assets:precompile', 'deploy:assets:remove_digests'
@bigfive
bigfive / association_counter.rb
Last active August 29, 2015 13:56
count_sql_for
module AssociationCounter
def count_sql_for(association_sym)
association_table_name = reflect_on_association(association_sym).klass.table_name
select("count(#{association_table_name}.id) as #{association_sym}_count").joins(association_sym).to_sql
end
end
ActiveRecord::Base.send(:extend, AssociationCounter)
@bigfive
bigfive / example_mailer_spec.rb
Created January 7, 2014 08:14
ActionMailer RSpec helpers. Makes mailer test more similar to controller tests in that you can test that instance variables are assigned for rendering
require "spec_helper"
describe ExampleMailer do
describe :new_user do
let(:user) { FactoryGirl.create :user }
it "sends to the correct addresses" do
# :mail is similar to the controller specs 'get', 'post' etc methods
mail :new_user, user
@bigfive
bigfive / application_helper.rb
Last active December 21, 2015 17:08
Tupleize a number.
# app/helpers/application_helper.rb
module ApplicationHelper
def tupleize number
units = {
1 => "single",
2 => "double",
3 => "triple",
4 => "quadruple",
5 => "quintuple",
@bigfive
bigfive / active_admin_helper.rb
Last active November 15, 2018 21:33
Active admin reskin
module ActiveAdminHelper
def admin_arbre_context
@admin_arbre_context ||= Arbre::Context.new(assigns, self)
end
def default_renderer
case controller.send(:resource_class).name
when "ActiveAdmin::Page"
"page"