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 / Dockerfile
Last active July 4, 2022 13:55
Sample Dockerfile for rails app
FROM appbase
# install npm & bower packages
WORKDIR /root
COPY package.json bower.json /root/
RUN npm install --only=prod && \
npm cache clean && \
bower install --allow-root
# install gems
@joker1007
joker1007 / ginzarb_21.md
Last active April 14, 2021 06:41
Ginza.rb 21回の発表資料。rails_adminのつらみとオススメgem達。

rails_adminのつらみとオススメGemについて

rails_adminのつらみ

カスタマイズできるようで出来ない

レコード件数が一定以上になると使えない機能

  • ダッシュボード
  • 何も考えずに各モデルをカウントするのでレコード件数増えるとえらいことになる。
@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 / 10_create_users.rb
Created May 5, 2015 11:55
FactoryGirlのtransientとtraitのサンプル
class CreateUsers < ActiveRecord::Migration
def change
create_table :users do |t|
t.string :name
t.references :user_account
t.timestamps null: false
end
end
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 / docker_build_cap.rb
Created May 11, 2016 10:16
capistranoでビルドサーバーにdocker buildを実行してもらう処理のサンプル
namespace :docker do
desc "build and push docker image on remote host"
task :build do
docker_registry_host = SSHKit::Host.new(fetch(:docker_registry_host))
docker_registry_host.ssh_options = {
user: "ec2-user",
keys: ENV['SSH_KEY'],
}
sha1 = `git rev-parse #{fetch(:branch)}`.chomp
@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