This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Person | |
include ActiveModel::Validations | |
attr_accessor :age,:name | |
validates_presence_of :name | |
def initialize(attr = {}) | |
attr.each { |n, v| send("#{n}=", v)} | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#content | |
%strong Person | |
%p | |
= flash[:notice] | |
- form_for(:person, :url => acms_path) do |f| | |
%p | |
name: | |
= f.text_field :name | |
%p | |
age: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
production: | |
adapter: jdbc | |
driver: com.microsoft.sqlserver.jdbc.SQLServerDriver | |
url: jdbc:sqlserver://localhost;database=database; | |
username: user | |
password: password |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# changedの振る舞い | |
t = Event.new | |
param = {:year=>2000, :month=>'', :day=>nil} | |
t.attributes = param | |
t.changed? #=> true | |
t.year_changed? #=> true | |
t.month_changed? #=> false | |
t.day_changed? #=> false | |
t.changes #=> {"year"=>[nil, 2000]} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@hoges =Kaminari::paginate_array(Hoge.find_by_sql('select * from hoges limit 25'), total_count: 37,).page(1).per(25) | |
paginate @hoges | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ruby -e 'puts `vm_stat`.gsub!(/([0-9]*)\.$/){ "#{($1.to_i * 4096 / 1000000.0).round(2)}M" }' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class WebkitToPng | |
def self.create(urls, options={}) | |
urls.each do |url| | |
puts "convert #{url} to #{options[:dir]}" | |
url.sub!('//', "//#{options[:auth]}@") if options[:auth] | |
op = "-F -D #{options[:dir]} -o #{url.split('/').last}" | |
op += " --user-agent='#{user_agent}'" if options[:mobile] | |
exec(url, op) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Point | |
attr_accessor :point, :color | |
def initialize(point, color) | |
@point = point | |
@color = color | |
end | |
def toggle | |
@color = color == 'R' ? 'W' : 'R' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Tournament | |
def self.start(players) | |
if players.length == 2 | |
game(players, []).first | |
else | |
left_count = players.length / 2 | |
right_count = players.length - left_count | |
right = players.pop(right_count) | |
left = players |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Game { | |
public static Player matchUp(Player player1, Player player2) { | |
String left = player1.getStrategy(player2.getStrategySize()); | |
String right = player2.getStrategy(player1.getStrategySize()); | |
for(int i=0; i < left.length(); i++) { | |
char left_hand = left.charAt(i); | |
char right_hand = right.charAt(i); | |
if( left_hand == 'R' && right_hand =='S') { | |
return player1; |
OlderNewer