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 'faraday' | |
require 'json' | |
def fetch_data(search_query) | |
response = [:just_started_sentinel] | |
list = [] | |
page = 1 | |
until response.empty? do | |
sleep 0.11 # 10 request/sec is the remote rate limit |
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 Datadog | |
module Profiling | |
# Starts the profiler, if the profiler is supported by in | |
# this runtime environment and if the profiler has been enabled | |
# in configuration. | |
# | |
# @return [Boolean] `true` if the profiler has successfully started, otherwise `false`. | |
# @public_api | |
def self.start | |
return false unless Datadog.send(:components).profiler |
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 Wrapper | |
InstanceMethods = Module.new | |
def self.for(klass, accessor_name: nil) | |
InstanceMethods.module_eval do | |
define_method :initialize do |object| | |
raise TypeError, "not a #{klass}" unless object.is_a?(klass) | |
@object = object | |
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
# Code mostly adapted from original by Jesus: https://www.ruby-forum.com/t/extract-numbers-from-string/115434/5 | |
require 'benchmark' | |
n = 100_000 | |
header = 't=1570633834.463123' | |
Benchmark.bmbm do |x| | |
x.report('scan') do | |
n.times {header.scan(/\d/).join} |
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
# This code is licensed from CircleCI to the user under the MIT license. See | |
# https://circleci.com/orbs/registry/licensing for details. | |
commands: | |
hello-triggerer: | |
parameters: | |
to: | |
default: ${CIRCLE_USERNAME} | |
type: string | |
steps: | |
- run: echo "Hello << parameters.to >>" |
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
linking miniruby | |
generating encdb.h | |
./miniruby: [BUG] Segmentation fault at 0x0000000000060ee0 | |
ruby 2.5.3p105 (2018-10-18 revision 65156) [x86_64-linux-musl] | |
-- Control frame information ----------------------------------------------- | |
c:0001 p:0000 s:0003 E:000e10 (none) [FINISH] | |
-- Machine register context ------------------------------------------------ |
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('sql.active_record') do |_, _, _, _, payload| | |
puts " == Query : #{payload[:sql]}" | |
puts " == Caller: #{caller.reject{|x|x.include?('/gems/')||x.include?('/lib/ruby/')}.join("\n")}" | |
puts | |
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
Rails.application.routes.recognize_path('/api/path/to') |
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
ActiveRecord::Base.connection.exec_query("SELECT t.tablename, indexname, c.reltuples AS num_rows, pg_size_pretty(pg_relation_size(quote_ident(t.tablename)::text)) AS table_size, pg_size_pretty(pg_relation_size(quote_ident(indexrelname)::text)) AS index_size, CASE WHEN indisunique THEN 'Y' ELSE 'N' END AS UNIQUE, idx_scan AS number_of_scans, idx_tup_read AS tuples_read, idx_tup_fetch AS tuples_fetched FROM pg_tables t LEFT OUTER JOIN pg_class c ON t.tablename=c.relname LEFT OUTER JOIN ( SELECT c.relname AS ctablename, ipg.relname AS indexname, x.indnatts AS number_of_columns, idx_scan, idx_tup_read, idx_tup_fetch, indexrelname, indisunique FROM pg_index x JOIN pg_class c ON c.oid = x.indrelid JOIN pg_class ipg ON ipg.oid = x.indexrelid JOIN pg_stat_all_indexes psai ON x.indexrelid = psai.indexrelid ) AS foo ON t.tablename = foo.ctablename WHERE t.schemaname='public' ORDER BY 1,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
ActiveRecord::Base.connection.exec_query("SELECT pid, age(query_start, clock_timestamp()), state, query FROM pg_stat_activity WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%' and state = 'active' ORDER BY age(query_start, clock_timestamp())") | |
#ActiveRecord::Base.connection.exec_query("select pg_cancel_backend(123456)") # Kill by PID |
NewerOlder