View datadog_apm_sql_time.rb
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 |
View mysql_process_list_to_stdout.sh
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}') |
View Nginx access log
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",' |
View nginx.local.conf
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 { |
View reloader_fix.rb
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! |
View tests.rb
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 |
View reverse_sentence.rb
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 |
View fizz_buzz.rb
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 |
View decimal_mark.rb
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 |
View valid_parentheses.rb
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