ブログを色々いじった

On 2011年5月29日, in 未分類, by タカ

勉強しようと思っていたけど何故がブログいじりをしてしまった…。

やった事

テーマ変更

iBlogというテーマに変えた。

以前は、猫のテーマにしていた。
でも、WordPressの新しい機能との相性が悪かったので辞めた。

当初、iBlogのテーマだとシンタックスハイライトがGoogle Chromeで動かなかったんだよね。

まぁ、なんとか解決した。

内容見直し

目次をつけたり、HTMLのタグを見直したりしてた。

ちゃんと考えて書かないとダメだね(笑)

Twitter連動

記事書いたらTweetするようにしておいた。

Facebook連動は検討中。

もう一個立ち上げた

dotcloud使ってもう一個ブログ立ち上げた(笑)

正直、どう住み分けるか?を考えていない。

ただの勢いだけ…。

Tagged with:  

たまには技術以外の事を

On 2011年5月29日, in 未分類, by タカ

退職

という訳で、来月末で退職します。

最終出社日は6月10日(金)です。

残された工数は10人日!

どこまでできるか。

約2年間の最後の仕事!

この2年間

とても勉強になったと思う。

振り返ってみる。

月間十数億PVのサービスの開発・運用

これはとても刺激的で勉強になった!
今まで、ここまで大きなサービスに関わった事がなかったから。

色々、セオリーから外れたバットノウハウの塊みたいなシステムだったけどね(笑)

オブジェクト指向・設計

今までなんとなーくでやってたなぁと思い知らされた。

その時の上司はとても熱心にレビューしてくれたし、設計の相談にも乗ってくれた。

心の中で勝手に師匠と思ってるくらい素晴らしい人だった。

この人の退職していなかったらもう少し今の会社に居たかも?

それくらいにとても尊敬できる人に出会えた。

運営

サービスの運営の人と一緒に働くのは初めて。

工数の問題やシステムの問題で実現できない事も多々あったけどとても新鮮だった。

決して使いやすいとは言えないシステムだった。
でも、運営の人達の頑張りでここまで大きなサービスになったんだと思う。

ユーザさんの立場に立つという事をしっかり考えさせてくれました!

営業・管理

この人達がしっかりと稼いできてくれるから飯食えてます(笑)

アイディアがいっぱい持ってて熱い人達が多かったなぁ。

プライベートでいいから、ちゃんと形にして世に出したいね。

嫌だった所

もちろん、いい事だけではなかった。

役職的に部下という立場の方が居たのですが、色々大変だった…。
そこはもう振り返らない!

あとは、壁を感じた。
50人くらいの会社でこんな厚い壁はデメリットだと思う。

勢いで作ってしまえば早くやれるのに!
って結構苛立つ事もあったなぁ。

まとめ

という訳で、何故こんな事を書いているかと言うと…。

最終日に話さないといけないからです(笑)

ここら辺の内容からそれっぽく挨拶を考えます。

楽しい事の方が多かったとは思うのでネガティブではないです!

ありがとうごさいました!

 
という現象に遭遇。

同じ現象に遭遇している人も発見…。

原因は…

小一時間程あれこれして原因を特定。

それは、ウィジェットに設置していたAmazonのアフィリエイトだった…。
iframeとの相性が悪いのかな??

iframeでない物に差し替えたらシンタックス復活!!

Tagged with:  

CentOS 5.5にdotcloudの開発環境を作る

On 2011年5月13日, in dotcloud, by タカ

目次


意外とハマったのでメモ。

まだ、dotcloudのアカウントを持っていない人は、

http://www.dotcloud.com/

から。

ちょっと待っててな!的なメールがすぐに来て、2日もすればアカウント作れるよ!的なメールが届く。

さてさて、環境構築の流れは以下の通り。

  1. python 2.6.6のインストール
  2. easy_installのインストール
  3. dotcloudコマンドのインストール
  4. 開発用ユーザでいじってみる

ハマった点は

CentOS 5.5デフォルトのpythonのバージョンが低くてeasy_installでdotcloudが入らない

という点。

さくらのVPSで作業した。(sudo面倒だからrootで…)

python 2.6.6のインストール

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()
.bashrc設定

すでに入っている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

開発用ユーザでいじってみる

さすがにrootで開発するのは嫌なので、一般ユーザに設定を入れていじってみる。

.bashrc設定
$ 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ページを見ると書いてある。

PHPのアプリケーションを作ってみる
$ 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でもデプロイしてみようかなぁ。

Tagged with:  

