Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View jhawthorn's full-sized avatar
⌨️

John Hawthorn jhawthorn

⌨️
View GitHub Profile
class A
def foo
@foo
end
def initialize
@foo = 123
40.times do
instance_variable_set(:"@var_#{_1}", _1)
end
@jhawthorn
jhawthorn / hawthjit.rb
Last active September 17, 2022 12:36
A "MJIT Custom Compiler" JIT in ~100 lines of Ruby
# $ ruby -v
# ruby 3.2.0dev (2022-09-11T14:08:14Z master 684353fc03) [x86_64-linux]
# $ ruby --mjit=pause --mjit-wait --mjit-min-calls=5 hawthjit.rb
# 246
# 246
# 246
# 246
# attempting to compile block in <main>
# can't compile putself
# attempting to compile double
@jhawthorn
jhawthorn / stream-2021-10-05.md
Last active October 4, 2021 22:36
Plan for Tuesday's stream 2021-10-05

Will be at https://twitch.tv/seejohnrun 4:00PM PST

Plan for Tuesday's Stream: ActionView fragment cache digesting

On a previous stream we looked at encapsulating Action View template details (format, locale, and variant) in a nice class rails/rails#42210. That code is now being used for template lookups rails/rails#42945.

Today I'd like to use these template details to change how we do Action View's fragment digests.

Currently these fragments are calculated separately for each different set of details,

class Integer
alias_method :add, :+
alias_method :+, :*
alias_method :*, :add
end
p File.readlines("data/18.txt").map {
|l| eval(l.tr("+*", "*+"))
}.sum
require "ripper"
class LocalDetector < ::Ripper
Ident = Struct.new(:value)
attr_reader :vcalls, :var_assigns, :var_refs
def initialize(code)
@vcalls = Set.new
@var_assigns = Set.new
@jhawthorn
jhawthorn / my_helper.rb
Created September 24, 2020 20:07
Ruby 2.6 autoload/inspect/name bug
module MyHelper
m = Module.new
m.inspect # #inspect break this. #name is fine. wtffffff
FooBar = m
FooBarName = FooBar.name
end
@jhawthorn
jhawthorn / git-flatfix
Last active June 30, 2020 06:52
For each changed file, generate a separate "fixup" commit targetting the last time that file was changed.
#!/usr/bin/env ruby
# git-flatfix
# For each changed file, generate a separate "fixup" commit targetting the last
# time that file was changed.
def usage
STDERR.puts <<~USAGE
Usage: git-flatfix [basebranch]
USAGE
class NullFileUpdateChecker
def initialize(files, dirs, &block)
@block = block
end
def execute
@block.call
end
def updated?
@jhawthorn
jhawthorn / benchmark_first_request.rb
Last active September 10, 2019 17:55
Script to benchmark the initial request after a fork. Records stats and makes a flamegraph
REQUEST_URI = ARGV[0] || "http://0.0.0.0/"
REQUEST_OPTS = {
'REMOTE_ADDR' => "127.0.0.1",
'HTTP_HOST' => '0.0.0.0'
}
ARGV.clear
require "actionview_precompiler"
require "flamegraph"
require "./config/environment"
# frozen_string_literal: true
ENV['RAILS_ROOT'] = "/Users/jhawthorn/src/current_status/"
require 'benchmark/ips'
require 'rails/all'
require 'rails/backtrace_cleaner'
class MyApp < Rails::Application
config.root = "/Users/jhawthorn/src/current_status"