Skip to content

Instantly share code, notes, and snippets.

View mitsuhirookuno's full-sized avatar
🏚️
working in home(Bit Valley)

mitsuhiro okuno mitsuhirookuno

🏚️
working in home(Bit Valley)
View GitHub Profile
'2021-07-08 06:56:00 JST'.to_datetime.utc
'2021-07-07 21:56:00'.to_datetime.in_time_zone('Tokyo')
@mitsuhirookuno
mitsuhirookuno / loyalty_rspec_checker.rb
Last active February 17, 2021 02:24
対応するrspecに漏れがないかチェッカー
def main
@class_files = Dir.glob("app/loyalties/**/*.rb")
@rspec_files = Dir.glob("spec/loyalties/**/*.rb")
@class_files.each do |class_file|
rspec_file = class_file.gsub(/\Aapp/, 'spec').gsub(/loyalty.rb\z/, 'loyalty_spec.rb')
next if @rspec_files.include?(rspec_file)
next if class_file == 'app/loyalties/application_loyalty.rb'
puts "#{class_file} のテストが無いよ #{rspec_file}だよ"
end
end
@mitsuhirookuno
mitsuhirookuno / example.rb
Created January 20, 2021 05:13
Mysql2の例外のみ補足したい
def main(raise_class)
raise raise_class, 'try rescue!'
rescue Mysql2::Error
puts "catch #{$!}"
rescue
puts "Through #{$!}"
end
main(Mysql2::Error)
main(Mysql2::Error::TimeoutError)
@mitsuhirookuno
mitsuhirookuno / example.rb
Created June 11, 2020 03:26
書きぶり検討
# frozen_string_literal: true
@media_website_id = 2_136
def before_labels
registered_labels = []
MediaWebsite.eager_load(media_website_labels: :label)
.where(id: @media_website_id).first
.media_website_labels.each do |media_website_label|
label = media_website_label.label
@mitsuhirookuno
mitsuhirookuno / wip.rb
Created June 1, 2020 01:23
こんな感じかな?と言うイメージ
# frozen_string_literal: true
def build_total(reports)
[reports]
end
def original
campaigns = Campaign.where(id: 1..3)
reports = MediaDailyReport.limit(3).to_a
@mitsuhirookuno
mitsuhirookuno / benchmark_sequel.rb
Created February 6, 2020 03:39
RDBアクセス方法比較
db = Sequel.mysql2(ApplicationRecord.connection_config)
# media_daily_referrer_campaign_report
Benchmark.bm do |x|
# 1. sequel
# 1-1. idのみ
x.report('sequel(id) ') do
db.fetch('select id from media_daily_referrer_campaign_reports limit 50000'){|r| r[:id] }
end
@mitsuhirookuno
mitsuhirookuno / InsertSubmittedDataLocal.sh
Last active December 20, 2019 02:39
InsertSubmittedDataLocal.sh の新しいやつです
#!/bin/sh
private_key_path=$1
insert_file_path=$2
environment_path=$3
if [ ${environment_path} = '/home/ec2-user/circuit-x-batch-dev' ]; then
echo '[[[ 開発環境に向いています ]]]'
batch_server_ip_address=3.112.22.21
else
@mitsuhirookuno
mitsuhirookuno / app/controllers/concerns/slack_helper.rb
Created November 1, 2019 06:18
良い実装か?は置いていて、controllerのconcernsをmodelから利用するやつ
module SlackHelper
extend ActiveSupport::Concern
# メッセージを通知します
def self.send_to_slack(message, channel:, mentions: nil, icon: ':fukurouchan:')
mentions_line = SlackHelper.create_mentions_line(mentions)
SlackHelper.send_core(mentions_line + message, channel, icon_emoji: icon)
end
delegate :send_to_slack, to: SlackHelper
@mitsuhirookuno
mitsuhirookuno / reproduce_request.rb
Last active August 25, 2019 06:09
リクエストの再実行
require 'uri'
require 'pry'
require 'csv'
require 'time'
REPRODUCE_HOST = 'localhost:4567'
PROTOCOL = 'http'
CURL_COMMAND = 'curl'
def main
@mitsuhirookuno
mitsuhirookuno / gist:c2eb29528de15c74638265b614107bfb
Last active March 6, 2019 08:02
フレームワークの無いPHPでのbugsnag利用
php -r "readfile('https://getcomposer.org/installer');" | php
php composer.phar require guzzlehttp/guzzle
php composer.phar require bugsnag/bugsnag
```
require 'vendor/autoload.php';
$bugsnag = Bugsnag\Client::make($_ENV['BUGSNAG_API_KEY']);
$bugsnag->setReleaseStage('development');
$bugsnag->notifyException(new RuntimeException("Test error"));"
```