Skip to content

Instantly share code, notes, and snippets.

Avatar

Marcelo Ribeiro Xavier da Silva marcelorxaviers

View GitHub Profile
View pre-commit.sh
#!/bin/bash
chruby 2.7.0
export RUBYOPT=-W:no-deprecated
# Install all gem dependencies
bundle install
# Just to prevent showing many "error" messages
dirty_bit=0
View batch_create_do_nothing.rb
class BatchCreate
class << self
def perform(active_records:, conflict_fields:)
return if active_records.empty?
ActiveRecord::Base.connection.execute(
<<-SQL.squish
#{insert_statement(active_records.first)}
#{values(active_records)}
#{on_conflict_statement(conflict_fields)}
View batch_create.rb
class BatchCreate
class << self
def perform(active_records:, conflict_fields:)
return if active_records.empty?
ActiveRecord::Base.connection.execute(
<<-SQL.squish
#{insert_statement(active_records.first)}
#{values(active_records)}
#{on_conflict_statement(active_records.first, conflict_fields)}
View routes.rb
if Rails.env.development?
class MarcelosController < ApplicationController
def method
require 'pry-byebug' ; binding.pry
end
end
get '/marcelos_method/:id', to: 'marcelos#method'
end
@marcelorxaviers
marcelorxaviers / flatten.rb
Last active Jun 26, 2017
Flatten method for array in Ruby
View flatten.rb
# flatten.rb
module Flatten
extend self
def perform!(array, type = nil)
return [] if type == Array
recursive(array.to_a, type)
rescue
raise "The parameter has to be a #{type || "mixed types"} collection."
You can’t perform that action at this time.