Skip to content

Instantly share code, notes, and snippets.

View willnet's full-sized avatar
👶
parenting

Shinichi Maeshima willnet

👶
parenting
View GitHub Profile
@willnet
willnet / sample_from_atendees.js
Last active November 11, 2023 09:00
google meet参加者から誰か一人をランダムで選択するスクリプト
// chromeを利用して、ユーザ一覧を表示しつつconsoleで↓を実行すると、現在の参加者からランダムで一人表示することができます
const names_array = document.querySelector("[aria-label='参加者']").innerText.split("\n").filter((word)=> !word.match(/\(|メイン|ミュート|主催者|あなたの画面共有|その他の操作|keep_off|more_vert|keep_pin|keep_pin_outline|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)]
@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)
@willnet
willnet / gist:4128828
Created November 22, 2012 01:05
attributes custom matcher for minitest
# -*- coding: utf-8 -*-
class EqualAttributesMatcher
def initialize(attrs)
@attrs = attrs
end
def matches?(model)
@model = model
@attrs.all? { |k,v| @model.send(k) == v }
end
@willnet
willnet / be_a_rails_contributer.md
Last active August 21, 2023 05:44
Railsコントリビュータへの道

これはなに

  • Railsにプルリクストを送るときに知っておくと便利なお作法集
  • Railsにプルリクエストを送りたいけど何から始めたらいいのかわからない人向けの指針

お作法についてはRuby on Rails に貢献する方法 | Rails ガイドを参考にしています。

前提知識

Railsのコードを読むには、最低限次の二つの知識があったほうがよいです

@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
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": {