Skip to content

Instantly share code, notes, and snippets.

@ichi
ichi / .gitignore
Last active February 19, 2020 08:13
atnd `ruby main.rb > atnd.json`
atnd.json
@ichi
ichi / Gemfile
Last active February 24, 2017 05:05
refile in rails5
# NOTE: https://github.com/refile/refile/pull/486
# NOTE: https://github.com/refile/refile/issues/447
gem 'refile', github: 'jastkand/refile', branch: 'mime-types-v3', require: 'refile/rails'
gem 'sinatra', '~> 2.0.0.beta2', require: false
# gem 'refile-s3'
@ichi
ichi / notify_slack_on_deploy.sh
Last active August 15, 2017 09:41
circleciのdeploy前後に通知する
#!/bin/sh
set -e
case "$1" in
"start" )
title="Started deploying to $2!"
title_link="${CIRCLE_BUILD_URL}"
text="<$3|$2>へのdeployを開始します..."
fallback="$2へのdeployを開始します"
color="#28d7e5"
@ichi
ichi / application_enum.rb
Created September 21, 2016 05:17
railsのenumにも使えるやーつ
class ApplicationEnum
class << self
attr_writer :attribute_names
def all
@all ||= Set.new
end
def attribute_names
@attribute_names ||= Set.new
@ichi
ichi / hoge.rb
Last active September 11, 2016 16:20
class HogeError < StandardError
attr_reader :messages
def initialize(*messages)
@messages = messages
end
end
begin
raise HogeError.new(%w(err1 err2 err3))
@ichi
ichi / factory_girl.rb
Last active August 23, 2016 11:51
associationのidもattributesにほしいときに
# spec/support/factory_girl.rb
module FactoryGirl
module Strategy
class AttributesWithForeignKey
def association(runner)
runner.run
end
def result(evaluation)
instance = evaluation.object
@ichi
ichi / devise.rb
Last active August 8, 2018 08:47
spec/support/devise.rb; devise (4.2.0); rspec (3.5.0); rails (5.0.0.1);
module Devise
SCOPES = [:user]
module ResourceHelper
def create_resource(name)
send("current_#{name}")
rescue NameError
create(name)
end
end
@ichi
ichi / faker.rb
Created March 8, 2016 08:55
Fakerのlocale設定無視
# config/initializers/faker.rb
if defined?(Faker)
module Faker
class Internet < Base
class << self
def user_name_with_ignoring_locale(specifier = nil, separators = %w(. _))
ignore_locale do
user_name_without_ignoring_locale(specifier, separators)
traceroute google.com | head -1 | cut -f4 -d" "
@ichi
ichi / postgres.rake
Created January 25, 2016 05:36
postgresのセッションぶっとばすrakeタスク。 test環境にするならRAILS_ENV=testの指定も忘れずにね。
# lib/tasks/postgres.rake
namespace :db do
namespace :pg do
namespace :session do
desc 'reset postgres session/connection'
task :reset do
sql = %{
SELECT pg_terminate_backend(pid)
FROM pg_stat_activity
WHERE datname = '#{ActiveRecord::Base.connection_config[:database]}'