Skip to content

Instantly share code, notes, and snippets.

View vlado's full-sized avatar

Vlado Cingel vlado

View GitHub Profile
@vlado
vlado / bd_upgrade_es_on_semaphoreci.sh
Last active March 25, 2016 20:33
[BD] Upgrade Elasticsearch on SemaphoreCI
rbenv global 2.2.2
sudo service elasticsearch stop
if ! [ -e .semaphore-cache/elasticsearch-1.5.1.deb ]; then (cd .semaphore-cache; curl -OL https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.5.1.deb); fi
echo Y | sudo dpkg -i .semaphore-cache/elasticsearch-1.5.1.deb
sudo sh -c "echo 'script.disable_dynamic: false' >> /etc/elasticsearch/elasticsearch.yml"
sudo service elasticsearch start
sleep 5 && curl -XGET 'localhost:9200'
@vlado
vlado / example.rb
Created March 5, 2016 21:29 — forked from JoshCheek/example.rb
Debug
# https://minhajuddin.com/2016/03/03/put-this-in-your-code-to-debug-anything
require 'rouge'
require 'method_source'
require 'pp'
class Dbg
def initialize(object, to:)
@object, @stream = object, to
end
@vlado
vlado / add_empty_check_for_name_and_ams_key_to_carriers.rb
Last active February 18, 2016 05:17
Postgres constraints and triggers migration examples
class AddEmptyCheckForNameAndAmsKeyToCarriers < ActiveRecord::Migration
def up
execute %{
ALTER TABLE carriers
ADD CONSTRAINT check_carriers_name_is_not_empty
CHECK (name <> '');
}
execute %{
ALTER TABLE carriers
ADD CONSTRAINT check_carriers_ams_key_is_not_empty
@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 / 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/
@vlado
vlado / ar_enhanced_query_objects.rb
Created September 20, 2013 08:45
ActiveRecord: Enhanced Query Objects
# Hamed Asghari post: http://hasghari.github.io/2013/09/15/active-record-enhanced-query-objects.html
class PopularProductQuery
def initialize(relation = Product.scoped)
@relation = relation.extending(Scopes)
end
def popular(time)
@relation.with_recent_activity(time).with_available_reviews
end