Skip to content

Instantly share code, notes, and snippets.

View willnet's full-sized avatar
👶
parenting

Shinichi Maeshima willnet

👶
parenting
View GitHub Profile
# frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
gem "rails", "7.0.8.4"
# If you want to test against edge Rails replace the previous line with this:
# gem "rails", github: "rails/rails", branch: "main"
@willnet
willnet / rails_7_2_new_features.md
Last active September 5, 2024 05:55
Rails7.2のマイナーフィーチャーで気になったところ

これはなに

  • 現時点(2024/08/30)でRails7.2.1がリリースされています
  • Ruby on Rails 7.2 Release Notes — Ruby on Rails Guides にメジャーフィーチャーが書かれている
  • マイナーフィーチャーはよくわからないので、個人的に気になったマイナーフィーチャをまとめています

Railties

rails bootコマンドの追加

@willnet
willnet / inspect_associations.rb
Last active August 7, 2023 02:06
get association models
require 'set'
class InspectAssociations
def self.call(model)
new.call(model)
end
def call(model)
return if set.include?(model)
set.add(model)
@willnet
willnet / video.rb
Last active April 20, 2023 09:28
screenshot video sample
require 'ferrum'
require 'base64'
browser = Ferrum::Browser.new(logger: File.open('/tmp/hoge.log', 'w'))
Dir.mktmpdir do |dir|
browser.on('Page.screencastFrame') do |params, index, total|
File.open("#{dir}/#{Time.now.strftime('%Y%m%d%H%M%S%L.jpeg')}", 'w') do |f|
f.write(Base64.decode64(params['data']))
end
@willnet
willnet / should_have_length_validations.rb
Last active May 13, 2022 02:42
string型もしくはtext型なのに最大長のバリデーションをかけていないものを出力するスクリプト
ActiveRecord::Base.descendants.reject(&:abstract_class?).each do |model|
string_or_text_columns = model.columns.select { |column| column.type == :string || column.type == :text }
columns_with_maximum_length_validation = model.validators.select {|v| v.is_a? ActiveRecord::Validations::LengthValidator }.select {|v| v.options[:maximum] || v.options[:within] }.map(&:attributes).flatten.uniq
string_or_text_columns.each do |column|
if columns_with_maximum_length_validation.include?(column.name.to_sym)
puts "#{model.name}##{column.name} is OK"
else
puts "#{model.name}##{column.name} is NG"
end
end
@willnet
willnet / sample_from_atendees.js
Last active July 3, 2024 03:22
google meet参加者から誰か一人をランダムで選択するスクリプト
// chromeを利用して、ユーザ一覧を表示しつつconsoleで↓を実行すると、現在の参加者からランダムで一人表示することができます
const names_array = document.querySelector("[aria-label='参加者']").innerText.split("\n").filter((word)=> !word.match(/\(|メイン|ミュート|主催者|あなたの画面共有|その他の操作|keep_off|more_vert|keep|domain_disabled/))
const names_set = new Set(names_array)
const names_uniq_array = Array.from(names_set)
names_uniq_array[Math.floor(Math.random() * names_uniq_array.length)]
source 'https://rubygems.org'
platforms :jruby do
gem 'railties'
end
group :test do
gem 'railties'
end
@willnet
willnet / application_record.rb
Last active September 8, 2021 01:30
ARのオブジェクトを生成しているところがどこか探すコード
class ApplicationRecord < ActiveRecord::Base
@ar_initialize_counter = Hash.new(0)
@ar_find_counter = Hash.new(0)
after_initialize :count_initialize
def count_initialize
return unless ApplicationRecord.enable_counter?
gems_paths = (Gem.path | [Gem.default_dir]).map { |p| Regexp.escape(p) }
caller_in_app = caller.find { |file_and_lineno| file_and_lineno !~ gems_paths}
@willnet
willnet / webpackconfig-from-webpacker5.4.2.js
Last active August 23, 2021 13:34
webpackconfig.js comparison between webpacker6-rc1 and webpacker5.4.2
{
"mode": "development",
"output": {
"filename": "js/[name]-[contenthash].js",
"chunkFilename": "js/[name]-[contenthash].chunk.js",
"hotUpdateChunkFilename": "js/[id]-[hash].hot-update.js",
"path": "/Users/willnet/tmp/webpacker5/public/packs",
"publicPath": "/packs/"
},
"resolve": {
@willnet
willnet / rails_6_1_new_features.md
Last active October 13, 2023 01:10
「Rails 6.1で新しく入る機能について」iCARE Dev Meetup #12 の登壇内容 https://icare.connpass.com/event/183716/

Rails 6.1で新しく入る機能について

@willnet

最近のRailsリリース日

  • 6.0.0 (2019/08/06)
  • 5.2.0 (2018/04/09)
  • 5.1.0 (2017/04/27)
  • 5.0.0 (2016/06/30)