Skip to content

Instantly share code, notes, and snippets.

View soares-marcio's full-sized avatar
🌎
Working

Márcio Soares soares-marcio

🌎
Working
View GitHub Profile
@soares-marcio
soares-marcio / gist:d6150785952ce5b3050a99ce8d792eb1
Created September 18, 2024 18:21 — forked from rxaviers/gist:7360908
Complete list of github markdown emoji markup

People

:bowtie: :bowtie: 😄 :smile: 😆 :laughing:
😊 :blush: 😃 :smiley: ☺️ :relaxed:
😏 :smirk: 😍 :heart_eyes: 😘 :kissing_heart:
😚 :kissing_closed_eyes: 😳 :flushed: 😌 :relieved:
😆 :satisfied: 😁 :grin: 😉 :wink:
😜 :stuck_out_tongue_winking_eye: 😝 :stuck_out_tongue_closed_eyes: 😀 :grinning:
😗 :kissing: 😙 :kissing_smiling_eyes: 😛 :stuck_out_tongue:
@soares-marcio
soares-marcio / customize_error.rb
Created May 1, 2020 23:50 — forked from telwell/customize_error.rb
Customize Field Errors with Rails 5 and Bootstrap
# Adapted from https://rubyplus.com/articles/3401-Customize-Field-Error-in-Rails-5
ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
html = ''
form_fields = [
'textarea',
'input',
'select'
]
@soares-marcio
soares-marcio / rails http status codes
Created March 28, 2020 17:07 — forked from mlanett/rails http status codes
HTTP status code symbols for Rails
HTTP status code symbols for Rails
Thanks to Cody Fauser for this list of HTTP responce codes and their Ruby on Rails symbol mappings.
Status Code Symbol
1xx Informational
100 :continue
101 :switching_protocols
102 :processing
@soares-marcio
soares-marcio / book.rb
Created January 31, 2020 14:34 — forked from grauwoelfchen/book.rb
Unit test example for cache in model class
class Book < ActiveRecord::Base
after_commit :flush_cache
def self.cached_find(id)
Rails.cache.fetch([name, id], expires_in: 30.mitues) do
where(:id => id).take!
end
end
private
@soares-marcio
soares-marcio / searchkick_reindex_resume.rb
Created July 20, 2019 15:00 — forked from Chocksy/searchkick_reindex_resume.rb
Searchkick reindex with resume
namespace :searchkick do
desc "maybe reindex without running out of memory?"
task :altindex, [:start_index, :batch_size, :new_index_name] => :environment do |t, args|
ActiveRecord::Base.logger = Logger.new(STDOUT)
count = Item.count
start = args[:start_index].to_i || 0
batch_size = args[:batch_size].to_i || 1000
# we create a new index or take one already present
if args[:new_index_name]
require 'minitest/spec'
require 'minitest/autorun'
module Helpers
module Let
def let(name, &blk)
define_method name do
@let_assigments ||= {}
@let_assigments[name] ||= send(:"original_#{name}")
@soares-marcio
soares-marcio / missing_num_array.rb
Created August 22, 2018 13:23 — forked from malchak/missing_num_array.rb
Solutions to Find Missing Number in Array.
# Question:
# Suppose you have an array of 99 numbers.
# The array contains the digits 1 to 100 with one digit missing.
# Write four different algorithms to compute the missing number.
# Two of these should optimize for low storage and two of these should optimize for fast processing.
# (Keep in mind, there are no duplicates and the array is not already sorted.)
#######################################################
@soares-marcio
soares-marcio / factory.rb
Created July 18, 2018 20:35 — forked from sjke/factory.rb
FactoryGirl: Generate factory for all models
Rails.application.eager_load!
ActiveRecord::Base.subclasses.reject { |m| m.name =~ /HABTM/ || m.name =~ /Pg/ }.each do |model|
begin
model_relation = model.reflect_on_all_associations.map{ |r| [ r.foreign_key, r.name ] }.to_h
columns = model.columns.map { |c| [ c.name, c.cast_type.type ] }.to_h
model_relation.keys.each { |k| columns.delete(k) }
`rails g factory_girl:model #{model.name} #{columns.map { |k, v| "#{k}:#{v}" }.join(' ')}`
@soares-marcio
soares-marcio / stack-javascript-es6
Created June 18, 2017 18:02
uma Fila em javascript
class Stack {
constructor() {
this.items = [];
}
push(item) {
this.items.push(item);
}
pop() {
return this.items.pop();
}
@soares-marcio
soares-marcio / rspec_model_testing_template.rb
Created June 14, 2016 13:28 — forked from PWSdelta/rspec_model_testing_template.rb
Rails Rspec model testing skeleton & cheat sheet using rspec-rails, shoulda-matchers, shoulda-callbacks, and factory_girl_rails. Pretty much a brain dump of examples of what you can (should?) test in a model. Pick & choose what you like, and please let me know if there are any errors or new/changed features out there. Reddit comment thread: http…
# This is a skeleton for testing models including examples of validations, callbacks,
# scopes, instance & class methods, associations, and more.
# Pick and choose what you want, as all models don't NEED to be tested at this depth.
#
# I'm always eager to hear new tips & suggestions as I'm still new to testing,
# so if you have any, please share!
#
# @kyletcarlson
#
# This skeleton also assumes you're using the following gems: