Skip to content

Instantly share code, notes, and snippets.

View RafaelMCarvalho's full-sized avatar

Rafael Carvalho RafaelMCarvalho

View GitHub Profile
@RafaelMCarvalho
RafaelMCarvalho / postgres-bdr-setup.md
Last active April 9, 2024 10:23
A PostgreSQL BDR step-by-step Debian setup guide. May become a small post someday.

1. Configure SO locale

export LANGUAGE=en_US.UTF-8
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
locale-gen en_US.UTF-8
dpkg-reconfigure locales
@RafaelMCarvalho
RafaelMCarvalho / ransackable_scopes.rb
Created May 24, 2016 15:21 — forked from gabeodess/ransackable_scopes.rb
Ransack with JSONB query for array values (or condition)
class Edition < ActiveRecord::Base
scope :distances_any, -> (*distances) {
where("distances ?| array[:values]", values: distances)
}
private
def self.ransackable_scopes(auth_object = nil)
%i(distances_any)
end
@RafaelMCarvalho
RafaelMCarvalho / array.rb
Created October 8, 2015 20:58
Simple, but useful, methods to manipulate an array of hashes.
class Array
def pluck(key)
map { |h| h[key] }
end
# a = [
# {id: 1, name: 'John' },
# {id: 2, name: 'Doe' },
# {id: 3, name: 'John' },
# { name: 'Doe' }
@RafaelMCarvalho
RafaelMCarvalho / bulk_updatable.rb
Last active September 24, 2015 22:22
A concern that adds a perfomatic .bulk_update method for ActiveRecord classes.
module BulkUpdatable
extend ActiveSupport::Concern
self.included do |base|
# Usage:
#
# User.bulk_update([{id: 1, name: 'Foo'}, {id: 2, name: 'Bar'}])
# (1.5ms) UPDATE "users" SET "id" = 1, "name" = 'Foo' WHERE "users"."id" = 1;
# UPDATE "users" SET "id" = 2, "name" = 'Bar' WHERE "users"."id" = 2
# => #<PG::Result:0x007f814aa04c40 status=PGRES_COMMAND_OK ntuples=0 nfields=0 cmd_tuples=1>
html, body, div {
margin: 0;
padding: 0;
}
.clearfix:after {
margin: 0;
padding: 0;
content: "";
display: block;