This file contains 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
- (void)deviceCheck{ | |
NSString* devicemodel = [[UIDevice currentDevice].model lowercaseString]; | |
NSLog(@"device model = %@", devicemodel); | |
// @"ipod touch", @"iphone", @"iphone simulator" | |
} | |
This file contains 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
// 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; |
This file contains 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
# -*- coding: utf-8 -*- | |
# 0-9a-zの7文字の文字列取得 | |
# ただし乱数度合いは厳密ではない | |
c = "0123456789abcdefghijklmnopqrstuvwxyz" | |
str = "" | |
7.times{ str += c[rand(c.size)] } | |
p str |
This file contains 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
# 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 |
This file contains 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
x = 0.0 | |
10.times do | |
x += 0.1 | |
end | |
p x | |
if x == 1.0 | |
puts 'true' | |
else | |
puts 'false' | |
end |
This file contains 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
# -*- 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) |
This file contains 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
total_amount.toString().replace( /([0-9]+?)(?=(?:[0-9]{3})+$)/g , '$1,' ); |
This file contains 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
# -*- coding: utf-8 -*- | |
# $ rails runner self.rb | |
class C | |
def foo | |
'FOO' | |
end | |
end | |
class C | |
# 既存メソッドfooと一緒に呼ぶ新しいメソッド foo_with_XXXを定義 |
This file contains 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
require 'rinda/tuplespace' | |
$ts = Rinda::TupleSpace.new | |
DRb.start_service('druby://:12345', $ts) | |
puts DRb.uri | |
DRb.thread.join |
This file contains 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
#=> 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!"] |