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 can_call?(name, seconds, limit) | |
calls = redis.llen(name) | |
return false if calls > limit | |
if redis.exists(name) | |
redis.rpushx(name, 1) | |
else | |
redis.multi do | |
redis.rpush(name, 1) | |
redis.expire(name, seconds) | |
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 ApplicationController < ActionController::API | |
def status | |
begin | |
DatabaseHelper::Mysql.smrt.exec_query('SELECT id FROM customers LIMIT 1') | |
DatabaseHelper::Mysql.scr.exec_query('SELECT id FROM filter_prefixes LIMIT 1') | |
DatabaseHelper::Mysql.backend.exec_query('SELECT id FROM accounts LIMIT 1') | |
DatabaseHelper::Mysql.delayed_job.exec_query('SELECT id FROM delayed_jobs LIMIT 1') | |
status = Class.new.extend DatabaseHelper |
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
Everything up-to-date | |
* 2013-09-26 17:39:07 executing `staging' | |
triggering start callbacks for `deploy:migrations' | |
* 2013-09-26 17:39:07 executing `multistage:ensure' | |
* 2013-09-26 17:39:07 executing `deploy:migrations' | |
* 2013-09-26 17:39:07 executing `deploy:update_code' | |
triggering before callbacks for `deploy:update_code' | |
* 2013-09-26 17:39:07 executing `smrt:compress_assets' | |
executing locally: "rm -rf public/assets/*" | |
command finished in 1071ms |
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
module ConvexHull | |
def self.calculate(points) | |
lop = points.sort_by { |p| p.x } | |
left = lop.shift | |
right = lop.pop | |
lower, upper = [left], [left] | |
lower_hull, upper_hull = [], [] | |
det_func = determinant_function(left, right) | |
until lop.empty? |
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 ApplicationController < ActionController::Base | |
# Add this to your application_controller | |
def self.authorized_inherited_resources | |
inherit_resources | |
before_filter :authorize_resource_with_cancan | |
define_method(:authorize_resource_with_cancan) do | |
case action_name.to_sym | |
when :new, :create |
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: | |
# | |
# find("span.assign").hover | |
# | |
module Capybara | |
module Node | |
class Element | |
def hover | |
@session.driver.browser.action.move_to(self.native).perform | |
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
# Tell Cucumber to quit after a scenario is done - if it failed. | |
# $ cucumber EXIT_WHEN_FAIL=1 | |
# Note: Please take in account the advantage of tags when working with a specific scenario before implemebt this! | |
After do |s| | |
if s.failed? && ENV.include?('EXIT_WHEN_FAIL') && ENV['EXIT_WHEN_FAIL'] == '1' | |
Cucumber.wants_to_quit = true | |
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
module ActionView | |
module Helpers | |
module FormOptionsHelper | |
# | |
# NOTE: This approach does not work with the :disabled flag and other HTML options that | |
# grouped_options_for_select_with_cache supports, it was done | |
# this way in order to improve the performance of large select tags that are rebuilt | |
# more than one time per request. | |
def grouped_options_for_select_with_cache(grouped_options, selected_key = nil, prompt = nil) | |
@grouped_options_cache ||= {} |
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: | |
# chosen_select 'select[name="projects"]', "ProjectA" | |
# | |
def chosen_select (css_select, option_text) | |
element_id = page.find(css_select)['id'] | |
page.driver.browser.mouse.down find("##{element_id}_chzn").native | |
within("##{element_id}_chzn") do | |
find(:xpath,"//li[text()=\"#{option_text}\"]").click | |
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
//bool setcookie ( string $name [, string $value [, int $expire = 0 [, string $path [, string $domain [, bool $secure = false [, bool $httponly = false ]]]]]] ) | |
//@see http://php.net/manual/en/function.setcookie.php | |
setcookie("A", 'A', time()+3600, '/','a.com', 1, 1); |