【追記】INVALID_GADGET_TOKEN

On 2011年1月28日, in Shindig, by タカ

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は動かないんだけど、動くアプリも結構ある)

php/src/common/sample/BasicBlobCrypter.php:unwrapメソッド
$bin = base64_decode($in);

から

$bin = base64_decode(urldecode(base64_decode($in)));

todoが動かない理由はまだわからない…。

Tagged with:  

またまたサーバ移行

On 2011年1月22日, in ServersMan, さくら, by タカ
ServersMan@VPSがあまりにも使えない…。

  • vimが固まる
  • lsが固まる
  • rmが固まる

などなど。

ログインして作業する事が苦痛になってきた…。

というわけで、さくらのVPSに移行する事にしました。

その際に、PHP 5.3、MySQL 5.5にしちゃおうと思います。

うまくいくかなぁ。

Tagged with:  

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:@"&amp;" options:NSLiteralSearch range:NSMakeRange(0, [string length])];
  [string replaceOccurrencesOfString:@"<" withString:@"&lt;" options:NSLiteralSearch range:NSMakeRange(0, [string length])];
  [string replaceOccurrencesOfString:@">" withString:@"&gt;" options:NSLiteralSearch range:NSMakeRange(0, [string length])];
  [string replaceOccurrencesOfString:@"\"" withString:@"&quot;" options:NSLiteralSearch range:NSMakeRange(0, [string length])];
  return [NSString stringWithString: string];
}

- (NSString *)unescapeHtml
{
  NSMutableString *string = [[self mutableCopy] autorelease];
  [string replaceOccurrencesOfString:@"&quot;" withString:@"\"" options:NSLiteralSearch range:NSMakeRange(0, [string length])];
  [string replaceOccurrencesOfString:@"&gt;" withString:@">" options:NSLiteralSearch range:NSMakeRange(0, [string length])];
  [string replaceOccurrencesOfString:@"&lt;" withString:@"<" options:NSLiteralSearch range:NSMakeRange(0, [string length])];
  [string replaceOccurrencesOfString:@"&amp;" 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]);
Tagged with:  

キュー

On 2010年12月21日, in Objective-C, by タカ

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);
  }
Tagged with:  

目次


ひとまずまとめてみた。

間違っているかもしれないので、つっこみ大歓迎!

メモリ解放の仕組み

  1. alloc,initすると参照カウンタが1になる
  2. retain, copy すると参照カウンタが1増える
  3. releaseすると参照カウンタが1減る
  4. 参照カウンタが0になるとdeallocが呼ばれる
  5. allocWithZone,copyWithZone,mutableCopy,mutableCopyWithZoneも参照カウンタを1増やす

ルール

  1. retainはアドレスコピー
  2. copyは別領域にメモリを確保してコピー
  3. NSString,NSArray,NSDictionaryなどのMutableでないクラスはcopyしてもアドレスコピーになってしまう!
  4. retain, copyをした人が責任を持つ
  5. auto releaseをしておけば責任放棄できる
  6. auto releaseが設定されている変数はreleaseしてはいけない
  7. auto release設定した変数は予期せぬタイミングでreleaseされる可能性があるので注意!
  8. +で始まるメソッドはauto release設定済みなのでreleaseしてはダメ(stringWithXXXとかarrayXXX)
  9. NSMutableArrayなどにaddObjectした変数はreleaseしないとメモリリークする。
  10. initXXXメソッドは、呼び出した側がreleaseする事。(auto release設定されていない)

ハマった点

  1. allocの時点では参照カウンタが1にならないクラスもある(alloc,initをセットでやる事!)
  2. シングルトンなクラスで保持しているNSStringの変数は他のクラス内変数にしない

どうやらアドレスを共有してしまうらしく、
対象クラスのdealloc時にメモリ内容がクリアされ次にその変数を見に行く時に落ちる。

参考

Google Objective-Cスタイルガイド 日本語訳

http://www.textdrop.net/google-styleguide-ja/objcguide.xml

iPhoneアプリ開発時のメモリ管理で気をつけること

http://d.hatena.ne.jp/glass-_-onion/20090831/1251723900

Tagged with:  

要因は沢山あると思うんだけど俺がはまったケース。

原因

addSubviewする前に、不正なCGSize(マイナスの値)を設定してしまった

という事で起きました。

調べ方

オブジェクト表示する時に、サイズが正しいか表示してみてはどうでしょう?

NSLog(@"%@", NSStringFromCGRect(frame));

とやると情報が見れます。

Tagged with: