Skip to content

Instantly share code, notes, and snippets.

View rummelonp's full-sized avatar
🐈‍⬛
ニャーン

Kazuya Takeshima rummelonp

🐈‍⬛
ニャーン
View GitHub Profile
@rummelonp
rummelonp / spec_helper.rb
Created September 18, 2014 08:36
RSpec 3.1 用の spec_helper.rb の雛形的な
RSpec.configure do |config|
config.expect_with :rspec do |expectations|
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
end
config.mock_with :rspec do |mocks|
mocks.verify_partial_doubles = true
end
config.filter_run :focus
class ApplicationController
before_action :set_locale
private
def set_locale
if authenticated?
I18n.locale = current_user.locale
else
langs = (request.headers['HTTP_ACCEPT_LANGUAGE'] || '').split(',').map { |l| l.split(';').first }
.Trash
.cabal
.cpanm
.dropbox
.emacs.d
.gem
.gemrc
.ghc
.gitconfig
.gitignore
(require 'vc-git)
(require 'anything-config)
(defgroup anything-rails nil
"anything for rails"
:prefix "anything-rails:"
:group 'anything)
(defun anything-rails:root ()
(vc-git-root default-directory))
@rummelonp
rummelonp / ruby-conf.el
Created September 8, 2014 08:55
rinari.el で before_action とかをハイライトするやつ
;; これを (require 'rinari) の下あたりにコペピ
(setq rinari-controller-keywords
(append rinari-controller-keywords
'("before_action" "append_before_action" "prepend_before_action"
"after_action" "append_after_action" "prepend_after_action"
"around_action" "append_around_action" "prepend_around_action"
"skip_before_action" "skip_after_action" "skip_around_action")))
@rummelonp
rummelonp / application.rb
Last active August 29, 2015 14:06
Rails のジェネレータで使わない奴生成しないようにするやつ
# これを config/application.rb 内にコペピする
# 参考: http://guides.rubyonrails.org/generators.html#customizing-your-workflow-by-changing-generators-templates
config.generators do |g|
g.controller helper: false, assets: false
g.rspec view_specs: false, helper_specs: false
end
@rummelonp
rummelonp / id_no_tuyosa.rb
Created September 5, 2014 08:54
ID の強さ
def tuyosa(id)
score = 50
score -= (id.size - 1)
id.chars.each do |char|
score -= 1 if char =~ /_/
score -= 1 if char =~ /[A-Z]/
score -= 2 if char =~ /[0-9]/
end
score * 2
end
@rummelonp
rummelonp / application_form.rb
Last active August 29, 2015 14:06
Rails で Form クラス的なやつ
class ApplicationForm
include ActiveModel::Model
def submit(params = {})
params.each do |key, value|
self.public_send("#{key}=", value)
end
self
end
@rummelonp
rummelonp / .gitignore
Last active August 29, 2015 14:05
Chinese numeral parser
/.bundle/
/.yardoc
/Gemfile.lock
/_yardoc/
/coverage/
/doc/
/pkg/
/spec/reports/
/tmp/
*.bundle
@rummelonp
rummelonp / kansuji.rb
Last active August 29, 2015 14:05
Parslet で漢数字を Int にするやつ
require 'parslet'
module Kansuji
NUMBERS = %w{一 二 三 四 五 六 七 八 九}
DIGITS = %w{十 百 千}
UNITS = %w{万 億 兆 京 垓 𥝱 穣 溝 澗 正 載 極 恒河沙 阿僧祇 那由他 不可思議 無量大数}
def self.parser
@parser ||= Parser.new
end