Skip to content

Instantly share code, notes, and snippets.

@davygora
davygora / list_indexes_in_rails_console.rb
Created September 10, 2018 12:36
Get list of all indexes in rails console.
# rails console
ActiveRecord::Base.connection.tables.each do |table|
indexes = ActiveRecord::Base.connection.indexes(table)
if indexes.length > 0
puts "====> #{table} <===="
indexes.each do |index|
puts "----> #{index.name}"
end
puts "====> #{table} <===="
@rpdelaney
rpdelaney / traceback_exc.py
Last active August 2, 2024 13:20
Serialize python exceptions into dictionaries
import traceback
from typing import Dict, Union, List
def traceback_exc(exc: Exception) -> Dict[str, Union[str, List[str]]]:
tb = traceback.TracebackException.from_exception(exc, capture_locals=True)
return {
"title": type(exc).__name__,
"message": str(exc),
"traceback": [
@tomholford
tomholford / install_pg_gem.md
Last active October 21, 2024 19:08
Install postgresql gem `pg` on macOS

Installing pg gem on macOS

If you're trying to install the postgresql gem pg and it is failing with the following error message:

Installing pg 1.2.3 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: ~/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/pg-1.2.3/ext
~/.rbenv/versions/3.0.0/bin/ruby -I ~/.rbenv/versions/3.0.0/lib/ruby/3.0.0 -r ./siteconf20210125-97201-pycpo.rb extconf.rb