You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Instantly share code, notes, and snippets.
Stan Lo
st0012
Ruby Tooling Developer. Maintaining IRB, Reline, RDoc and built ruby-lsp-rspec.
Rails 7.0.1 addes net-smtp, net-imap and net-pop gems as Action Mailbox and Action Mailer dependency, you do not need to add them explicitly in your application Gemfile anymore.
thor 1.2.1 has been released. You will not see DidYouMean::SPELL_CHECKERS.merge deprecate warnings anymore.
Rails 6.1.Z
Use Rails 6.1.5 to support database.yml with aliases and secrets.yml with aliases.
Steps to get GDB actually working in April 2021 on macOS (Intel x86-64 only)
Debug with GDB on macOS 11
The big reason to do this is that LLDB has no ability to "follow-fork-mode child", in other words, a multi-process target that doesn't have a single-process mode (or, a bug that only manifests when in multi-process mode) is going to be difficult or impossible to debug, especially if you have to run the target over and over in order to make the bug manifest. If you have a repeatable bug, no big deal, break on the fork from the parent process and attach to the child in a second lldb instance. Otherwise, read on.
Install GDB
Don't make the mistake of thinking you can just brew install gdb. Currently this is version 10.2 and it's mostly broken, with at least two annoying bugs as of April 29th 2021, but the big one is https://sourceware.org/bugzilla/show_bug.cgi?id=24069
$ xcode-select install # install the XCode command-line tools
This file contains hidden or 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
π Ping me @cheeaun on Twitter or leave a comment below if you found some awesome stuff for #rdrc2016. This gist will be updated whenever there's new stuff.
Ruby module that you can use in a `before_action` on sensitive controllers for which you'd like a usage audit trail
Adding an audit log to your Rails app
If you have any sort of administrative interface on your web site, you can easily imagine an intruder gaining access and mucking about. How do you know the extent of the damage? Adding an audit log to your app is one quick solution. An audit log should record a few things:
controller entry points with parameter values
permanent information about the user, like user_id
transient information about the user, like IP and user_agent
Using the Rails framework, this is as simple as adding a before_action to your admin controllers. Hereβs a basic version that Iβm using in production.
When developing a program in Ruby, you may sometimes encounter a memory leak.
For a while now, Ruby has a facility to gather information about what objects are laying around:
ObjectSpace.
There are several approaches one can take to debug a leak. This discusses a time-based approach, where
a full memory dump is generated every, say, 5 minutes, during a time that the memory leak is showing up.
Afterwards, one can look at all the objects, and find out which ones are staying around, causing the
UPDATE a fork of this gist has been used as a starting point for a community-maintained "awesome" list: machine-learning-with-ruby Please look here for the most up-to-date info!
Comprehensive Guide to Ruby Performance Benchmarking
GC.disable
Wall Clock Time versus CPU Time
An important difference to note is the how time is reported by various measurement methods. Wall clock time is the actual time passed in terms of human perception whereas CPU time is the time spent processing the work. CPU time doesn't include any delays waiting on resources to free up such as thread interrupts or garbage collection.
The Work to Measure
To keep things simple, we'll create a Ruby Proc and just repeatedly call that Proc for each of the measurement methods below.