Skip to content

Instantly share code, notes, and snippets.

View gacha's full-sized avatar

Gatis Tomsons gacha

  • eazyBI
  • Ventspils, Latvia
View GitHub Profile
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
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"
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
@gacha
gacha / overlay.js
Created July 22, 2010 05:25
overlay your form while Ajax in progress
// 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()
@gacha
gacha / headless
Last active September 24, 2015 08:58
With this you can run cucumber with selenium without seeing browser window. Add it to PATH and chmod +x
#!/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
$@
@gacha
gacha / colorbox-title-hack.js
Created March 24, 2011 08:59
This solves the long title problem on ColorBox. Tested only for this design http://colorpowered.com/colorbox/core/example1/index.html
$(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();
}
});
@gacha
gacha / colorbox_fix.js
Created May 4, 2011 18:08
Colorbox title for long lines
$(document).bind('cbox_complete', function(){
$("#cboxTitle").hide();
$("<div>"+$("#cboxTitle").html()+"</div>").css({color: $("#cboxTitle").css('color')}).insertAfter(".cboxPhoto");
$.fn.colorbox.resize();
});
@gacha
gacha / merger.rb
Created August 24, 2012 06:53
Merge rails i18n YAML files
# 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)
@gacha
gacha / mute.rb
Created September 4, 2012 14:46
Mute ruby output block
# 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')
@gacha
gacha / tinymce_fill_in.rb
Created November 1, 2012 19:23
Fill in text into tinymce for capybara, using native input for selenium and JS for other
# 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