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
ActiveSupport::Notifications.subscribe('process_action.action_controller') do |*args| | |
event = ActiveSupport::Notifications::Event.new(*args) | |
span = Datadog.tracer.active_span | |
payload = event.payload | |
if span && payload.key?(:db_runtime) | |
db_runtime = payload[:db_runtime].to_f.round(3) | |
span.set_tag('database.sql_time', db_runtime) | |
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
#!/bin/bash | |
set -ex | |
# Inject APM Trace ID (part of SQL query comment) to a Log event | |
# https://docs.datadoghq.com/tracing/advanced/connect_logs_and_traces/?tab=ruby | |
# Input: {"command": "Query", "current_statement": "SELECT ... /* 4572859165692197980 */"} | |
# Output: {"process_list": {"current_statement": "SELECT ... /* 4572859165692197980 */"}, "dd": {"trace_id": 4572859165692197980}} | |
function inject_trace_id() { | |
trace_id=$(echo "$1" |grep -Eo '/\* [0-9]{16,20} \*/' | awk '{print $2}') |
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
log_format json '{' | |
'"http":{' | |
'"method":"$request_method",' | |
'"request_id":"$request_id",' | |
'"status_code":$status,' | |
'"content_type":"$content_type",' | |
'"url":"$request_uri",' | |
'"url_details":{' | |
'"path":"$uri",' | |
'"scheme":"$scheme",' |
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
upstream upstream_close_server_keepalive_timeout_0 { | |
server upstream:10443; | |
} | |
upstream upstream_keepalive_server_keepalive_timeout_0 { | |
server upstream:11443; | |
keepalive 64; | |
} | |
upstream upstream_close_server_keepalive_timeout_300 { |
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 ActionDispatch | |
class Reloader | |
def call(env) | |
if env['PATH_INFO'].include?(Rails.application.config.assets.prefix) | |
@app.call(env) | |
else | |
@validated = @condition.call | |
prepare! |
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 Object | |
class UnitTestError < StandardError; end | |
def describe(description, &block) | |
if Object.class_eval(&block) | |
print '.' | |
else | |
puts 'FAIL ' + description | |
raise UnitTestError |
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 ReverseSentence | |
def initialize(string) | |
@array, @array_reversed = string.split(" "), [] | |
end | |
def process | |
@array_reversed << @array.pop while @array.any? | |
@array_reversed.join(" ") | |
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 FizzBuzz | |
def initialize(array) | |
@array = array | |
@new_array = [] | |
end | |
def process | |
@array.each do |e| | |
value = \ | |
if e % 3 == 0 && e % 5 == 0 |
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 DecimalMark | |
def initialize(data) | |
@array = data.split("") | |
@new_array = [] | |
end | |
def process | |
i = 0 | |
loop do |
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 ValidParentheses | |
SYMBOLS = {"(" => ")", "[" => "]", "{" => "}"} | |
def initialize(array) | |
@array = array.split("") | |
@stack = [] | |
end | |
def process | |
@array.each do |i| |
NewerOlder