Skip to content

Instantly share code, notes, and snippets.

View benoittgt's full-sized avatar
🏴

Benoit Tigeot benoittgt

🏴
View GitHub Profile
require 'nokogiri'
require 'open-uri'
# Get a Nokogiri::HTML:Document for the page we're interested in...
doc = Nokogiri::HTML(open('http://www.google.com/search?q=tenderlove'))
# Do funky things with it using Nokogiri::XML::Node methods...
####
ActiveSupport::Notifications.subscribe 'halted_callback.action_controller' do |name, start, finish, id, payload|
Rails.logger.warn { '=' * 80 }
Rails.logger.warn { "HALTED CALLBACK: #{ payload[:filter] }" }
end
@csfrancis
csfrancis / gdb_ruby_backtrace.py
Last active June 25, 2024 19:12
Dump an MRI call stack from gdb
# Updated for Ruby 2.3
string_t = None
def get_rstring(addr):
s = addr.cast(string_t.pointer())
if s['basic']['flags'] & (1 << 13):
return s['as']['heap']['ptr'].string()
else:
return s['as']['ary'].string()
@rogerleite
rogerleite / converters.rb
Last active August 28, 2024 19:34
Ruby and CSV examples
require "csv"
require "date"
puts CSV::HeaderConverters.keys.inspect # => [:downcase, :symbol]
# Add new header converter
CSV::HeaderConverters[:remap] = lambda do |raw_value|
raw_value = raw_value.to_sym
case raw_value
when :country
@juliandunn
juliandunn / postgresql-on-aws-tips.md
Last active September 27, 2022 10:55
Notes on PostgreSQL performance optimization on RDS

Deep Dive: PostgreSQL on AWS

When loading data

  • disable backups (backup_retention=0)
  • disable multi-AZ and autovacuum
  • pg_dump -Fc (compressed) and pg_restore -j (parallel)
  • Increase maintenance_work_mem
@davidpdrsn
davidpdrsn / Profiling.markdown
Last active June 16, 2017 10:57
Ruby benchmarking and benchmarking notes

(because I can't remember anything)

Setup

gem install benchmark-ips
gem install stackprof
gem install allocation_tracer
Vim Script
===========
#Defining functions
```VimL
fun! Foo()
" function body
endfun
@mattheworiordan
mattheworiordan / cli.rb
Created January 9, 2015 12:21
Thor with subcommands that work correctly with help
#!/usr/bin/env ruby
require 'thor'
class SubCommandBase < Thor
def self.banner(command, namespace = nil, subcommand = false)
"#{basename} #{subcommand_prefix} #{command.usage}"
end
def self.subcommand_prefix

TIL attr_* methods are optomized.

class Whatever
  def foo
    @foo
  end

  attr_reader :bar
end
@kazu69
kazu69 / database_clenaer.rb
Last active October 13, 2023 14:44
Such as setting when you write a test of parallel processing in ActiveRecord
# spec_helper.rb
RSpec.configure do |config|
...
# テスト完了後一度だけ実行される
config.after(:suite) do
DatabaseCleaner.clean_with(:truncation)
end
# 各テスト実行前に実行される
config.before(:each) do |spec|