Skip to content

Instantly share code, notes, and snippets.

- (void)deviceCheck{
NSString* devicemodel = [[UIDevice currentDevice].model lowercaseString];
NSLog(@"device model = %@", devicemodel);
// @"ipod touch", @"iphone", @"iphone simulator"
}
@igaiga
igaiga / waitXsec.m
Created June 21, 2010 05:58
Wait X sec on cocoa
// X sec 待つ
[NSThread sleepUntilDate:[NSDate dateWithTimeIntervalSinceNow:2]];
// アニメーション開始時刻を遅らせる場合
view.alpha = 1.0f;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelay:3]; // 3sec
[UIView setAnimationDuration:2.0];
view.alpha = 0.0f;
# -*- coding: utf-8 -*-
# 0-9a-zの7文字の文字列取得
# ただし乱数度合いは厳密ではない
c = "0123456789abcdefghijklmnopqrstuvwxyz"
str = ""
7.times{ str += c[rand(c.size)] }
p str
@igaiga
igaiga / spec_plugins.rake
Created October 8, 2010 06:28
rake spec:plugins
# Rails3 で vendor/plugins/ 以下のspecファイルを実行するrake task.
# lib/tasks/ 以下にこのファイルを置けば rake -T に追加される。
namespace :spec do
desc 'Run the code examples in plugins'
task :plugins do
system 'bundle exec rspec vendor/plugins/'
end
end
@igaiga
igaiga / float.rb
Created October 29, 2010 01:51
float.rb
x = 0.0
10.times do
x += 0.1
end
p x
if x == 1.0
puts 'true'
else
puts 'false'
end
# -*- coding: utf-8 -*-
class C
X = 12
def set_x(arg)
X = arg #←ここでエラー "5: dynamic constant assignment"
end
end
c = C.new
c.set_x(34)
@igaiga
igaiga / gist:744549
Created December 17, 2010 06:03
3桁ごとにカンマ区切り
total_amount.toString().replace( /([0-9]+?)(?=(?:[0-9]{3})+$)/g , '$1,' );
@igaiga
igaiga / alias_method_chain_test.rb
Created December 23, 2010 08:00
alias_method_chain_test
# -*- coding: utf-8 -*-
# $ rails runner self.rb
class C
def foo
'FOO'
end
end
class C
# 既存メソッドfooと一緒に呼ぶ新しいメソッド foo_with_XXXを定義
require 'rinda/tuplespace'
$ts = Rinda::TupleSpace.new
DRb.start_service('druby://:12345', $ts)
puts DRb.uri
DRb.thread.join
#=> irb
require 'drb'
#=> true
$ts = DRbObject.new_with_uri('druby://localhost:12345')
#=> #<DRb::DRbObject:0x10136d740 @uri="druby://localhost:12345", @ref=nil>
$ts.write(["message", "Hello, world!"])
#=> #<DRb::DRbObject:0x10135e060 @uri="druby://127.0.0.1:12345", @ref=2152218120>
$ts.take(["message",nil])
#=> ["message", "Hello, world!"]