Skip to content

Instantly share code, notes, and snippets.

©️
   ​

Aaron Patterson tenderlove

©️
   ​
Block or report user

Report or block tenderlove

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View yamaha-receiver.rb
# 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"
View conflict.txt
[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
View after_patch.csv
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
View heapviz.rb
require 'fiddle'
color_iter = DATA.readlines.map(&:chomp).map { |i|
i = i.to_i(16)
[(i >> 16) & 0xFF, (i >> 8) & 0xFF, i & 0xFF, 255]
}.each
SIZEOF_HEAP_PAGE_HEADER_STRUCT = Fiddle::SIZEOF_VOIDP
SIZEOF_RVALUE = 40
View superduper.rb
require "ast"
class Superduper
class EnumerableAST
include Enumerable
def initialize ast
@ast = ast
end
View memory_stuff.rb
# How to measure the size of a method's iseq
require 'objspace'
small_body = (["bar"] * 10).join(" + ")
big_body = (["bar"] * 10_000).join(" + ")
eval "def small(bar); #{small_body}; end"
eval "def big(bar); #{big_body}; end"
View header.h
#ifdef __GNUC__
# pragma GCC system_header
#endif
View gc-perf.md

Benchmarks for GC Compactor

GC benchmarks for trunk vs gc-compact seem to be about the same:

$ make benchmark ITEM=gc
./revision.h unchanged
/Users/aaron/.rbenv/shims/ruby --disable=gems -rrubygems -I./benchmark/lib ./benchmark/benchmark-driver/exe/benchmark-driver \
	            --executables="compare-ruby::/Users/aaron/.rbenv/shims/ruby --disable=gems -I.ext/common --disable-gem" \
	            --executables="built-ruby::./miniruby -I./lib -I. -I.ext/common  -r./prelude --disable-gem" \
View heapviz.rb
require 'fiddle'
color_iter = DATA.readlines.map(&:chomp).map { |i|
i = i.to_i(16)
[(i >> 16) & 0xFF, (i >> 8) & 0xFF, i & 0xFF, 255]
}.each
SIZEOF_HEAP_PAGE_HEADER_STRUCT = Fiddle::SIZEOF_VOIDP
SIZEOF_RVALUE = 40
View thing.rb
begin
Integer("foo", exception: false)
def parse_int string, default
Integer(string, exception: false) || default
end
rescue TypeError
def parse_int string, default
Integer(string)
rescue
You can’t perform that action at this time.