Skip to content

Instantly share code, notes, and snippets.

View bench2.rb
require 'benchmark/ips'
string = <<~STRING
Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean. A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth. Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far World of Grammar. The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks and devious Semikoli, but the Little Blind Text didn’t listen. She packed her seven versalia, put her initial into the belt and made herself on the way. When she reached the first hills of the Italic Mountains, she had a last view back on the skyline of her
View bench.rb
require 'benchmark/ips'
string = <<~STRING
Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean. A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth. Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far World of Grammar. The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks and devious Semikoli, but the Little Blind Text didn’t listen. She packed her seven versalia, put her initial into the belt and made herself on the way. When she reached the first hills of the Italic Mountains, she had a last view back on the skyline of her
View gist:3cf5b725fdc5f469b453c405f4e3c433
<svg xmlns="http://w3.org/2000/svg" width="385" height="104" viewBox="0 0 385 104">
<g id="discourse-logo-large" fill="none" fill-rule="nonzero">
<path fill="#000" d="M117.4 22.22c1.649399-.0222812 3.233299.6446239 4.37 1.84 1.192379 1.1784439 1.850092 2.7938161 1.82 4.47.02983 1.6575188-.620685 3.2548933-1.8 4.42-1.119242 1.1834351-2.681214 1.8466391-4.31 1.83-1.662331.023056-3.258247-.6515814-4.4-1.86-1.195146-1.1971019-1.852129-2.8287301-1.82-4.52-.000018-3.3998017 2.750216-6.1589796 6.15-6.17l-.01-.01zm-4.84 21.05h9.68v40.36h-9.68V43.27zm42.1 6.39l-6 6C146.22 53.22 144 52 142 52c-.902316-.0524313-1.79724.1897247-2.55.69-.573152.3850847-.91784 1.0295007-.92 1.72.003314.536265.210697 1.0511472.58 1.44.861614.7548917 1.836939 1.3691103 2.89 1.82l3.55 1.77c3.733333 1.8466667 6.3 3.7266667 7.7 5.64 3.339481 4.8109001 2.622713 11.3471474-1.68 15.32-2.52 2.2933333-5.896667 3.44-10.13 3.44-5.290881.1460857-10.315591-2.3176674-13.44-6.59l6-6.49c1.120876 1.3107131 2.47767 2.3995407 4 3.21 1.21567.7242383 2.58
View test.rb
require 'mini_racer'
ctx = MiniRacer::Context.new
ctx.attach("print", proc {|x| puts x})
ctx.attach("read", proc {|f, type| File.read(f)})
ctx.attach("quit", proc {|status| exit(status)})
ctx.attach("readbuffer", proc {|f| File.read(f).each_char.map(&:to_i)})
#ctx.eval("WebAssembly.instantiate(readbuffer('hello.wasm'), { imports: {} }).then(r => print(999)).catch(e => print('bang'))")
#ctx.eval("1")
View memoize.rb
#require_relative '../rerunner/rerunner'
require 'benchmark/ips'
module Memoizer
def memoize_26(method_name)
cache = {}
uncached = "#{method_name}_without_cache"
alias_method uncached, method_name
View Desktop Arch Native
Running benchmark on 1 thread
--------------------
Topic View (dev): 6.298 (±20.8%) op/s
Topic Creation Time - no background queue: 3.855 (±7.1%) op/s
Cooking README.md: 100.992 (±55.9%) op/s
Booting Rails: 1.506 (±1.3%) seconds
Running benchmark on 16 threads
--------------------
View gist:6f9ffec0162c475152a5176ab9401ee9
require 'active_record'
config = <<~CONF
development:
adapter: sqlite3
database: ":memory:"
host_names:
- test.localhost
CONF
View test_concurrency.rb
require 'active_record'
require 'rails_multisite'
require 'tempfile'
conn = RailsMultisite::ConnectionManagement
config = <<~CONF
development:
adapter: sqlite3
database: ":memory:"
View test.rb
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'pg', '1.2.2'
end
$max_time = 2
Thread.new do
View gist:20bd346a5b94d7e2172413f8cc03aa5e
bundle exec rails c
/home/sam/.gem/truffleruby/2.6.5/gems/zeitwerk-2.2.2/lib/zeitwerk/kernel.rb:23:in `require': /home/sam/Source/discourse/lib/stylesheet/importer.rb:214: multiple assignment in conditional (SyntaxError)
from /home/sam/.gem/truffleruby/2.6.5/gems/zeitwerk-2.2.2/lib/zeitwerk/kernel.rb:23:in `require'
from /home/sam/.gem/truffleruby/2.6.5/gems/activesupport-6.0.1/lib/active_support/dependencies.rb:325:in `block in require'
from /home/sam/.gem/truffleruby/2.6.5/gems/activesupport-6.0.1/lib/active_support/dependencies.rb:289:in `block in load_dependency'
You can’t perform that action at this time.