Skip to content

Instantly share code, notes, and snippets.

View kazuhisa's full-sized avatar

Yamamoto Kazuhisa kazuhisa

View GitHub Profile
def word_capitalize(str)
str.gsub(/(\w+)/){ |v| v.capitalize }
end
p word_capitalize('in-reply-to')
p word_capitalize('X-MAILER')
class SongTagValidator < ActiveModel::Validator
def validate(record)
if record.tags.size > 10
record.errors[:base] << 'タグは10こまでです'
end
end
end
@kazuhisa
kazuhisa / UFO
Created February 15, 2014 08:11
class Hoge
include Comparable
attr_accessor :age
def initialize(age)
@age = age
end
def <=>(other)
self.age <=> other.age
#!/bin/sh
cd /Users/kazuhisa/taisou
if [ "$((RANDOM % 20))" -eq 0 ]; then
afplay moe_taisou.mp3
else
afplay radio_taisou.mp3
fi
[kazuhisa: ~/tmp]$ rails new hogera -m http://railswizard.org/e46ea1216311c64543f4.rb
create
create README.rdoc
create Rakefile
create config.ru
create .gitignore
create Gemfile
create app
create app/assets/javascripts/application.js
create app/assets/stylesheets/application.css
@kazuhisa
kazuhisa / relation_patch.rb
Created September 11, 2013 14:57
Rails4.0.0でJoinしたテーブルに対してreadonly(false)が効かないのはバグです。4.1系で解消されるはずなので、次のパッチをconfig/initializersにでも入れておくといいよ。
# -*- coding: utf-8 -*-
module ActiveRecord
class Relation
def initialize(klass, table, values = {})
@klass = klass
@table = table
@values = values
@loaded = false
end
class Rental
attr_reader :movie, :days_rented
def initialize(movie, days_rented)
@movie, @days_rented = movie, days_rented
end
def charge
result = 0
case movie.price_code
・好きな言語は?
・好きなメソッドは?
・好きなアニメは?
・好きなガンダムシリーズは?
・githubアカウントは?
・英語しゃべれる?
・最近気になるテクノロジーは?
・最近行った勉強会は?
・最近登壇した勉強会は?
・iPhone落とした事ある?