Skip to content

Instantly share code, notes, and snippets.

View everton's full-sized avatar

Everton J. Carpes everton

  • http://www.nutrebem.com.br
  • Rio de Janeiro, RJ - Brasil
View GitHub Profile
@everton
everton / lisp-conditions-in-ruby.rb
Last active April 21, 2024 18:57
Inspired by Common LISP conditions system, this code here uses continuations to inject "restart" options from the context where an Exception was raised and allowing to resume from the error line. Obs.: since this code relies on continuations, it is not supposed to work on Ruby implementations without this resource (such as JRuby, Ribinius, etc)
require 'continuation'
class Restart < RuntimeError
attr_accessor :menu
def initialize(**menu)
@menu = menu
@menu.each do |name, proc|
define_singleton_method "#{name}!" do
module FormTestHelper
def assert_form(action, options = {}, &block)
method = options.delete(:method) || :post
if method == :put || method == :patch || method == :delete
virtual_method, method = method, :post
test_body = -> (*args) {
assert_select "input[type='hidden'][name='_method']",
value: virtual_method
@everton
everton / form_builder.rb
Last active March 31, 2020 12:08
Add "required" for input tags of fields with "presence" validation and "minlength" / "maxlength" of fields with "length" validation
# config/initializers/form_builder.rb
module InputTagsMarkedAsRequiredOrWithMinMaxLengthInHTMLIfValidatedForPresence
def initialize(object_name, method_name, template_object, options = {})
return super unless options[:object] # it will be nil when called from #form_with
validators = options[:object].class.validators_on(method_name)
unless options.has_key? :required # check using has_key? to allow "required: nil"
if validators.any? ActiveRecord::Validations::PresenceValidator
import java.lang.invoke.MethodHandles;
class Base {
public static class CurrentClassGetter extends SecurityManager {
public Class<?>[] getClassContext() {
return super.getClassContext();
}
}
public static void find(int id) {
@everton
everton / table-to-mobile.html
Created December 23, 2018 15:20
Mobile Table + CSS Scroll Snap Points
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Mobile Table + CSS Scroll Snap Points</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style type="text/css" media="screen">
@everton
everton / tasks_test_helper.rb
Created September 15, 2017 12:26
IntegrationTest specialization to test rake tasks
require 'rake'
class TasksTest < ActionDispatch::IntegrationTest
include ActionMailer::TestHelper
private
def self.task(t = nil)
return @task unless t
t = t.to_s
@everton
everton / minitest_twice_fork.rb
Last active February 4, 2016 20:58
Minitest running twice when dealing with forks
require 'minitest/autorun'
class TestSuite
def self.before_run
pid = fork do
puts "on fork"
exit 0
end
Process.detach pid
@everton
everton / rails-issue-20633.rb rails-4.2.3.rc1-unscope-bug.rb
Last active August 29, 2015 14:23
blongs_to unscope not respected in includes - rails 4.2.3
begin
require 'bundler/inline'
rescue LoadError => e
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
raise e
end
gemfile(true) do
source 'https://rubygems.org'
# Activate the gem you are reporting the issue against.
@everton
everton / gist:91a2cb2aed4258218ad9
Created May 30, 2014 02:56
rails-4.1.2.rc2 before_create bug report
# Activate the gem you are reporting the issue against.
gem 'activerecord', '4.1.2.rc1'
require 'active_record'
require 'minitest/autorun'
require 'logger'
# Ensure backward compatibility with Minitest 4
Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test)
# This connection will do for database-independent bug reports.
#!/usr/bin/env ruby
project_source_dir = ARGV.first
project_source_dir += '/' unless project_source_dir[-1] == '/'
raise 'Not a Git repository' unless File.exists? "#{project_source_dir}.git"
# TODO: raise 'Not a Rails application' if ???
def pending_git_tasks?