Skip to content

Instantly share code, notes, and snippets.

View tenderlove's full-sized avatar
©️
 ​[object Object] :trollface:

Aaron Patterson tenderlove

©️
 ​[object Object] :trollface:
View GitHub Profile
# Method tables and constant tables are lazily allocated. When a module is
# mixed in to a class, it creates an ICLASS which is the object used to
# represent the module in the inheritance hierarchy. The ICLASS object shares
# some tables with the source module, so when it gets created Ruby will
# allocate these tables to share even if they didn't exist previously.
#
# You can see the tables get allocated in this function:
# https://github.com/ruby/ruby/blob/962c302a1ae8e50738c36adb61c8ec9c9fa5a49b/class.c#L832-L862
#
# Output on my machine:
class Infinite
def each
return enum_for(:each) unless block_given?
loop do
('a'..'zzz').each do |m|
yield m
end
end
end
end

URI.encode deprecations

We're getting these deprecation warnings because URI.encode the method doesn't really makes sense. Paths in URIs are escaped differently than query parameters, and those are escaped differently than anchors (I think). So fixing these warnings isn't always straight forward. We need to think about the context in which the data will be used. Typically I've seen this method used with query parameters, and in that case we should use URI.encode_www_form.

Keyword Argument Deprecations

From b5aeef5703dab7da9ebb47cc20e4c8b64f7f5866 Mon Sep 17 00:00:00 2001
From: Aaron Patterson <aaron.patterson@gmail.com>
Date: Thu, 12 Mar 2020 10:25:48 -0700
Subject: [PATCH] Fix possible XSS vector in JS escape helper
This commit escapes dollar signs and backticks to prevent JS XSS issues
when using the `j` or `javascript_escape` helper
CVE-2020-5267
---
# frozen_string_literal: true
require "active_record"
require "active_record/railties/collection_cache_association_loading"
require "action_controller"
require "action_view"
require "tmpdir"
require "benchmark/ips"
ActionView::PartialRenderer.prepend(ActiveRecord::Railties::CollectionCacheAssociationLoading)
# An example of calculating least-squares linear regression fit in Ruby
#
# This is free and unencumbered software released into the public domain.
#
# Anyone is free to copy, modify, publish, use, compile, sell, or
# distribute this software, either in source code form or as a compiled
# binary, for any purpose, commercial or non-commercial, and by any
# means.
#
# In jurisdictions that recognize copyright laws, the author or authors
#!/usr/bin/erb
<%= yield %>
#!/usr/bin/env ruby
# frozen_string_literal: true
require "action_controller"
require "action_view"
# Watch Yamaha AV receivers for events
#
# This script watches a Yamaha AV receiver for changes in state.
# It also implements two functions for changing the volume which is a fun
# way to "help" unsuspecting users.
#
# Protocol is here: https://www.sdu.se/pub/yamaha/yamaha-ynca-receivers-protocol.pdf
require "socket"
require "io/wait"
[aaron@TC ~/git]$ ruby -rminitest/autorun -e' '
Traceback (most recent call last):
9: from /Users/aaron/.rbenv/versions/ruby-trunk/lib/ruby/gems/2.7.0/gems/minitest-5.11.3/lib/minitest.rb:63:in `block in autorun'
8: from /Users/aaron/.rbenv/versions/ruby-trunk/lib/ruby/gems/2.7.0/gems/minitest-5.11.3/lib/minitest.rb:121:in `run'
7: from /Users/aaron/.rbenv/versions/ruby-trunk/lib/ruby/gems/2.7.0/gems/minitest-5.11.3/lib/minitest.rb:92:in `load_plugins'
6: from /Users/aaron/.rbenv/versions/ruby-trunk/lib/ruby/gems/2.7.0/gems/minitest-5.11.3/lib/minitest.rb:92:in `each'
5: from /Users/aaron/.rbenv/versions/ruby-trunk/lib/ruby/gems/2.7.0/gems/minitest-5.11.3/lib/minitest.rb:98:in `block in load_plugins'
4: from /Users/aaron/.rbenv/versions/ruby-trunk/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:54:in `require'
3: from /Users/aaron/.rbenv/versions/ruby-trunk/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:54:in `require'
2: from /Users/aaron/.rbenv/versions/ruby-trunk/lib/ruby/gems/2.7.0/gems/rai
real cstime cutime stime utime total
47.30989000003319 8.122842 37.494842999999996 0.005576000000000025 0.00012099999999998223 45.62338199999999
49.633449999964796 9.02866 37.767471 0.0045399999999999885 0.00013900000000000023 46.800810000000006
46.255383000010625 7.929361999999998 37.034392999999994 0.0045099999999999585 0.000124000000000013 44.968388999999995
46.28654599993024 8.027361000000003 36.961467 0.004464999999999997 0.00012499999999998623 44.993418000000005
45.782935000024736 8.010796999999997 36.488111 0.004514000000000018 0.00012700000000004374 44.503549
48.835172999999486 8.771659 37.279645000000016 0.004508999999999985 0.00012700000000004374 46.055940000000014
49.2580490000546 9.047513000000002 37.05552799999998 0.00464500000000001 0.00013699999999999823 46.10782299999998
45.05590499995742 7.856316000000007 36.05048099999999 0.0061370000000000036 0.00015100000000001224 43.913084999999995
45.321803999948315 7.876872999999989 36.332494 0.004386999999999974 0.00011899999999998023 44.21387299999998