Skip to content

Instantly share code, notes, and snippets.

View nashirox's full-sized avatar
🏠
Working from home

Daisuke Nashiro nashirox

🏠
Working from home
View GitHub Profile
@nashirox
nashirox / conditional_hash.rb
Last active December 3, 2021 06:18
Samples to building an hash key\value pairs in a conditional way.
# case1
Hash.new.tap do |hash|
hash[:key1] = value1 if condition_1
hash[:key2] = value2 if condition_2
end
# case2
hash = {}
hash[:key1] = value1
hash[:key2] = value2 if condition_2
@nashirox
nashirox / decimal_point.rb
Last active November 19, 2021 01:05
小数点以下の桁数を取得
def digits_after_decimal_point(val)
return unless val.is_a?(Numeric)
digits = 0
while(val != val.to_i)
digits += 1
val *= 10
end
digits
end
@nashirox
nashirox / circle_ci_config.yml
Last active May 18, 2023 00:09
CircleCI config for Rails 6 + Ruby 2.6 + Postgres + Redis
version: 2
jobs:
build:
working_directory: ~/my-app
docker:
- image: circleci/ruby:2.6.3-node-browsers
environment:
BUNDLE_RETRY: 3
BUNDLE_PATH: vendor/bundle
DATABASE_URL: postgres://postgres:password@localhost:5432/tech_cast_test
class DropUsers < ActiveRecord::Migration
def change
drop_table :users do |t|
t.string :name, null: false
t.string :email, null: false, unique: true
t.timestamps null: false
end
end
end
%body
- flash.each do |key, value|
- key = "info" if key == "notice"
- key = "danger" if key == "alert"
= content_tag :div, value, class: "alert alert-#{key}"
@nashirox
nashirox / _form.html.erb
Last active February 8, 2018 12:30
link_toヘルパーにアイコンを埋め込む
<% link_to root_path do %>
<i class="icon-home"></i> ホーム
<% end %>
@nashirox
nashirox / hoge.txt
Last active February 8, 2018 13:44
# ローカルのmasterブランチ以外削除
$ git branch | grep -v 'master' | grep -v '*' | xargs git branch -D
# リモートのmasterブランチ以外全削除
$ git branch -r | grep origin | grep -v master | sed -e s/^.*origin\\///g | xargs git push -d origin
prefectures = %w(北海道 青森県 岩手県 宮城県 秋田県 山形県 福島県 茨城県 栃木県 群馬県 埼玉県 千葉県 東京都 神奈川県 新潟県 富山県 石川県 福井県 山梨県 長野県 岐阜県 静岡県 愛知県 三重県 滋賀県 京都府 大阪府 兵庫県 奈良県 和歌山県 鳥取県 島根県 岡山県 広島県 山口県 徳島県 香川県 愛媛県 高知県 福岡県 佐賀県 長崎県 熊本県 大分県 宮崎県 鹿児島県 沖縄県)
@nashirox
nashirox / rails-validates.rb
Last active April 7, 2024 08:07
Rubyのバリデーション用正規表現集
#
# 数字
#
# 全て数値(全角)
/\A[0-9]+\z/
# 全て数値(半角)
/\A[0-9]+\z/
@nashirox
nashirox / _form.html.erb
Last active February 8, 2018 12:27
f.submitタグにアイコンを埋め込む
<%= button_tag, class: "btn btn-default btn-sm" do %>
<%= content_tag :span, "送信", class: "glyphicon glyphicon-star" %>
<% end %>