勉強しようと思っていたけど何故がブログいじりをしてしまった…。
テーマ変更
以前は、猫のテーマにしていた。
でも、WordPressの新しい機能との相性が悪かったので辞めた。
当初、iBlogのテーマだとシンタックスハイライトがGoogle Chromeで動かなかったんだよね。
まぁ、なんとか解決した。
内容見直し
ちゃんと考えて書かないとダメだね(笑)
Twitter連動
Facebook連動は検討中。
もう一個立ち上げた
正直、どう住み分けるか?を考えていない。
ただの勢いだけ…。
退職
最終出社日は6月10日(金)です。
残された工数は10人日!
どこまでできるか。
約2年間の最後の仕事!
この2年間
振り返ってみる。
月間十数億PVのサービスの開発・運用
今まで、ここまで大きなサービスに関わった事がなかったから。
色々、セオリーから外れたバットノウハウの塊みたいなシステムだったけどね(笑)
オブジェクト指向・設計
その時の上司はとても熱心にレビューしてくれたし、設計の相談にも乗ってくれた。
心の中で勝手に師匠と思ってるくらい素晴らしい人だった。
この人の退職していなかったらもう少し今の会社に居たかも?
それくらいにとても尊敬できる人に出会えた。
運営
工数の問題やシステムの問題で実現できない事も多々あったけどとても新鮮だった。
決して使いやすいとは言えないシステムだった。
でも、運営の人達の頑張りでここまで大きなサービスになったんだと思う。
ユーザさんの立場に立つという事をしっかり考えさせてくれました!
営業・管理
アイディアがいっぱい持ってて熱い人達が多かったなぁ。
プライベートでいいから、ちゃんと形にして世に出したいね。
嫌だった所
役職的に部下という立場の方が居たのですが、色々大変だった…。
そこはもう振り返らない!
あとは、壁を感じた。
50人くらいの会社でこんな厚い壁はデメリットだと思う。
勢いで作ってしまえば早くやれるのに!
って結構苛立つ事もあったなぁ。
まとめ
最終日に話さないといけないからです(笑)
ここら辺の内容からそれっぽく挨拶を考えます。
楽しい事の方が多かったとは思うのでネガティブではないです!
ありがとうごさいました!
同じ現象に遭遇している人も発見…。
原因は…
それは、ウィジェットに設置していたAmazonのアフィリエイトだった…。
iframeとの相性が悪いのかな??
iframeでない物に差し替えたらシンタックス復活!!
目次
まだ、dotcloudのアカウントを持っていない人は、
から。
ちょっと待っててな!的なメールがすぐに来て、2日もすればアカウント作れるよ!的なメールが届く。
さてさて、環境構築の流れは以下の通り。
- python 2.6.6のインストール
- easy_installのインストール
- dotcloudコマンドのインストール
- 開発用ユーザでいじってみる
ハマった点は
CentOS 5.5デフォルトのpythonのバージョンが低くてeasy_installでdotcloudが入らない
という点。
さくらのVPSで作業した。(sudo面倒だからrootで…)
python 2.6.6のインストール
# mkdir /usr/local/python266 # ln -fns /usr/local/python266 /usr/local/python
# cd /usr/local/src # wget http://www.python.org/ftp/python/2.6.6/Python-2.6.6.tgz # tar -zxvf Python-2.6.6.tgz # cd Python-2.6.6 # ./configure --with-threads --enable-shared --prefix=/usr/local/python # vim Modules/Setup zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib -lz # make # make install
# vim /etc/ld.so.conf.d/python2.6.6.conf /usr/local/python266/lib # ldconfig
# /usr/local/python/bin/python Python 2.6.6 (r266:84292, May 13 2011, 10:45:20) [GCC 4.1.2 20080704 (Red Hat 4.1.2-48)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> quit()
すでに入っているpythonとの共存の為にaliasにしておく
# vim ~/.bashrc PATH=$PATH:/usr/local/python/bin alias python='python2.6'
# . ~/.bashrc # python Python 2.6.6 (r266:84292, May 13 2011, 10:45:20) [GCC 4.1.2 20080704 (Red Hat 4.1.2-48)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> quit()
easy_installのインストール
# cd /usr/local/src # wget http://peak.telecommunity.com/dist/ez_setup.py # python ez_setup.py # easy_install-2.6
dotcloudコマンドのインストール
# easy_install-2.6 dotcloud
開発用ユーザでいじってみる
$ vim ~/.bashrc PATH=$PATH:/usr/local/python/bin alias python='python2.6'
$ . ~/.bashrc $ python Python 2.6.6 (r266:84292, May 13 2011, 10:45:20) [GCC 4.1.2 20080704 (Red Hat 4.1.2-48)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> quit()
$ mkdir -p ~/work/dotcloud/
※testの部分には自分の好きな名前を入れる。すでに使われているとエラーになる。
$ dotcloud create test
※初回はAPIキーを聞かれる。これは、dotcloudのWebにログインして、Settingsページを見ると書いてある。
$ dotcloud deploy --type php test.php
$ mkdir -p ~/work/dotcloud/test/php $ cd ~/work/dotcloud/test/php $ vim index.php <?php phpinfo();
$ dotcloud push test.php ~/work/dotcloud/test/php
デプロイは、
~/work/dotcloud/test/php
のディレクトリをrsyncしてるみたい。
http://php.test.dotcloud.com/
にアクセス。
独自ドメインの割り当て
dotcloud alias add test.php ドメイン
で割り振れるらしい。
CNAMEはgateway.dotcloud.com。
まとめ
何よりも、PHPだけじゃなくてRubyやPythonの環境もデプロイできるのは凄い!
次はSinatraでもデプロイしてみようかなぁ。
Shindig 2 (PHP) + Partuza(Revision 271) + PHP5
試したアプリは
http://www.labpixies.com/campaigns/todo/todo.xml
OpenPNE3にしても出たのでShindig 2のバグかな…。
結構放置されているみたい。
php/src/common/sample/BasicSecurityTokenDecoder.php
の2つ目のINVALID_GADGET_TOKENが出ている
throw $e;
// throw new GadgetException('INVALID_GADGET_TOKEN');
としてみると「HMAC verification failure」と出ている。
うーん…。
【追記】
Partuzaをtrunkから落として、以下のように書き換えると認証が通る。
(サンプルのtodoは動かないんだけど、動くアプリも結構ある)
$bin = base64_decode($in);
から
$bin = base64_decode(urldecode(base64_decode($in)));
todoが動かない理由はまだわからない…。
- vimが固まる
- lsが固まる
- rmが固まる
などなど。
ログインして作業する事が苦痛になってきた…。
というわけで、さくらのVPSに移行する事にしました。
その際に、PHP 5.3、MySQL 5.5にしちゃおうと思います。
うまくいくかなぁ。
NSString+Escape.h
#import <Foundation/Foundation.h> @interface NSString (Escape) - (NSString *)urlEncode; - (NSString *)urlDecode; - (NSString *)escapeHtml; - (NSString *)unescapeHtml; @end
NSString+Escape.m
#import "NSString+Escape.h"
@implementation NSString (Escape)
- (NSString *)escapeHtml
{
NSMutableString *string = [[self mutableCopy] autorelease];
[string replaceOccurrencesOfString:@"&" withString:@"&" options:NSLiteralSearch range:NSMakeRange(0, [string length])];
[string replaceOccurrencesOfString:@"<" withString:@"<" options:NSLiteralSearch range:NSMakeRange(0, [string length])];
[string replaceOccurrencesOfString:@">" withString:@">" options:NSLiteralSearch range:NSMakeRange(0, [string length])];
[string replaceOccurrencesOfString:@"\"" withString:@""" options:NSLiteralSearch range:NSMakeRange(0, [string length])];
return [NSString stringWithString: string];
}
- (NSString *)unescapeHtml
{
NSMutableString *string = [[self mutableCopy] autorelease];
[string replaceOccurrencesOfString:@""" withString:@"\"" options:NSLiteralSearch range:NSMakeRange(0, [string length])];
[string replaceOccurrencesOfString:@">" withString:@">" options:NSLiteralSearch range:NSMakeRange(0, [string length])];
[string replaceOccurrencesOfString:@"<" withString:@"<" options:NSLiteralSearch range:NSMakeRange(0, [string length])];
[string replaceOccurrencesOfString:@"&" withString:@"&" options:NSLiteralSearch range:NSMakeRange(0, [string length])];
return [NSString stringWithString: string];
}
- (NSString *)urlEncode
{
NSMutableString *string = [[self mutableCopy] autorelease];
[string replaceOccurrencesOfString:@"%" withString:@"%25" options:NSLiteralSearch range:NSMakeRange(0, [string length])];
[string replaceOccurrencesOfString:@";" withString:@"%3B" options:NSLiteralSearch range:NSMakeRange(0, [string length])];
[string replaceOccurrencesOfString:@"/" withString:@"%2F" options:NSLiteralSearch range:NSMakeRange(0, [string length])];
[string replaceOccurrencesOfString:@"?" withString:@"%3F" options:NSLiteralSearch range:NSMakeRange(0, [string length])];
[string replaceOccurrencesOfString:@":" withString:@"%3A" options:NSLiteralSearch range:NSMakeRange(0, [string length])];
[string replaceOccurrencesOfString:@"@" withString:@"%40" options:NSLiteralSearch range:NSMakeRange(0, [string length])];
[string replaceOccurrencesOfString:@"&" withString:@"%26" options:NSLiteralSearch range:NSMakeRange(0, [string length])];
[string replaceOccurrencesOfString:@"=" withString:@"%3D" options:NSLiteralSearch range:NSMakeRange(0, [string length])];
[string replaceOccurrencesOfString:@"+" withString:@"%2B" options:NSLiteralSearch range:NSMakeRange(0, [string length])];
[string replaceOccurrencesOfString:@"$" withString:@"%24" options:NSLiteralSearch range:NSMakeRange(0, [string length])];
[string replaceOccurrencesOfString:@"," withString:@"%2C" options:NSLiteralSearch range:NSMakeRange(0, [string length])];
[string replaceOccurrencesOfString:@"[" withString:@"%5B" options:NSLiteralSearch range:NSMakeRange(0, [string length])];
[string replaceOccurrencesOfString:@"]" withString:@"%5D" options:NSLiteralSearch range:NSMakeRange(0, [string length])];
[string replaceOccurrencesOfString:@"#" withString:@"%23" options:NSLiteralSearch range:NSMakeRange(0, [string length])];
[string replaceOccurrencesOfString:@"!" withString:@"%21" options:NSLiteralSearch range:NSMakeRange(0, [string length])];
[string replaceOccurrencesOfString:@"'" withString:@"%27" options:NSLiteralSearch range:NSMakeRange(0, [string length])];
[string replaceOccurrencesOfString:@"(" withString:@"%28" options:NSLiteralSearch range:NSMakeRange(0, [string length])];
[string replaceOccurrencesOfString:@")" withString:@"%29" options:NSLiteralSearch range:NSMakeRange(0, [string length])];
[string replaceOccurrencesOfString:@"*" withString:@"%2A" options:NSLiteralSearch range:NSMakeRange(0, [string length])];
return [NSString stringWithString: string];
}
- (NSString *)urlDecode
{
NSMutableString *string = [[self mutableCopy] autorelease];
[string replaceOccurrencesOfString:@"%2A" withString:@"*" options:NSLiteralSearch range:NSMakeRange(0, [string length])];
[string replaceOccurrencesOfString:@"%29" withString:@")" options:NSLiteralSearch range:NSMakeRange(0, [string length])];
[string replaceOccurrencesOfString:@"%28" withString:@"(" options:NSLiteralSearch range:NSMakeRange(0, [string length])];
[string replaceOccurrencesOfString:@"%27" withString:@"'" options:NSLiteralSearch range:NSMakeRange(0, [string length])];
[string replaceOccurrencesOfString:@"%21" withString:@"!" options:NSLiteralSearch range:NSMakeRange(0, [string length])];
[string replaceOccurrencesOfString:@"%23" withString:@"#" options:NSLiteralSearch range:NSMakeRange(0, [string length])];
[string replaceOccurrencesOfString:@"%5D" withString:@"]" options:NSLiteralSearch range:NSMakeRange(0, [string length])];
[string replaceOccurrencesOfString:@"%5B" withString:@"[" options:NSLiteralSearch range:NSMakeRange(0, [string length])];
[string replaceOccurrencesOfString:@"%2C" withString:@"," options:NSLiteralSearch range:NSMakeRange(0, [string length])];
[string replaceOccurrencesOfString:@"%24" withString:@"$" options:NSLiteralSearch range:NSMakeRange(0, [string length])];
[string replaceOccurrencesOfString:@"%2B" withString:@"+" options:NSLiteralSearch range:NSMakeRange(0, [string length])];
[string replaceOccurrencesOfString:@"%3D" withString:@"=" options:NSLiteralSearch range:NSMakeRange(0, [string length])];
[string replaceOccurrencesOfString:@"%26" withString:@"&" options:NSLiteralSearch range:NSMakeRange(0, [string length])];
[string replaceOccurrencesOfString:@"%40" withString:@"@" options:NSLiteralSearch range:NSMakeRange(0, [string length])];
[string replaceOccurrencesOfString:@"%3A" withString:@":" options:NSLiteralSearch range:NSMakeRange(0, [string length])];
[string replaceOccurrencesOfString:@"%3F" withString:@"?" options:NSLiteralSearch range:NSMakeRange(0, [string length])];
[string replaceOccurrencesOfString:@"%2F" withString:@"/" options:NSLiteralSearch range:NSMakeRange(0, [string length])];
[string replaceOccurrencesOfString:@"%3B" withString:@";" options:NSLiteralSearch range:NSMakeRange(0, [string length])];
[string replaceOccurrencesOfString:@"%25" withString:@"%" options:NSLiteralSearch range:NSMakeRange(0, [string length])];
return [NSString stringWithString: string];
}
main.m
NSString *string1 = @"<strong>strong</strong>"; NSLog(@"%@, %@, %@", string1, [string1 escapeHtml], [[string1 escapeHtml] unescapeHtml]); NSString *string2 = @"%;/=?&"; NSLog(@"%@, %@, %@", string2, [string2 urlEncode], [[string2 urlEncode] urlDecode]);
Queue.h
#import <Foundation/Foundation.h>
#define kDefaultQueueSize 20
@interface Queue : NSObject <NSFastEnumeration>
{
@private
NSMutableArray *tasks_;
int capacity_;
}
@property (nonatomic, readonly) int capacity;
- (id)init;
- (id)initWithCapacity:(int)capacity;
- (void)dealloc;
- (void)add:(id)object;
- (id)remove;
- (int)count;
@end
Queue.m
#import "Queue.h"
@implementation Queue
@synthesize capacity = capacity_;
- (id)init
{
return [self initWithCapacity:kDefaultQueueSize];
}
- (id)initWithCapacity:(int)capacity
{
if (![super init]) return nil;
capacity_ = capacity;
tasks_ = [[NSMutableArray alloc] initWithCapacity:capacity];
return self;
}
- (void)dealloc
{
[tasks_ release]; tasks_ = nil;
[super dealloc];
}
- (void)add:(id)object
{
[tasks_ addObject:object];
if ([tasks_ count] > capacity_) {
[tasks_ removeObjectAtIndex:0];
}
}
- (id)remove
{
if ([tasks_ count] < 1) return nil;
id object = [tasks_ objectAtIndex:0];
[object retain];
[tasks_ removeObjectAtIndex:0];
return [object autorelease];
}
- (int)count
{
return [tasks_ count];
}
- (NSString *)description
{
return [tasks_ description];
}
- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id *)stackbuf count:(NSUInteger)len
{
return [tasks_ countByEnumeratingWithState:state objects:stackbuf count:len];
}
@end
使い方
Queue *queue = [[Queue alloc] initWithCapacity:3];
[queue add:@"1"];
[queue add:@"2"];
[queue add:@"3"];
[queue add:@"4"];
[queue add:@"5"];
NSLog(@"%@, %d", queue, [queue count]);
[queue remove];
NSLog(@"%@, %d", queue, [queue count]);
for (id object in queue) {
NSLog(@"%@", object);
}
目次
間違っているかもしれないので、つっこみ大歓迎!
メモリ解放の仕組み
- alloc,initすると参照カウンタが1になる
- retain, copy すると参照カウンタが1増える
- releaseすると参照カウンタが1減る
- 参照カウンタが0になるとdeallocが呼ばれる
- allocWithZone,copyWithZone,mutableCopy,mutableCopyWithZoneも参照カウンタを1増やす
ルール
- retainはアドレスコピー
- copyは別領域にメモリを確保してコピー
- NSString,NSArray,NSDictionaryなどのMutableでないクラスはcopyしてもアドレスコピーになってしまう!
- retain, copyをした人が責任を持つ
- auto releaseをしておけば責任放棄できる
- auto releaseが設定されている変数はreleaseしてはいけない
- auto release設定した変数は予期せぬタイミングでreleaseされる可能性があるので注意!
- +で始まるメソッドはauto release設定済みなのでreleaseしてはダメ(stringWithXXXとかarrayXXX)
- NSMutableArrayなどにaddObjectした変数はreleaseしないとメモリリークする。
- initXXXメソッドは、呼び出した側がreleaseする事。(auto release設定されていない)
ハマった点
- allocの時点では参照カウンタが1にならないクラスもある(alloc,initをセットでやる事!)
- シングルトンなクラスで保持しているNSStringの変数は他のクラス内変数にしない
どうやらアドレスを共有してしまうらしく、
対象クラスのdealloc時にメモリ内容がクリアされ次にその変数を見に行く時に落ちる。
参考
http://www.textdrop.net/google-styleguide-ja/objcguide.xml
要因は沢山あると思うんだけど俺がはまったケース。
原因
という事で起きました。
調べ方
NSLog(@"%@", NSStringFromCGRect(frame));
とやると情報が見れます。

最新コメント