Skip to content

Instantly share code, notes, and snippets.

@SyunWatanabe
SyunWatanabe / moneyforward_timesheet_completer.js
Created December 26, 2019 10:35 — forked from akinov/moneyforward_timesheet_completer.js
マネフォクラウドの勤怠一括入力
$('#js-multiple-timesheet-employee-daily-records-table tr').each((i, e)=>{
if (!/平日/.test(e.textContent)) return;
$('.add_fields',e).click();
$('[name*="elapsed_minutes_at_work_in_with_neuminour_string_format"]', e)[0].value = '10:00';
$('[name*="elapsed_minutes_at_work_out_with_neuminour_string_format"]', e)[0].value = '19:00';
})
# RGB変換プログラム
# 3つの10進数を受け取り、それぞれを16進数に変換した文字列を返す
def to_hex(*args)
arry = args.map {|s|s.to_s(16).rjust(2,"0")}
p "##{arry.join}"
end
to_hex(255, 255, 255)
to_hex(4, 60, 120)
# 長さの単位変換プログラム
def convert_length(num, unit, conversion)
hash = {'m' => 1.00, 'ft' => 3.28, 'in' => 39.37}
(num * hash[conversion] / hash[unit]).round(2)
end
puts convert_length(1, 'm', 'in')
puts convert_length(15, 'in', 'm')
puts convert_length(35_000, 'ft', 'm')
# 正規表現変換
old_syntax = <<TEXT
{
:name => 'Alice',
:age=>20,
:gender => :female
}
TEXT
# 改札機プログラム(自力作)
STATION = ['harajyuku', 'omotesando', 'nogizaka']
class Gate
attr_accessor :name
def initialize(name)
@name = name
end
# Moduleを使う DeepFreeze(自作)
module Freeze
def deep_freeze(object)
object.freeze
object.each do |element, value|
element.freeze
value&.freeze
end
end
end
# 例外処理 サンプルそのまま
print "Text?:"
text = gets.chomp
begin
print "Pattern?:"
pattern = gets.chomp
regexp = Regexp.new(pattern)
rescue RegexpError => e
puts "Invalid regexp #{e.message}"
retry
# count 再実装
class Array
def count(*args)
if block_given?
num = 0
each { |i| num += 1 if yield(i) }
num
elsif args.empty?
size
else
# frozen_string_literal: true
# block
# simple
def say_fact
if block_given?
puts 'i got block'
else
puts 'i need block'
# Ruby Document
# https://docs.ruby-lang.org/ja/latest/class/Enumerable.html#I_PARTITION
# github: holiday_japan
# https://github.com/masa16/holiday_japan/blob/master/lib/holiday_japan.rb
require 'holiday_japan'
# Enumerable#partitionを使い2020年の祝日がある月を抽出する