Skip to content

Instantly share code, notes, and snippets.

Avatar
:octocat:
Hire me!

OKURA Masafumi okuramasafumi

:octocat:
Hire me!
View GitHub Profile
@okuramasafumi
okuramasafumi / bench.rb
Created Nov 12, 2020
Ruby sum benchmark
View bench.rb
require 'benchmark'
huge_array = (1..10000000).to_a
Benchmark.bmbm do |x|
puts "Adding all numbers"
x.report(:sum) { huge_array.sum }
x.report(:plus_equal) { sum = 0; huge_array.each {|i| sum += i }; sum}
x.report(:inject) { huge_array.inject(:+) }
x.report(:inject_block) { huge_array.inject(0) {|memo, i| memo + i} }
@okuramasafumi
okuramasafumi / Gemfile
Last active Sep 1, 2020
Ruby JSON serializers benchmark
View Gemfile
# frozen_string_literal: true
source "https://rubygems.org"
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
gem "rails"
gem "sqlite3"
gem "jbuilder"
gem "active_model_serializers"
@okuramasafumi
okuramasafumi / after.rb
Created May 18, 2020
ActiveModelSerializerのこう書きたい
View after.rb
class HogeSerializer < ActiveModel::Serializer
attributes :id, :hogehoge
has_many :fugas do |fuga|
fuga.attributes :id, :fugafuga
fuga.has_many :bars do |bar|
bar.attributes :id, :barbar
end
end
end
View vimconf2019.txt
Keynote: Vim Renaissance
By Prabir Shrestha
"I'm thankful to people in vim-jp"
"With LSP, you don't have to configure for every language!"
"If you're not using LSP, go use it!"
It works with every language, every OS, in Vim8 or Neovim...Great!
He talks about vim so passionately, that's awesome.
He says "Go use it!" so many times, I'd like to use LSP more!
View code_location.diff
diff --git a/proc.c b/proc.c
index 19ce7a1d19..3eb8c9445d 100644
--- a/proc.c
+++ b/proc.c
@@ -1196,6 +1196,24 @@ iseq_location(const rb_iseq_t *iseq)
return rb_ary_new4(2, loc);
}
+static VALUE
+iseq_code_location(const rb_iseq_t *iseq)
@okuramasafumi
okuramasafumi / growrb-anti-harassment-policy.md
Created Apr 28, 2019
Grow.rbのアンチハラスメントポリシーです。
View growrb-anti-harassment-policy.md

Grow.rb アンチハラスメントポリシー

Grow.rbではアンチハラスメントポリシーを定めています。

以下の内容について合意・遵守いただけない場合、イベントへの参加をお断りする・イベントからの退出をお願いする場合がございますので予めご了承ください。

当ポリシーの目的

当ポリシーは参加者の皆さんにイベントを最大限に楽しんでいただくために策定されました。

@okuramasafumi
okuramasafumi / Description.md
Last active Apr 5, 2019
Weird rubygems error by redefining `find` method
View Description.md

Here, with broken_find.rb required, specification.rb raises an error saying stub is an Array.

/Users/okuramasafumi/.rubies/ruby-2.6.1/lib/ruby/site_ruby/2.6.0/rubygems/specification.rb:1065:in find_active_stub_by_path': undefined method this' for #<Array:0x00007fc3e18ff960> (NoMethodError)

The error disappears with working_find.rb required.

The only difference is whether ifnone.call if ifnone exists or not.

However, in specification.rb uses find method without ifnone argument. This means ifnone is nil.

View hash_to_proc.rb
hash = {foo: 1, bar: 2, buzz: 10}
words = %i(foo bar buzz)
p words.map(&hash) # => [1, 2, 10]
proc_obj = hash.method(:[]).to_proc
p words.map(&proc_obj) # => [1, 2, 10]
View pref_to_lat_long.rb
{
"北海道"=>{:lat=>"43.06417", :long=>"141.34694"},
"青森県"=>{:lat=>"40.82444", :long=>"140.74"},
"岩手県"=>{:lat=>"39.70361", :long=>"141.1525"},
"宮城県"=>{:lat=>"38.26889", :long=>"140.87194"},
"秋田県"=>{:lat=>"39.71861", :long=>"140.1025"},
"山形県"=>{:lat=>"38.24056", :long=>"140.36333"},
"福島県"=>{:lat=>"37.75", :long=>"140.46778"},
"茨城県"=>{:lat=>"36.34139", :long=>"140.44667"},
"栃木県"=>{:lat=>"36.56583", :long=>"139.88361"},
You can’t perform that action at this time.