Skip to content

Instantly share code, notes, and snippets.

View igor-alexandrov's full-sized avatar
😀
Ruby, Ruby, Ruby, Ruby... Crystal :)

Igor Alexandrov igor-alexandrov

😀
Ruby, Ruby, Ruby, Ruby... Crystal :)
View GitHub Profile
@igor-alexandrov
igor-alexandrov / gist:1599584
Created January 12, 2012 09:36
AuthLogic controller helpers for multiple sessions
module Application::Controller::Authlogic
def self.included(base)
base.extend Application::Controller::Authlogic::ClassMethods
end
module ClassMethods
end
def current_session(id=nil)
if User.session_ids.include?(id)
@igor-alexandrov
igor-alexandrov / settings.rb
Created December 11, 2011 18:51
Multiple configuration files in SettingsLogic
class Settings < Settingslogic
source "#{Rails.root}/config/application.yml"
if Rails.env == 'development'
namespace 'development-' + Socket.gethostname.gsub(/\W/, '-').gsub(/[-]{2,}/, '-')
else
namespace Rails.env
end
# load local settings
@igor-alexandrov
igor-alexandrov / application_controller.rb
Created August 6, 2010 12:50
DRY up empty controller actions
class Admin::AdminController < ActionController::Base
def self.simple_action(*actions)
actions.each {|action| class_eval("def #{action}; end")}
end
end
@igor-alexandrov
igor-alexandrov / add floor and ceil to Time
Created April 16, 2010 05:33
Add floor() and ceil() methods to Time class
class Time
def ceil(seconds = 60)
Time.at((self.to_f / seconds).ceil * seconds)
end
def floor(seconds = 60)
Time.at((self.to_f / seconds).floor * seconds)
end
end
require 'rainbow'
def log(level, message)
Rails.logger.send level, message.foreground(color_for_level(level))
if RAILS_ENV == 'development'
puts level.to_s.upcase " " message.foreground(color_for_level(level))
end
end
def color_for_level(level)