This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// useReducer | |
// https://ja.reactjs.org/docs/hooks-reference.html#usereducer | |
// basic | |
// const [state, dispatch] = useReducer(reducer, initialArg, init); | |
// reducer type | |
// (state, action) => newState; | |
// when it use?? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name show meta | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description show meta what we want | |
// @author me | |
// @match *://*/* | |
// @grant none | |
// ==/UserScript== |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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年の祝日がある月を抽出する |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
# block | |
# simple | |
def say_fact | |
if block_given? | |
puts 'i got block' | |
else | |
puts 'i need block' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# count 再実装 | |
class Array | |
def count(*args) | |
if block_given? | |
num = 0 | |
each { |i| num += 1 if yield(i) } | |
num | |
elsif args.empty? | |
size | |
else |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 例外処理 サンプルそのまま | |
print "Text?:" | |
text = gets.chomp | |
begin | |
print "Pattern?:" | |
pattern = gets.chomp | |
regexp = Regexp.new(pattern) | |
rescue RegexpError => e | |
puts "Invalid regexp #{e.message}" | |
retry |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Moduleを使う DeepFreeze(自作) | |
module Freeze | |
def deep_freeze(object) | |
object.freeze | |
object.each do |element, value| | |
element.freeze | |
value&.freeze | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 改札機プログラム(自力作) | |
STATION = ['harajyuku', 'omotesando', 'nogizaka'] | |
class Gate | |
attr_accessor :name | |
def initialize(name) | |
@name = name | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 正規表現変換 | |
old_syntax = <<TEXT | |
{ | |
:name => 'Alice', | |
:age=>20, | |
:gender => :female | |
} | |
TEXT |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 長さの単位変換プログラム | |
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') |
NewerOlder