Skip to content

Instantly share code, notes, and snippets.

View theharq's full-sized avatar

Hildebrando Rueda theharq

  • Berlin, Germany
View GitHub Profile
if ENV["APPSIGNAL_PUSH_API_KEY"]
require "rake/task"
module Appsignal
module Integrations
module CustomRakeIntegration
EXCLUDED_RAKE_TASKS = [
"timezone_environment",
"assets:clean",
"assets:precompile",
@theharq
theharq / selenium-iterm2-images.rb
Last active August 10, 2018 08:38
Render images in Iterm2 with Ruby
# Useful when dealing with screenshots taken by Selenium
def selenium_driver
@_selenium_driver ||= begin
options = Selenium::WebDriver::Chrome::Options.new
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
Selenium::WebDriver.for :chrome, options: options
end
@theharq
theharq / rails_helper.rb
Created May 4, 2018 15:23
Simplecov add group with files changed in current branch
## The base branch in this case is called `develop`
SimpleCov.start 'rails' do
add_group 'Policies', 'app/policies'
add_group 'Serializers', 'app/serializers'
add_group 'Services', 'app/services'
add_group 'This Branch' do |source_file|
`git diff --name-only develop`.split("\n").detect do |filename|
source_file.filename.ends_with?(filename)
end
@theharq
theharq / gist:214dd45a15d8abaded4266a0a143c0dd
Created February 22, 2017 20:23
Mapping template for haraka
curl -XPUT localhost:9201/_template/haraka_results -d '
{
"template" : "smtp-transaction-*",
"mappings" : {
"haraka" : {
"dynamic_templates" : [
{ "fail_results" : {
"match" : "fail",
"mapping" : {
"type" : "string", "index" : "not_analyzed"
@theharq
theharq / active_record_log_subscriber.rb
Created December 21, 2016 03:47
Initializer to log which line caused a query
# http://www.jkfill.com/2015/02/14/log-which-line-caused-a-query/
module LogQuerySource
def debug(*args, &block)
return unless super
backtrace = Rails.backtrace_cleaner.clean caller
relevant_caller_line = backtrace.detect do |caller_line|
!caller_line.include?('/initializers/')
end
@theharq
theharq / gist:b5a3ed84afd3caee4b07a91a6fda659f
Created November 11, 2016 14:54
Show ping with timestamp
ping www.google.com | while read pong; do echo "$(date): $pong"; done
SELECT *
FROM "measures"
INNER JOIN
(SELECT *
FROM
(SELECT *
FROM
(SELECT "measures".*,
(CASE WHEN ("measures"."validity_start_date" IS NULL) THEN base_regulations.validity_start_date ELSE measures.validity_start_date END) AS "effective_start_date",
(CASE WHEN ("measures"."validity_end_date" IS NULL) THEN base_regulations.effective_end_date ELSE measures.validity_end_date END) AS "effective_end_date"
@theharq
theharq / Gemfile
Created February 27, 2016 21:13
Helper for ruby-prof gem
gem "ruby-prof"
@theharq
theharq / classify.rb
Created February 26, 2016 14:32
Testing custom classify method .. We assume the string has snake case format and may be plural
Benchmark.ips do |x|
x.config(time: 5, warmup: 5)
x.report("Option 1") do
"quota_order_number_origin_exclusions".classify
end
x.report("Option 2") do
"quota_order_number_origin_exclusions".gsub(/(^|_)(.)/) { $2.upcase }.gsub(/s$/, '')
end
@theharq
theharq / ox.rb
Last active February 18, 2016 04:40
OX Sax Parser for HUGE xml files - https://github.com/ohler55/ox
# Ruby Optimizations
# Comparison:
# Array#[-1]: 8053888.8 i/s
# Array#last: 7388678.2 i/s - 1.09x slower
# Comparison:
# Array#length: 11394036.7 i/s
# Array#size: 11302701.1 i/s - 1.01x slower
# Array#count: 9194976.2 i/s - 1.24x slower
# Comparison: