This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def avg_speed | |
avg_speed = Event.sum(:avg_speed,:conditions => {:bike_id => self.id}) | |
event_count = Event.count(:all,:conditions => ["bike_id = ? AND avg_speed > 0",self.id]) | |
(avg_speed > 0)? avg_speed / event_count : 0 | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Emailer < ActionMailer::Base | |
layout "emailer" | |
def simple_user_registration user | |
recipients user.email | |
from Lolita.config.email(:default_from) | |
subject I18n.t("emailer.simple_user_registration.subject") | |
sent_on Time.now | |
@user = user | |
content_type "multipart/alternative" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
aggregate(:twitter, "http://search.twitter.com/search.atom?q=from:gacha") do |doc| | |
(doc/:entry).collect do |item| | |
{ | |
:created_at => (item/:published).inner_html, | |
:value => (item/:content).inner_html | |
} | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Usage: | |
// | |
// simply show it: | |
// $('#content .my_form').overlay().show() | |
// | |
// show with custom CSS options: | |
// $('#content .my_form').overlay().show({width: '500px',opacity: 0.5}) | |
// | |
// hide it: | |
// $('#content .my_form').overlay().hide() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
if [ $(pidof -x Xvfb| wc -w) -eq 0 ]; then | |
Xvfb -ac -screen scrn 1024x768x24 :12.0 > /dev/null 2>&1 & | |
fi | |
export DISPLAY=:12.0 | |
$@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).bind('cbox_complete', function(){ | |
if($('#cboxTitle').height() > 20){ | |
$("#cboxTitle").hide(); | |
$("<div>"+$("#cboxTitle").html()+"</div>").css({color: $("#cboxTitle").css('color')}).insertAfter("#cboxPhoto"); | |
$.fn.colorbox.resize(); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).bind('cbox_complete', function(){ | |
$("#cboxTitle").hide(); | |
$("<div>"+$("#cboxTitle").html()+"</div>").css({color: $("#cboxTitle").css('color')}).insertAfter(".cboxPhoto"); | |
$.fn.colorbox.resize(); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# LOAD RAILS ENV ... | |
def returning(value) | |
yield(value) | |
value | |
end | |
def convert_hash_to_ordered_hash_and_sort(object, deep = false) | |
# from http://seb.box.re/2010/1/15/deep-hash-ordering-with-ruby-1-8/ | |
if object.is_a?(Hash) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Example | |
# mute do | |
# puts "Foo" | |
# end | |
# puts "Bar" | |
# | |
# Only Bar will be printed | |
def mute &block | |
orig_stdout = $stdout | |
$stdout = File.new('/dev/null', 'w') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# used as example https://groups.google.com/d/msg/ruby-capybara/XhDAHGjZSjA/VwiW0-2nOIEJ | |
# IMPORTANT! To do the real simulation you need chrome driver - http://code.google.com/p/selenium/downloads/list, download and add to PATH | |
def tinymce_fill_in name, options = {} | |
if page.driver.browser.browser == :chrome | |
page.driver.browser.switch_to.frame("#{name}_ifr") | |
page.find(:css, '#tinymce').native.send_keys(options[:with]) | |
page.driver.browser.switch_to.default_content | |
else | |
page.execute_script("tinyMCE.get('#{name}').setContent('#{options[:with]}')") | |
end |
OlderNewer