Skip to content

Instantly share code, notes, and snippets.

View michiels's full-sized avatar

Michiel Sikkes michiels

View GitHub Profile
@michiels
michiels / organizations_controller_before.rb
Created December 28, 2012 15:53
Before code for OrganizationsController
class OrganizationsController < ApplicationController
def show
@notification = notification_for_current_user
@categories = Category.top_level
@category = nil
if params[:category_id]
@michiels
michiels / product_sortable_listing.rb
Created December 28, 2012 15:57
Refactored sortable code into concern
module ProductSortableListing
extend ActiveSupport::Concern
private
def sort_products_from_params(products)
if params[:sort] == "product_name"
if params[:direction] == "desc"
products = products.order("products.name desc")
else
class OrganizationsController < ApplicationController
include ProductSortableListing
def show
@notification = notification_for_current_user
@categories = Category.top_level
@category = nil
@michiels
michiels / find_or_initialize_by.rb
Created January 15, 2013 11:31
So is this the new way of doing find_or_initialize_by?
user = User.where(email: row['email']).first || User.new(email: row['email'])
@michiels
michiels / deploy.rb
Created August 21, 2013 14:15
Don't allow someone to deploy a feature branch when there's already one active
if ENV['BRANCH']
before "deploy", "deploy:check_branch"
end
after "deploy:finalize_update", "deploy:put_branch"
namespace :deploy do
task :check_branch do
current_branch = capture("cat #{current_path}/BRANCH; true")
class Metric
attr_accessor :reason
end
class MetricsLoader
def self.load
file = File.open(Rails.root.join('app','metrics.rb'), 'r')
contents = file.read
class DashboardMetrics < MetricsDefinition
metric "github stargazers" do |m|
m.reason = "Hallo!"
m.fetch_with do
5
end
end
class Organization
has_many :organization_histories
history_methods = [
:coc_number,
:coc_office
]
history_methods.each do |method|
{
"run_list":["role[mysql]","role[rails]"],
"mysql": {
"server_debian_password": "our_secret_debian_password",
"server_root_password": "our_secret_root_password",
"server_repl_password": "our_secret_repl_password",
},
"authorization": {
"sudo": {
"users": ["intercity"],
@michiels
michiels / deploy.rb
Last active January 4, 2016 18:59
Capistrano deploy.rb for Intercity
require 'bundler/capistrano'
set :application, ">> set application name <<"
set :repository, ">> change to your Git repository <<"
set :ssh_options, { forward_agent: true }
set :default_run_options, { pty: true }
set :user, "deploy"
set :use_sudo, false
set :default_environment, {
"PATH" => "/opt/rbenv/shims:/opt/rbenv/bin:$PATH"