Skip to content

Instantly share code, notes, and snippets.

View lazaronixon's full-sized avatar

Lázaro Nixon lazaronixon

View GitHub Profile
@lazaronixon
lazaronixon / address.rb
Last active September 4, 2018 13:26
Simple Form Object
# name, state, city
class Address < ApplicationRecord
has_one :location, as: :locable, dependent: :destroy
end
@lazaronixon
lazaronixon / WebSecurityFilter.java
Last active June 19, 2019 00:02
SpringBoot Simple Secure API
import java.io.IOException;
import java.util.Objects;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
@lazaronixon
lazaronixon / dropzone_controller.js
Last active September 25, 2024 14:28
Dropzone.js + Stimulus + Active Storage
import { Controller } from "stimulus"
import { DirectUpload } from "@rails/activestorage"
import Dropzone from "dropzone"
import { getMetaValue, findElement, removeElement, insertAfter } from "helpers"
Dropzone.autoDiscover = false
export default class extends Controller {
static targets = [ "input" ]
@lazaronixon
lazaronixon / rubocop.yml
Last active October 21, 2022 17:49
Basecamp Rubocop Template
# This template is inspired on https://github.com/basecamp/audits1984/blob/master/.rubocop.yml
#
# 1 - Add dependencies to group :development, :test
# gem "rubocop", "~> 1.26", require: false
# gem "rubocop-performance", require: false
# gem "rubocop-rails", require: false
#
# 2 - Create a file .rubocop.yml and add the lines below
# inherit_from: https://gist.githubusercontent.com/lazaronixon/7815d84702f277ead5e89c9f2aa5581f/raw/rubocop.yml
#
@lazaronixon
lazaronixon / Gemfile.rb
Last active May 17, 2022 04:57
Elasticsearch integrated with geared pagination
# Search
gem "elasticsearch-model", "~> 7.1.0"
gem "elasticsearch-rails", "~> 7.1.0"
gem "geared_pagination"
@lazaronixon
lazaronixon / callbacks.rb
Created May 18, 2022 00:33
Elastic search index async
module ElasticsearchExtension
module Callbacks
extend ActiveSupport::Concern
included do
after_commit -> { IndexJob.perform_later(:create, self.class.name, self.id) }, on: :create
after_commit -> { IndexJob.perform_later(:update, self.class.name, self.id) }, on: :update
after_commit -> { IndexJob.perform_later(:destroy, self.class.name, self.id) }, on: :destroy
end
end
@lazaronixon
lazaronixon / settings.json
Last active February 2, 2023 05:32
VSCode as Atom
{
"workbench.startupEditor": "none",
"workbench.colorTheme": "Atom One Light",
"workbench.activityBar.visible": false,
"editor.minimap.enabled": false,
"editor.scrollBeyondLastLine": false,
"editor.guides.indentation": false,
"editor.fontSize": 14,
"editor.tabSize": 2,
"editor.renderControlCharacters": false,
@lazaronixon
lazaronixon / Gemfile
Last active April 3, 2023 18:33
Action deliver
gem "abstract_notifier"
@lazaronixon
lazaronixon / application_controller.rb
Last active October 2, 2024 14:28
Application controller and concerns
class ApplicationController < ActionController::Base
include SetCurrentRequestDetails
include SetCurrentTimeZone
include Authenticate
include ForgeryProtection
include ErrorResponses
include SetSentryUser
@lazaronixon
lazaronixon / database.yml
Last active May 28, 2024 01:50
config/initializers/sqlite3.rb
# config/database.yml
# SQLite. Versions 3.8.0 and up are supported.
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem "sqlite3"
#
default: &default
adapter: sqlite3