Skip to content

Instantly share code, notes, and snippets.

View shioyama's full-sized avatar

Chris Salzberg shioyama

View GitHub Profile
@shioyama
shioyama / gsub_benchmark.rb
Last active October 15, 2020 06:37
Remove pry, don't need it
#!/usr/bin/env ruby
# frozen_string_literal: true
#
# This script demonstrates a performance regression introduced in https://github.com/rails/rails/pull/34405
# That PR patched ActiveSupport::SafeBuffer methods gsub, gsub!, sub and sub! to set backreferences, but
# in doing so incurred a significant penalty.
#
# This script creates a random string with texts at random locations which are swapped with gsub. The string
# is random but seeded the same each run, so the same length produces the same string.
#
@shioyama
shioyama / dry_types_optional.rb
Created June 11, 2019 07:44
Force "optional" to really mean "optional"
# It's annoying to write meta(required: false) everywhere, so let's just make
# "optional" do the same thing.
Dry::Types::Builder.module_eval do
def optional
meta(required: false)
end
end
@shioyama
shioyama / webpacker_sync.rake
Last active June 24, 2020 13:34
Sync files from Rails webpacker manifest.json to S3 asset bucket.
# Sync files from webpacker manifest.json to S3 asset bucket.
# Based on asset_sync but much simplified for this case.
#
# Requirements
#
# Add fog to Gemfile.
#
# Environment variables:
# - AWS_S3_ASSETS_BUCKET_NAME
# - AWS_S3_REGION
@shioyama
shioyama / sway.log
Created December 2, 2018 01:39
Resizing urxvt terminal font size
2018-12-02 10:19:05 - [xwayland/xwm.c:418] XCB_ATOM_WM_NAME: echo -e "\e]710;xft:Sans:size=18\007"
2018-12-02 10:19:05 - [sway/sway/ipc-server.c:329] Sending window::title event
2018-12-02 10:19:05 - [xwayland/xwm.c:923] XCB_PROPERTY_NOTIFY (12582922)
2018-12-02 10:19:05 - [xwayland/xwm.c:688] unhandled X11 property 37 (WM_ICON_NAME) for window 12582922
2018-12-02 10:19:05 - [xwayland/xwm.c:923] XCB_PROPERTY_NOTIFY (12582922)
2018-12-02 10:19:05 - [xwayland/xwm.c:688] unhandled X11 property 335 (_NET_WM_ICON_NAME) for window 12582922
2018-12-02 10:19:05 - [xwayland/xwm.c:923] XCB_PROPERTY_NOTIFY (12582922)
2018-12-02 10:19:05 - [xwayland/xwm.c:572] WM_NORMAL_HINTS (18)
2018-12-02 10:19:05 - [xwayland/xwm.c:838] XCB_CONFIGURE_REQUEST (12582922) [4834x1512+-1457,-442]
2018-12-02 10:19:05 - [xwayland/xwm.c:923] XCB_PROPERTY_NOTIFY (12582922)
class MyModule < Module
def initialize(&block)
block.call(self)
end
end
MyModule.new do |mod|
puts mod.class
end
#=> MyModule

RubyKaigi 2017 Sponsorship Prospectus

Page 2

Left

RubyKaigi is an international conference on the Ruby Object-Oriented programming language.

Once a year, Rubyists from all around the world converge on Japan, Ruby's

Keybase proof

I hereby claim:

  • I am shioyama on github.
  • I am shioyama (https://keybase.io/shioyama) on keybase.
  • I have a public key ASCdFFAduowUMfL1VWpiW8FOQVaqd21fHcKT6cFIAMLFfwo

To claim this, I am signing this object:

Spree::OrderPopulator.class_eval do
def populate_with_options(from_hash)
binding.pry
if variants_with_options = from_hash[:variants].select { |variant, quantity| quantity.is_a?(Hash) }
variants_with_options.each do |variant_id, options|
quantity = options.delete(:quantity) || 1
attempt_cart_add(variant_id, quantity)
if (line_item = order.line_items.where(variant_id: variant_id).first)
line_item.assign_options!(options)