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
$ make benchmark ITEM=vm_call
/Users/aaron/.rubies/arm64/ruby-trunk/bin/ruby --disable=gems -rrubygems -I./benchmark/lib ./benchmark/benchmark-driver/exe/benchmark-driver \
--executables="compare-ruby::/Users/aaron/.rubies/arm64/ruby-trunk/bin/ruby --disable=gems -I.ext/common --disable-gem" \
--executables="built-ruby::./miniruby -I./lib -I. -I.ext/common ./tool/runruby.rb --extout=.ext -- --disable-gems --disable-gem" \
--output=markdown --output-compare -v $(find ./benchmark -maxdepth 1 -name 'vm_call' -o -name '*vm_call*.yml' -o -name '*vm_call*.rb' | sort)
compare-ruby: ruby 3.4.0dev (2024-04-12T17:49:17Z master 1521af3259) [arm64-darwin23]
built-ruby: ruby 3.4.0dev (2024-04-12T19:48:34Z speed-forward 0265c020ed) [arm64-darwin23]
warming up........
# Iteration per second (i/s)
#!/Users/aaron/.rubies/arm64/ruby-trunk/bin/ruby
# This is a demo language server for Ruby, written in Ruby. It just checks
# the syntax of Ruby programs when you save them.
#
# Configure this in Vim by adding the vim-lsp plugin, then doing this
# in your vimrc:
#
# au User lsp_setup
# \ lsp#register_server({
module RBTree
module M
def insert val
RBTree.insert self, val
end
alias :<< :insert
def include?(...) = key?(...)
end
class Leaf
cons = lambda { |a, b|
lambda { |m| m.call(a, b) }
}
car = lambda { |m| m.call(lambda { |a, _| a }) }
cdr = lambda { |m| m.call(lambda { |_, b| b }) }
# A list that only uses lambdas
list = cons.call(1, cons.call(2, cons.call(3, nil)))
@tenderlove
tenderlove / mdns.rb
Created November 19, 2023 20:02
Sample mDNS client in Ruby
# mDNS client
#
# Usage: ruby script.rb "_http._tcp.local."
require "socket"
require "ipaddr"
require "fcntl"
require "resolv"
module DNSSD
(use posix)
(define (make-serialport file)
(let ((fileno
(file-open
file
(bitwise-ior open/rdwr open/noctty open/nonblock))))
; Enable blocking reads on the FD
(let ((current-fl (file-control fileno fcntl/getfl 0)))
#!/Users/aaron/.rubies/arm64/ruby-trunk/bin/ruby
# Configure Vim (using vim-lsp) like this where `ls.rb` is this script:
#
# if executable('./ls.rb')
# au User lsp_setup call lsp#register_server({
# \ 'name': 'ls.rb',
# \ 'cmd': ['./ls.rb'],
# \ 'allowlist': ['ruby'],
# \ })
#!/Users/aaron/.rubies/arm64/ruby-trunk/bin/ruby
# Configure Vim (using vim-lsp) like this where `ls.rb` is this script:
#
# if executable('./ls.rb')
# au User lsp_setup call lsp#register_server({
# \ 'name': 'ls.rb',
# \ 'cmd': ['./ls.rb'],
# \ 'allowlist': ['ruby'],
# \ })
require 'webrick'
require 'webrick/https'
require 'ds9'
class HTTP2Server < WEBrick::HTTPServer
SETTINGS = [ [DS9::Settings::MAX_CONCURRENT_STREAMS, 100] ]
class HTTP2Response < WEBrick::HTTPResponse
def initialize config, ctx, stream_id
@ctx = ctx
profiler = Thread.new do
while true
p Thread.main.backtrace
sleep 0.5
end
end
def slow_function
sleep 2
end