Skip to content

Instantly share code, notes, and snippets.

View hidenba's full-sized avatar
🏠
Working from home

hidekuni KAJITA hidenba

🏠
Working from home
View GitHub Profile
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
#content
%strong Person
%p
= flash[:notice]
- form_for(:person, :url => acms_path) do |f|
%p
name:
= f.text_field :name
%p
age:
production:
adapter: jdbc
driver: com.microsoft.sqlserver.jdbc.SQLServerDriver
url: jdbc:sqlserver://localhost;database=database;
username: user
password: password
# 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]}
@hoges =Kaminari::paginate_array(Hoge.find_by_sql('select * from hoges limit 25'), total_count: 37,).page(1).per(25)
paginate @hoges
@hidenba
hidenba / gist:4576468
Created January 20, 2013 03:15
OSXでのメモリステータス
ruby -e 'puts `vm_stat`.gsub!(/([0-9]*)\.$/){ "#{($1.to_i * 4096 / 1000000.0).round(2)}M" }'
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
class Point
attr_accessor :point, :color
def initialize(point, color)
@point = point
@color = color
end
def toggle
@color = color == 'R' ? 'W' : 'R'
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
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;