Skip to content

Instantly share code, notes, and snippets.

# This custom version of the authenticate method allows the user to use login or email as unique keys.
# Please note that if using this method it's highly recommended that you make the email property, of the user model, a required one.
# Also consider adding a unique index to the email field. For that create a migration with: add_index :users, :email, :unique => true
# It's equally advisable to remove the nullable option from the email field.
def self.authenticate(login, password)
return nil if login.blank? || password.blank?
u = find :first, :conditions => ['(email = ? OR login = ?) and activated_at IS NOT NULL', login, login] # need to get the salt
u && u.authenticated?(password) ? u : nil
end
# Adapted for Rspec2. This won't work in RSpec 1.
# Put this code in acceptance_helper.rb or better in a new file spec/acceptance/support/javascript.rb
Rspec.configure do |config|
config.before(:each) do
Capybara.current_driver = :selenium if example.metadata[:js]
end
config.after(:each) do
@cavalle
cavalle / warden.rb
Created August 25, 2010 10:46
Testing Warden/Devise with Steak
# Create a file `spec/acceptance/support/warden.rb' with the following
# contents:
Spec::Runner.configure do |config|
config.include Warden::Test::Helpers, :type => :acceptance
config.after(:each, :type => :acceptance) { Warden.test_reset! }
end
# Or, if you're using RSpec 2 / Rails 3, the contents should be the following
# instead:
@natesilva
natesilva / markdown.vim
Created May 6, 2011 23:44
Vim: Preview a Markdown document in the default browser on Windows or Mac OS X
"
" While editing a Markdown document in Vim, preview it in the
" default browser.
"
" Author: Nate Silva
"
" To install: Place markdown.vim in ~/.vim/ftplugin or
" %USERPROFILE%\vimfiles\ftplugin.
"
" To use: While editing a Markdown file, press ',p' (comma p)
@paulmars
paulmars / gist:1375125
Created November 18, 2011 00:44
Quiet Assets for Rails
Source:
http://stackoverflow.com/questions/6312448/how-to-disable-logging-of-asset-pipeline-sprockets-messages-in-rails-3-1
mate config/initializers/quiet_assets.rb
Paste:
Rails.application.assets.logger = Logger.new('/dev/null')
Rails::Rack::Logger.class_eval do
def call_with_quiet_assets(env)
previous_level = Rails.logger.level
@benfyvie
benfyvie / object_diagnostics.rb
Created December 22, 2011 17:30 — forked from eric/object_diagnostics.rb
Tools for debugging memory bloat using Ruby's built in ObjectSpace
module ObjectDiagnostics
extend self
#This is handy when you want to determine what types of objects are contributing to memory bloat
#returns the change in object counts since the last time this method was called
def change_in_object_counts
#this will start all counts at 0 for the initial run
@previous_counts ||= Hash.new(0)
@burke
burke / 0-readme.md
Created January 27, 2012 13:44 — forked from funny-falcon/cumulative_performance.patch
ruby-1.9.3-p327 cumulative performance patch for rbenv

ruby-1.9.3-p327 cumulative performance patch for rbenv

This installs a patched ruby 1.9.3-p327 with various performance improvements and a backported COW-friendly GC, all courtesy of funny-falcon.

Requirements

You will also need a C Compiler. If you're on Linux, you probably already have one or know how to install one. On OS X, you should install XCode, and brew install autoconf using homebrew.

@timbogit
timbogit / eigenclasses.rb
Created March 8, 2012 05:19
Musing on the Ruby object model in Ruby 1.8.7 vs. 1.9.3
obj = Object.new
puts "obj is #{obj}"
eigobj = class << obj
self
end
puts "Eigenclass of obj is #{eigobj}"
puts "Superclass of the eigenclass of obj is #{eigobj.superclass}"
eigclassobj = class << obj.class
@eLafo
eLafo / install.txt
Last active July 5, 2021 14:25
My install notes for ubuntu. Must be reviewed, but in the meanwhile... it's ok for me
# Update System
# ------------------------------------------------------------------------------
echo 'Updating System...'
sudo apt-get -y update
# Hardware
# ------------------------------------------------------------------------------
echo 'Installing bumblebee'
sudo add-apt-repository -y ppa:bumblebee/stable && sudo apt-get update
sudo apt-get -y install bumblebee bumblebee-nvidia
@carlossanchezp
carlossanchezp / gist:6103569
Created July 29, 2013 10:53
mi ~/.gitconfig
[merge]
tool = meld
[clolor]
ui = true
[color]
branch = auto
status = auto
[color "branch"]
current = yellow reverse
local = yellow