This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
=begin | |
Sample one-file app to try to reproduce an issue with Capybara + Apparition: | |
https://github.com/twalpole/apparition/issues/40 | |
Running the file using `ruby` causes it to fail and log the following response: | |
log: -> RESPONSE: "" "success" {"readyState":4,"responseText":"","status":200,"statusText":"OK"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
APP_NAME="your-app-name-goes-here" | |
APP_PATH=/home/deploy/${APP_NAME} | |
# Production environment | |
export RAILS_ENV="production" | |
# This loads RVM into a shell session. Uncomment if you're using RVM system wide. | |
# [[ -s "/usr/local/lib/rvm" ]] && . "/usr/local/lib/rvm" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'benchmark/ips' | |
ARRAY = [1,2,3,1,'2',4,'5',6,7,8,9,'10'] | |
Benchmark.ips do |x| | |
x.report("while") { | |
hash = {} | |
index = 0 | |
length = ARRAY.length |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Support | |
module WorkerExampleGroup | |
include RSpec::Rails::RailsExampleGroup | |
def self.included(base) | |
base.metadata[:type] = :worker | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class A | |
def initialize_dup(other) | |
puts 'init dup' | |
super | |
end | |
def initialize_clone(other) | |
puts 'init clone' | |
super | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'socket' | |
test_file = ARGV[0] | |
socket = UNIXSocket.new('testing.sock') | |
socket.write(test_file) | |
socket.close_write |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'active_record' | |
require 'active_record/base' | |
module ActiveRecord | |
module CVE123456 | |
def define_attribute_methods | |
# .... | |
raise "OMG Monkey Patch!" | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/inputs/hour_input.rb | |
class HourInput < SimpleForm::Inputs::Base | |
def input | |
@builder.select(attribute_name, hour_options, { :selected => selected_value }, { :class => "input-medium" }) | |
end | |
private | |
# The "Selecione..." string could also be translated with something like: I18n.t("helpers.select.prompt') | |
def hour_options |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'benchmark' | |
TIMES = 100000 | |
HASH = { as: :fuu } | |
Benchmark.bm(25) do |x| | |
x.report('[:as] (existing)') do | |
TIMES.times do | |
HASH[:as] || :default | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define_method '<=>_with_infinity' do |other| | |
if other.class == self.class | |
public_send('<=>_without_infinity', other) | |
else | |
infinite = try(:infinite?) | |
other_infinite = other.try(:infinite?) | |
# inf <=> inf | |
if infinite && other_infinite | |
infinite <=> other_infinite |
NewerOlder