Skip to content

Instantly share code, notes, and snippets.

View ajtack's full-sized avatar

Andres Jaan Tack ajtack

View GitHub Profile
@ajtack
ajtack / TimeTolerance.py
Created February 7, 2012 08:57
Time Tolerance Comparator
class WithinToleranceOfNow:
def __init__(self, expectation = datetime.utcnow()):
self.expected_time = expectation
def __eq__(self, other):
try:
parsed_time = datetime.utcfromtimestamp(int(other))
difference = abs(parsed_time - self.expected_time)
return (difference.seconds < 10)
except AttributeError as e:
@ajtack
ajtack / webrat_form_method_fix.rb
Created May 19, 2009 14:11
Specifically enables the use of PUT and DELETE verbs in Rails forms. Rails' convention to override browsers' ignorance of these verbs is a hidden input field.
module Webrat
class Form
protected
def form_method
special_method = Webrat::XML.css_search(@element, 'input[name="_method"]').first
unless special_method.nil?
special_method['value']
else
Webrat::XML.attribute(@element, "method").blank? ? :get : Webrat::XML.attribute(@element, "method").downcase
end
@ajtack
ajtack / swapping_login_methods.js
Created May 4, 2009 04:18
Using JQuery, takes any link in the login form of a particular class, automatically converts the text to an ID-able string (e.g. "Phone Number" -> "session_phone_number"), and then shows that div and hides all the others.
$(document).ready(function() {
$('#LoginForm a.login_method_switch').click(function() {
var blockToShow = '#session_' + this.text.toLowerCase().replace(' ', '_');
$('#LoginForm ' + blockToShow).show("slow");
$('#LoginForm .session_login_method:not(' + blockToShow + ')').hide("slow");
});
});