Skip to content

Instantly share code, notes, and snippets.

Avatar

Carlos Eduardo L. Lopes carloslopes

View GitHub Profile
@carloslopes
carloslopes / analyzer.rb
Last active Jan 13, 2021
Simple memory used and time spent script
View analyzer.rb
require 'benchmark'
class Analyzer
def self.print_memory_usage
memory_before = `ps -o rss= -p #{Process.pid}`.to_i
yield
memory_after = `ps -o rss= -p #{Process.pid}`.to_i
puts "Memory: #{((memory_after - memory_before) / 1024.0).round(2)} MB"
end
@carloslopes
carloslopes / example.rb
Created May 11, 2015
Ruby Process Memory Usage Monitor
View example.rb
require_relative 'lib/memory_usage_monitor'
mm = MemoryUsageMonitor.new
mm.start
sum = 0
items = []
5_000_000.times do |n|
sum += n
items << n.to_s if rand > 0.8
@carloslopes
carloslopes / database_cleaner.rb
Last active Aug 29, 2015
DatabaseCleaner configuration
View database_cleaner.rb
RSpec.configure do |config|
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
config.use_transactional_fixtures = false
config.before :suite do
DatabaseCleaner.clean_with :truncation
end
View gist:9092385
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing">
<s:Header>
<a:Action s:mustUnderstand="1">http://www.w3.org/2005/08/addressing/soap/fault</a:Action>
</s:Header>
<s:Body>
<s:Fault>
<s:Code>
<s:Value>s:Sender</s:Value>
<s:Subcode>
<s:Value>a:DestinationUnreachable</s:Value>
@carloslopes
carloslopes / gist:7658120
Last active Dec 29, 2015
Ruby Hash to-from dotted notation hash
View gist:7658120
class Hash
def to_dotted_hash(recursive_key = '')
self.each_with_object({}) do |(k, v), ret|
key = recursive_key + k.to_s
if v.is_a?(Hash)
ret.merge!(v.to_dotted_hash(key + '.'))
else
ret[key] = v
end
@carloslopes
carloslopes / gist:7354100
Last active Dec 27, 2015 — forked from ericboehs/gist:7125105
Workaround for CoreText performance notes when using phantomjs on OS X Mavericks
View gist:7354100
module Capybara::Poltergeist
class Client
private
def redirect_stdout
prev = STDOUT.dup
prev.autoclose = false
$stdout = @write_io
STDOUT.reopen(@write_io)
prev = STDERR.dup
View gist:7353841
~/Projects/PremiosOnline(branch:master) » rspec spec carloslopes@Carlos-MacBook-Air
.............................................................................................................................................2013-11-07 09:50:14.413 phantomjs[29903:507] CoreText performance note: Client called CTFontCreateWithName() using name "Arial" and got font with PostScript name "ArialMT". For best performance, only use PostScript names when calling this API.
2013-11-07 09:50:14.413 phantomjs[29903:507] CoreText performance note: Set a breakpoint on CTFontLogSuboptimalRequest to debug.
2013-11-07 09:50:14.416 phantomjs[29903:507] CoreText performance note: Client called CTFontCreateWithName() using name "Arial" and got font with PostScript name "ArialMT". For best performance, only use PostScript names when calling this API.
2013-11-07 09:50:14.417 phantomjs[29903:507] CoreText performance note: Client called CTFontCreateWithName() using n
@carloslopes
carloslopes / gist:6698708
Created Sep 25, 2013
Threaded sinatra app
View gist:6698708
sinatra_thread = Thread.new do
require 'sinatra/base'
class SinatraServer < Sinatra::Base
get '/hi' do
"Hello World!"
end
run!
end
View gist:6541539
Msg 208, Level 16, State 1, Procedure FN_CLUBE_VANTAGENS_CAMPANHA, Line 15
Invalid object name 'TB_CAMPANHA'.
Msg 213, Level 16, State 1, Procedure JP_INS_PONTUACAO_CONSOLIDADA_PONTUACAO, Line 11
Column name or number of supplied values does not match table definition.
Msg 7308, Level 16, State 1, Procedure JP_INSERE_PARTICIPANTE_EXCEL, Line 11
OLE DB provider 'Microsoft.Jet.OLEDB.4.0' cannot be used for distributed queries because the provider is configured to run in single-threaded apartment mode.
The module 'JP_APURACAO_INS_PREMIACAO_POL_2' depends on the missing object 'JP_APURACAO_INS_APROVACAO_NEGADO'. The module will still be created; however, it cannot run successfully until the object exists.
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near 'CONSTR'.
@carloslopes
carloslopes / gist:6306255
Last active Sep 3, 2017 — forked from joost/ruby_google_analytics_server_to_server.md
Google Analytics API (server-to-server) using Ruby
View gist:6306255