Skip to content

Instantly share code, notes, and snippets.

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

Kazuya Takeshima rummelonp

🐈‍⬛
ニャーン
View GitHub Profile
@rummelonp
rummelonp / freeze_validator.rb
Created October 2, 2013 10:15
特定の条件の時に変更不可能なフィールドのためのバリデーション
# -*- coding: utf-8 -*-
class FreezeValidator < ActiveModel::EachValidator
def initialize(options)
options[:unless] = Array.wrap(options[:unless])
options[:unless] << :new_record?
super
end
def validate_each(record, attribute, value)

ChangeLog を支える英語

ChangeLog を書く際によく使われる英語をまとめました。

ほとんど引用です。

基本形

source 'https://rubygems.org'
gem 'sinatra'
gem 'puma'
gem 'thin'
@rummelonp
rummelonp / hash_camelize_keys.rb
Last active December 23, 2015 22:19
Hash の key を camelize するやつ
# -*- coding: utf-8 -*-
require 'active_support/core_ext'
class Hash
def camelize_keys(first_letter = :upper)
dup.camelize_keys!(first_letter)
end
def camelize_keys!(first_letter = :upper)
@rummelonp
rummelonp / blink.css
Last active December 23, 2015 21:29
blink するやつ
@rummelonp
rummelonp / colorful_cookie.js
Created September 16, 2013 05:34
クッキー焼くやつ
@rummelonp
rummelonp / table_fucking.rb
Last active December 23, 2015 01:19
プレフィクスのついたテーブル名/カラム名とかその他良い感じにするやつ
module TableFucking
extend ActiveSupport::Concern
included do
self.table_name = 'prefix_' + name.match(/\APrefix(.+)\Z/)[1].underscore
columns = connection.columns(table_name)
reserved_words = ActiveRecord::Base.instance_methods
columns.each do |column|
@rummelonp
rummelonp / post_controller.rb
Last active January 20, 2016 06:35
標準的な Rails のアレ
# -*- coding: utf-8 -*-
class PostController < ApplicationController
before_filter :require_post, only: [:show, :edit, :update, :destroy]
def index
@posts = posts
end
def new
# -*- coding: utf-8 -*-
module ValidationContext
extend ActiveSupport::Concern
included do
before_validation :reflect_context_to_associations
end
# @return [Symbol]
@rummelonp
rummelonp / after.erb
Last active December 22, 2015 17:49
float でタイル上に並べてるやつを強制的に横に並べて横スクロールにしたい
<div class="container clearfix" style="overflow-x: auto; width: 900px;">
<div class="sub-container" style="width: <%= @parts.size * 300 %>px;">
<% @parts.each do |part| %>
<div class="parts pull-left" style="width: 300px;">...</div>
<% end %>
</div>
</div>