Skip to content

Instantly share code, notes, and snippets.

View supairish's full-sized avatar
🏂
Shreddin

Chris Irish supairish

🏂
Shreddin
View GitHub Profile
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'
}
function proml {
local BLUE="\[\033[0;34m\]"
local RED="\[\033[0;31m\]"
local LIGHT_RED="\[\033[1;31m\]"
local GREEN="\[\033[0;32m\]"
local LIGHT_GREEN="\[\033[1;32m\]"
@supairish
supairish / gist:819adda554dd757aa492
Created September 7, 2014 20:14
Far future expires headers for Rails assets
location ~ ^/assets/ {
expires 1y;
add_header Cache-Control public;
add_header ETag "";
break;
}

Goals of this tutorial:

  • deploy a new Rails app with capistrano
  • make it fast (total process takes less than 5 minutes)
  • make it simple (no unecessary config)
  • manual ssh to the server not required

Rails application stack:

  • nginx
  • unicorn
  • postgresql
# e.g.:
# @user.should have_ability(:create, for: Post.new)
# @user.should have_ability([:create, :read], for: Post.new)
# @user.should have_ability({create: true, read: false, update: false, destroy: true}, for: Post.new)
RSpec::Matchers.define :have_ability do |ability_hash, options = {}|
match do |user|
ability = Ability.new(user)
target = options[:for]
@ability_result = {}
ability_hash = {ability_hash => true} if ability_hash.is_a? Symbol # e.g.: :create => {:create => true}
# in test.rb
require Rails.root.join('config/initializers/diagnostic')
config.middleware.use(MyApp::DiagnosticMiddleware)
# config/initializers/diagnostic.rb
module MyApp
class DiagnosticMiddleware
FILENAME = 'log/diagnostic.log' unless defined? FILENAME
Hey!
Here is what I currently use:
Put this in your application helper:
def image_assets
image_asset_dir = Rails.root.join('app', 'assets', 'images')
assets = {}
@supairish
supairish / ember_deploy.sh
Last active September 14, 2015 17:07 — forked from skwp/ember_deploy.sh
#!/bin/bash
# Fail if any commands fail
set -e
set -o pipefail
# These are ec2 tags from which we will determine where to deploy
ec2_stage=$DEPLOY_STAGE
ec2_app="core"
ec2_role="app"
@supairish
supairish / gist:1033379
Created June 18, 2011 18:32 — forked from bgkittrell/gist:704674
Reorder Multiple Elements ala Netflix
images = @album.image_assignments
changed = Array.new
# Get the images that changed order
for image in images
order = params["order_#{image.image_id}".to_sym]
if !order.blank? && order =~ /^\d+$/ && image.position.to_i != order.to_i
image.position = order.to_i
changed << image
@supairish
supairish / gist:1330161
Created November 1, 2011 08:37
Retryable method
# Options:
# * :tries - Number of retries to perform. Defaults to 1.
# * :on - The Exception on which a retry will be performed. Defaults to Exception, which retries on any Exception.
#
# Example
# =======
# retryable(:tries => 1, :on => OpenURI::HTTPError) do
# # your code here
# end
#
@supairish
supairish / gist:1521680
Created December 26, 2011 17:25 — forked from parndt/gist:1011435
How to cache pages and clear them in Refinery CMS
# put in config/application.rb
config.to_prepare do
::PagesController.module_eval do
caches_page :show, :unless => proc {|c| c.user_signed_in? || c.flash.any? }
caches_page :home, :unless => proc {|c| c.user_signed_in? || c.flash.any? }
end
::Page.module_eval do
after_save :clear_static_caching!
after_destroy :clear_static_caching!