Skip to content

Instantly share code, notes, and snippets.

View zachinglis's full-sized avatar

Zach Inglis zachinglis

View GitHub Profile
def self.authenticate(login, password)
return nil if login.blank? or password.blank?
# need to get the salt
if login.match("@")
user = find_in_state :first, :active, :conditions => { :email => login}
else
user = find_in_state :first, :active, :conditions => { :login => login}
end
## django
from django.contrib.auth.models import User
from django.core.validators import email_re
class BasicBackend:
def get_user(self, user_id):
try:
return User.objects.get(pk=user_id)
except User.DoesNotExist:
@zachinglis
zachinglis / unobtrusive_put_post_links.js
Created August 21, 2008 19:49
Unobtrusively have put and post links
// Examples:
//
// button_to "Mark as unread", mark_as_unread_message_path(message), :method => :put, :class => "form_to_link"
// button_to "New Alert", new_alert
//
jQuery(document).ready(function($) {
var form_to_link = jQuery('.form_to_link');
var form = form_to_link.parents('form');
form.after('<a href="' + form.attr('action') + '" class="button_link_to">' + form_to_link.attr('value') + '</a>');
form.hide();
>> Business.search(:conditions => { :state => "paid" }).length
=> 20
>> Business.find_all_by_state("paid").length
=> 321
Interesting.