Skip to content

Instantly share code, notes, and snippets.

Gabriel Sobrinho sobrinho

Block or report user

Report or block sobrinho

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View 00_active_record_patch_includes_without_primary_key.rb
if ActiveRecord::VERSION::STRING != ''
raise 'This patch only works with, be sure to repatch when upgrade'
module ActiveRecord
# Fix an issue where includes on models without primary key raises a crypto
# error.
# What we are essentially doing is ignoring the projection of blank column
# names because the array of columns is computed using the primary key which
View gist:1dcfc2c8035a1bfa7c480fcbfa60069f
[89] pry(main)> User.primary_key = nil
=> nil
[90] pry(main)> User.includes(:person).where(Person.arel_table[:id].eq(1)).all
SQL (0.4ms) SELECT "usuarios"."" AS t0_r0, "usuarios"."id" AS t0_r1, [[ommited]]
ActiveRecord::StatementInvalid: PG::SyntaxError: ERROR: zero-length delimited identifier at or near """"
LINE 1: SELECT "usuarios"."" AS t0_r0, "usuarios"."id" AS t0_r1, "us...
View diff.patch
diff --git a/src/authentication.c b/src/authentication.c
index bba7cef..4ea48c9 100644
--- a/src/authentication.c
+++ b/src/authentication.c
@@ -143,11 +143,5 @@ static bool CheckPassword() {
#endif /* ENABLE_PAM */
void Authenticate() {
- uint8_t tries = 0;
- while (tries < 3) {
View unaccent.rb
class String
def unaccent
string = ''
each_char do |char|
ascii = I18n.transliterate(char)
if ascii == '?'
string << char
View active_record.rb
# Robust JSON output for active record errors
# See!topic/rubyonrails-core/hxgX6D9s2uM
module ActiveRecord
module AutosaveAssociation
def validate_collection_association(reflection)
if association = association_instance_get(
if records = associated_records_to_validate_or_save(association, new_record?, reflection.options[:autosave])
records.each_with_index do |record, index|
association_valid?(reflection, record, index)
View form_object.rb
class SongForm
include ActiveModel::Model
attr_accessor :song_name, :artist_name
def song
@song ||=
def artist
sobrinho / track_habtm_changes.rb
Last active Dec 21, 2015
Track habtm changes on active record
View track_habtm_changes.rb
# See!topic/rubyonrails-core/Lb9rBkZnZSo
module TrackHabtmChanges
def self.included(model)
model.after_initialize :track_habtm_initial_state
model.after_save :track_habtm_initial_state
def changes
View water_tank.rb
class WaterTank
attr_reader :volume
def initialize(volume)
@volume = volume
def drain(quantity)
if quantity > volume
quantity = volume
sobrinho /
Last active Oct 12, 2016
Provides build-essential, git, memcached, postgres, redis, node, ruby, bundler, foreman and heroku. To be used against a precise64 machine (
set -e
set -x
provision_command="wget -O- | sh"
ssh root@server1 "$provision_command"
ssh root@server2 "$provision_command"
sobrinho / or.rb
Created Oct 3, 2012
Proof of concept for `(a | b).empty?` on ruby
View or.rb
class Or < BasicObject
def initialize(a, b)
@a = a
@b = b
def method_missing(method_name, *arguments, &block)
@a.send(method_name, *arguments, &block) || @b.send(method_name, *arguments, &block)
You can’t perform that action at this time.