Skip to content

Instantly share code, notes, and snippets.

View gouf's full-sized avatar
😇
I don't know how my life work with.

Go Furuya gouf

😇
I don't know how my life work with.
View GitHub Profile
@gouf
gouf / data.txt
Last active October 28, 2022 09:27
年月 (from, to) のデータから、のべ年数を計算する
20143 20149
20162 20175
20162 20164
20165 20166
20169 201611
20172 20175
20181 20192
20194 20195
20203 20208
202011 20222
@gouf
gouf / .bashrc
Created June 14, 2016 05:16
Switch git author
function switch_git_config () {
name=$1
email=$2
git config --global user.name $name
git config --global user.email $email
echo "Configuration has changed:"
echo "git config user.name: $(git config user.name)"
echo "git config user.email: $(git config user.email)"
}
interface Number {
isFizzBuzz(): boolean
isFizz(): boolean
isBuzz(): boolean
}
Number.prototype.isFizzBuzz = function(): boolean {
return this.isFizz() && this.isBuzz()
}
@gouf
gouf / common.rb
Last active August 16, 2021 12:45
reCAPTCHA (Ruby 側) の煩雑な処理をモジュール化
# 全体の処理
#
# スコアを得るまでの流れ:
#
# View 側:
# 1. reCAPTCHA を設置する (JS 処理)
# 2. ログインフォームの submit に合わせて g-recaptcha-response にデータを乗せる
#
# Rails 側:
# 1. client を生成
require 'active_support'
require 'active_support/core_ext'
#
# 関数の定義
#
def date_duration(base_date, after_date)
duration_parts =
ActiveSupport::Duration.build(after_date.to_i - base_date.to_i).parts
@gouf
gouf / main.rb
Created November 5, 2019 08:54
Paiza 練習問題 : [翌営業日 - その1](https://paiza.jp/works/mondai/dateset/working_day_1?language_uid=ruby)
require File.join(__dir__, 'lib', 'workdays')
# eg. 10 1 FRI
# => 10月4日
workday = WorkDay.new(*gets.chomp.split)
month, day = workday.next_workday
puts "#{month}月#{day}日"
@gouf
gouf / janken.rb
Last active October 23, 2019 04:08
[Rubyでじゃんけんアプリを作ってみた - Qiita](https://qiita.com/hiro-gen/items/85639c0a8f925e31fbbe) を見たので書いてみた
# frozen_string_literal: true
# じゃんけんゲームで出せる手の種類
module Hands
HANDS = %i[rock scissors paper].freeze
HANDS_LABEL = %w[グー チョキ パー].freeze
private_constant :HANDS, :HANDS_LABEL
end
@gouf
gouf / day_in_month.rb
Created August 16, 2019 15:39
Paiza レベルアップ問題集: 「月の日数 Ruby編」 - https://paiza.jp/works/mondai/dateset/ruby/days_in_a_month
require 'date'
def count_day_in_month(date, month:, count: 0)
return count unless month.eql?(date.month)
count_day_in_month(date.succ, month: month, count: count + 1)
end
year, month, day = [*gets.chomp.split, 1].map(&:to_i)
@gouf
gouf / date_format.rb
Created August 16, 2019 01:12
Paiza レベルアップ問題集: 「日付のフォーマット Ruby編」 - https://paiza.jp/works/mondai/dateset/ruby/date_format
class DateFormat
DATE_ORDER = %r{[0-9]{4}/[0-9]{2}/[0-9]{2}}.freeze
MONTH = [*(1..12).map { |n| n.to_s.rjust(2, '0') }].freeze
DAY = [*(1..31).map { |n| n.to_s.rjust(2, '0') }].freeze
class << self
def validate(date_string)
return 'No' unless date_string.match?(DATE_ORDER)
_year, month, day = date_string.split('/')
@gouf
gouf / guru_navi_api.rb
Created August 5, 2019 07:13
[Ruby - RailsアプリをHerokuへデプロイ後、ぐるなびAPIが検索結果を返さない|teratail](https://teratail.com/questions/203712)
# frozen_string_literal: true
require 'net/http'
require 'uri'
require 'json'
require 'logger'
require 'kaminari'
class GuruNaviApi
API_KEY = ENV['GNAVI_API_KEY']