Skip to content

Instantly share code, notes, and snippets.

View vlado's full-sized avatar

Vlado Cingel vlado

View GitHub Profile
@vlado
vlado / search_to_recommend.groovy
Created April 22, 2015 07:47
[BD] Groovy script to calculate custom scoring when recommending physician
if (doc['primary_specialization_name'].value == specialization_name) {
_score + 1000
} else {
_score
}
permissions:
some_role:
- physicians # Can access all actions in physicians controller
- admin/inquiries#index # Can access index action in inquiries controller
some_other_role:
- physicians#show
- admin/inquiries
- admin/users
@vlado
vlado / controller_helpers.rb
Last active February 16, 2019 01:03
Stub devise authentication in controller specs with multiple scopes
# Usage:
# fake_sign_in
# fake_sign_in(@user)
# fake_sign_in(@admin)
# fake_sign_in(:admin)
# fake_sign_in(@some_object, :scope => :user)
# fake_sign_out
# fake_sign_out :admin
module ControllerHelpers
@vlado
vlado / gist:7713285
Last active December 29, 2015 18:49 — forked from ericboehs/gist:7125105
Fork of @ericboehs Poltergeist hack to silence CoreText performance notes from phantomjs My changes: 1. to is now optional parameter, if not provided @write_io is used 2. option to easily add more messages to suppress (I added this one WARNING: Method userSpaceScaleFactor in class NSView is deprecated)
module Capybara::Poltergeist
class Client
private
def redirect_stdout(to = nil)
to ||= @write_io
prev = STDOUT.dup
prev.autoclose = false
$stdout = to
STDOUT.reopen(to)
// Usage:
// $('div').gracefullEffect('slideDown')
$.fn.gracefullEffect = function(effectName) {
fallbacksMap = {
slideDown: 'show',
slideUp: 'hide'
// ...
}
if ($.support.trailingWhiteSpace) {
@vlado
vlado / ey_env_var.rb
Created November 28, 2013 18:43
Script to easily add/remove custom environment variables (env.custom) on all instances
#!/usr/bin/env ruby
# Usage:
# Add env variable: /path/to/this/script {environment} add VAR_NAME varvalue
# Remove env variable: /path/to/this/script {environment} remove VAR_NAME
require 'active_support'
app_name = "betterdoc"
@vlado
vlado / tooltips_and_client_side_validation_form_builder.rb
Last active December 27, 2015 13:59
How to add options for tooltips and client side validations to Rails standard form helpers
class TooltipsAndClientSideValidationsFormBuilder > ActionView::Helpers::FormBuilder
def text_field(object_name, method, options = {})
# do nothing if raw option is present (same as rails standard text_field)
unless options[:raw]
extract_tooltip_options! options
extract_validation_options! options
end
super(object_name, method, options = {})
end
@vlado
vlado / custom_chosen.coffee
Created November 5, 2013 08:40
How to extend Chosen jQuery library example
# 1. Extend Chosen with custom method or owerwrite existing methods
class CustomChosen extends Chosen
show_search_field_default: ->
# ...
# original method updated
# ...
some_new_method: ->
# ...
@vlado
vlado / gist:6636923
Created September 20, 2013 12:44
Faster Ruby Tests
http://fredwu.me/post/60441991350/protip-ruby-devs-please-tweak-your-gc-settings-for
http://fredwu.me/post/61571741083/protip-faster-ruby-tests-with-databasecleaner-and
http://labs.goclio.com/tuning-ruby-garbage-collection-for-rspec/