Skip to content

Instantly share code, notes, and snippets.

View carloslopes's full-sized avatar

Carlos Lopes carloslopes

View GitHub Profile
@carloslopes
carloslopes / analyzer.rb
Last active January 13, 2021 15:46
Simple memory used and time spent script
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 19:38
Ruby Process Memory Usage Monitor
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 August 29, 2015 13:56
DatabaseCleaner configuration
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
<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 December 29, 2015 10:39
Ruby Hash to-from dotted notation hash
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 December 27, 2015 16:19 — forked from ericboehs/gist:7125105
Workaround for CoreText performance notes when using phantomjs on OS X Mavericks
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
~/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 September 25, 2013 12:05
Threaded sinatra app
sinatra_thread = Thread.new do
require 'sinatra/base'
class SinatraServer < Sinatra::Base
get '/hi' do
"Hello World!"
end
run!
end
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 September 3, 2017 09:44 — forked from joost/ruby_google_analytics_server_to_server.md
Google Analytics API (server-to-server) using Ruby