Skip to content

Instantly share code, notes, and snippets.

View digitalm's full-sized avatar

mika mizuno digitalm

View GitHub Profile
@digitalm
digitalm / table_schame_hash.rb
Created June 28, 2022 16:24
ActiveRecord経由でrailsアプリのすべてのテーブル、スキーマのハッシュを取得するスニペット
# { 'Org' => ['id:integer','name:string'],
# 'User' => ['id:integer','email:string'] }
#
# NOTE: If there is no corresponding model in the DB, it will warn.
err = []
ActiveRecord::Base.connection.tables.each_with_object({}) do |table_name, hash|
begin
next if table_name == 'schema_migrations'
next if table_name == 'ar_internal_metadata'
@digitalm
digitalm / gist:ac3268bb119e3bbcb3d238ad3ef8a988
Created May 24, 2022 02:32
way to delete revisions of github wiki
# wiki は repo とは別のリポジトリになっている。
# github uri => https://github.com/[user or org]/[repo].wiki.git
# clone the wiki
git clone https://github.com/[user or org]/[repo].wiki.git
# rm .git folder
rm -rf .git
# 初期化
@digitalm
digitalm / CloudwatchLogsInsightsSample.sh
Created May 13, 2022 10:01
Cloudwatch Logs Insights クエリ構文
# 20s 以上かかった 200 OK のリクエストログ行を出力
fields @timestamp, @message
| filter @message like /Completed 200 OK in /
| parse '*, [* *] * -- : [*] Completed 200 OK in *ms (*)' as key,ts,hash,level,req_hash,ms,detail
| display key,ts,hash,level,req_hash,ms,detail
| filter (ms>20000)
# https://docs.aws.amazon.com/ja_jp/AmazonCloudWatch/latest/logs/CWL_QuerySyntax.html
@digitalm
digitalm / get504.md
Last active April 22, 2022 07:51
development モードで 504 gateway timeout を受け取るためのイージーな方法
@digitalm
digitalm / amazon-linux.sh
Created April 21, 2022 08:39
サーバーメンテ用
# ホストにインストールされているセキュリティー更新の表示
yum updateinfo list sec
# 再起動が必要か, 要 yum-utils パッケージ
needs-restarting -s | sort
@digitalm
digitalm / aws.sh
Created April 21, 2022 01:34
よく使うAWSコマンド
# profile 定義ファイル
`cat ~/.aws/credentials`
# profile 指定
`aws s3 ls --profile PROFILE_NAME`
# リージョン 指定
`AWS_DEFAULT_REGION=ap-northeast-1 aws s3 ls`
# Service 情報表示

共通環境

homebrew / rbenv とかで入れておいてください 🙇

ruby 2.3.7p456
rails 5.2.2     # 5系の最新
      or 5.1.4  # 決済APIのバージョンに合わせる

候補

@digitalm
digitalm / install.sh
Created November 28, 2018 06:35
source-highlight
brew install source-highlight # https://www.gnu.org/software/src-highlite/
export LESSOPEN='| /usr/local/bin/src-hilite-lesspipe.sh %s'
export LESS='-R'
@digitalm
digitalm / btn-toggle.sass
Last active November 28, 2018 05:27
bootstrap button toggle style
// make understanding this https://codepen.io/aanjulena/pen/ZLZjzV
// toggle button ====================================================================
// Toggle Sizes
@toggle-default-size: 1.5rem;
@toggle-default-label-width: 4rem;
@toggle-default-font-size: .75rem;
.btn-toggle {
// top: 50%;
@digitalm
digitalm / sidekiq-killer.sh
Created October 2, 2018 06:51
stopping ステータスになった sidekiq を殺す
#!/bin/sh
# exec by cron
# * * * * * /home/app/cron/sidekiq-killer.sh >> /var/log/cronlog/cron.log 2>&1
# if use pid, get sidekiq-0.pid
# PID=`cat /var/www/app/shared/tmp/pids/sidekiq-0.pid`
count=`ps aux | grep -v grep | grep sidekiq | grep 'busy] stopping' | wc -l`
pid=`ps aux | grep -v grep | grep sidekiq | grep 'busy] stopping' | awk '{print $2}'`