Skip to content

Instantly share code, notes, and snippets.

View jacksonpires's full-sized avatar
🏠
Working from home

Jackson Pires jacksonpires

🏠
Working from home
View GitHub Profile
@jacksonpires
jacksonpires / create_locale_files.rb
Created May 26, 2023 21:37
Move pt-br.yml to splitted version
# frozen_string_literal: true
require "yaml"
namespace :dev do
desc "Create locale files to models"
task create_locale_files: :environment do
models_folder = Rails.root.join("app","models")
original_new_locales_folder = Rails.root.join("config", "locales")
@jacksonpires
jacksonpires / arel_nodes_trgm.rb
Last active May 26, 2023 21:37
Create a custom node on Arel
# frozen_string_literal: true
module ArelNodesTrgm
class Arel::Nodes::Trgm < Arel::Nodes::InfixOperation
def initialize(left, right)
super(:"%", left, right)
end
end
class Arel::Visitors::PostgreSQL < Arel::Visitors::ToSql

Arel Cheatsheet on Steroids

A (more) complete cheatsheet for Arel, including NamedFunction functions, raw SQL and window functions.

Tables

posts = Arel::Table.new(:posts)
posts = Post.arel_table # ActiveRecord

Table alias

@jacksonpires
jacksonpires / ruby.json
Created May 5, 2023 19:43
VsCode Snippets
{
"Print asterisk line": {
"prefix": "line",
"body": [
"p '*' * 100"
],
"description": "Print a asterisk line"
},
"Print and inspect a element": {
@jacksonpires
jacksonpires / must-watch-talks.txt
Created December 23, 2022 23:17 — forked from lastk/must-watch-talks.txt
must-watch talks
Rich Hickey
https://confreaks.tv/videos/railsconf2012-keynote-simplicity-matters
https://confreaks.tv/videos/jaxconf2012-keynote-the-value-of-values
Dave Thomas
https://confreaks.tv/videos/elixirconf2014-opening-keynote-think-different
https://confreaks.tv/videos/lonestarruby2013-elixir-power-of-erlang-joy-of-ruby
Robert Martin
https://confreaks.tv/videos/rubymidwest2011-keynote-architecture-the-lost-years
@jacksonpires
jacksonpires / remove-submodule.sh
Created February 11, 2021 22:08 — forked from niartenyaw/remove-submodule.sh
App Academy - Remove unwanted submodule from nested Git repos and re-add all the files inside of it
# In most cases, a single Rails app will be attached to a single repo
# As of Rails 5.1, initializing a new project will also automatically initialize Git
# This is perfect in most circumstances, but at App Academy, students have homework and
# project repos that contain multiple rails apps inside them
# To account for this without pushing the submodules, students need to remove the .git
# directory before adding and commiting the new project, but most do not, resulting in
@jacksonpires
jacksonpires / custom_arel.rb
Created July 8, 2020 18:57 — forked from gabeodess/custom_arel.rb
An example of how to add a custom predicate to Arel
module Arel::Predications
def has_key(right)
Arel::Nodes::HasKey.new(self, quoted_node(right))
end
end
class Arel::Nodes::HasKey < Arel::Nodes::Binary
def operator; :"?" end
end
@jacksonpires
jacksonpires / arel_any_predicate.rb
Created July 8, 2020 18:54 — forked from 3014zhangshuo/arel_any_predicate.rb
An example of how to add a custom predicate to Arel
module Arel::Predications
def any(right)
Arel::Nodes::Any.new(self, quoted_node(right))
end
end
class Arel::Nodes::Any < Arel::Nodes::Binary
def operator
:'ANY'
end
@jacksonpires
jacksonpires / ur_path_regex.rb
Created May 31, 2020 23:17
Regex to get path/id between last slash and question mark
/[^\/?]+(?=\?|$)/