Skip to content

Instantly share code, notes, and snippets.

View joker1007's full-sized avatar

Tomohiro Hashidate joker1007

View GitHub Profile
class Foo
attr_reader :hoge, :fuga,
def initialize(a, b)
p a
p b
end
end
Foo.new # => no error
@joker1007
joker1007 / pipewire_audio_selector.sh
Last active February 19, 2024 20:29
pipewire audio selector
#!/bin/bash
id=$(pw-dump Node | jq -r 'map({id: .id, class: .info.props["media.class"], desc: .info.props["node.description"]} | select(.desc != null)) | sort_by(.class, .desc) | .[] | [.id, .class, .desc] | @tsv' | wofi -di | cut -f 1)
if [ -n "$id" ]; then
echo "Setting default to $id"
wpctl set-default $id
fi
@joker1007
joker1007 / extend_ebs.sh
Created March 30, 2021 12:22
extend_ebs.sh
instance_ids=""
device_name=""
for vol in $(aws ec2 describe-instances --region ap-northeast-1 --instance-ids ${instance_ids} | jq '.Reservations[].Instances[] | .BlockDeviceMappings[] | select(.DeviceName == "'${device_name}'") | .Ebs.VolumeId' -r); do
current=$(aws ec2 describe-volumes --volume-ids ${vol} | jq '.Volumes[] | .Size')
target=$(expr $current + 50)
echo "${vol}: ${current} -> ${target}"
echo "aws ec2 modify-volume --volume-id ${vol} --size ${target} --dry-run"
#aws ec2 modify-volume --volume-id ${vol} --size ${target} --dry-run
done
@joker1007
joker1007 / 01-for.rb
Last active March 25, 2021 08:03
ruby_for_insn
for i in [1, 2, 3]
p i
j = i
end
p j
[1, 2, 3].each do |k|
l = k
end
@joker1007
joker1007 / benchmark.md
Last active January 11, 2021 15:38
Ruby-3.0.0 benchmark with optcarrot on Ryzen9 5900X

Environment

Linux 5.10.6-gentoo #1 SMP PREEMPT Mon Jan 11 02:51:36 JST 2021 x86_64 AMD Ryzen 9 5900X 12-Core Processor AuthenticAMD GNU/Linux
% cat /proc/cpuinfo
processor	: 0
vendor_id	: AuthenticAMD
@joker1007
joker1007 / segv_with_debug_inspector_and_tracepoint.rb
Last active July 23, 2019 13:24
segv with debug_inspector and tracepoint
require "debug_inspector"
class Foo
def meth1(&block)
RubyVM::DebugInspector.open do |dc|
iseq = dc.frame_iseq(2)
trace = TracePoint.new(:b_return) do |tp|
pp tp
tp.disable
end
@joker1007
joker1007 / proc_test.rb
Created December 26, 2018 11:08
ruby-2.6
class Symbol
alias :& :to_proc
end
pp ((1..)%2).each.lazy.map(&(:succ.& >> :succ.& >> :to_s.&)).take(10).force
class Object
def defer(method, *args)
@current_fibers ||= []
@tracepoint ||= TracePoint.trace(:return) do |tp|
@current_fibers.reverse_each do |fib|
fib.resume
end
end
@current_fibers << Fiber.new do
@joker1007
joker1007 / unbound_method.rb
Created January 23, 2018 17:28
unbound method equality
class C1
def meth
end
end
class C2 < C1
def meth
end
end
@joker1007
joker1007 / log.md
Created October 4, 2017 13:42
fluentd in_foward error?
Oct 04 22:05:37 ip-172-31-11-88 fluentd-aggregator: 2017-10-04 13:05:31 +0000 [error]: #0 unexpected error on reading data host="ip-172-31-14-22.ap-northeast-1.compute.internal" port=34018 error_class=NoMethodError error="undefined method `[]=' for nil:NilClass"
Oct 04 22:05:37 ip-172-31-11-88 fluentd-aggregator:   2017-10-04 13:05:31 +0000 [error]: #0 /fluentd/etc/vendor/bundle/ruby/2.3.0/gems/fluentd-0.14.20/lib/fluent/plugin/in_forward.rb:367:in `block in add_source_info'
Oct 04 22:05:37 ip-172-31-11-88 fluentd-aggregator:   2017-10-04 13:05:31 +0000 [error]: #0 /fluentd/etc/vendor/bundle/ruby/2.3.0/gems/fluentd-0.14.20/lib/fluent/event.rb:264:in `block in each'
Oct 04 22:05:37 ip-172-31-11-88 fluentd-aggregator:   2017-10-04 13:05:31 +0000 [error]: #0 /fluentd/etc/vendor/bundle/ruby/2.3.0/gems/fluentd-0.14.20/lib/fluent/event.rb:261:in `feed_each'
Oct 04 22:05:37 ip-172-31-11-88 fluentd-aggregator:   2017-10-04 13:05:31 +0000 [error]: #0 /fluentd/etc/vendor/bundle/ruby/2.3.0/gems/fluentd-0.14.20/lib/f