2010/10/13

Twitter Botの登録(AccessTokenの発行)

http://dev.twitter.com/からログイン
http://dev.twitter.com/apps/からアプリケーション登録
Consumer keyとConsumer secretを取得

Access tokenとAccess secret取得には
http://gist.github.com/388067が便利なのでgitからclone
gem twitter oauthが必要

ruby make_token.rbをする
Consumer keyとConsumer secretを入力
表示されるURLにアクセスしてPINを入手
Access tokenとAccess secret取得

あとはこんな感じで
base = TwitterOAuth::Client.new({
  :consumer_key=>'',
  :consumer_secret=>'',
  :token=>'',
  :secret=>''
})

#base.update("もう"+Time.now.strftime("%H時%M分")+"か。。。。。" )
bit.lyを使うなら
def shorten(long_url)
  id = ''
  api_key = ''
  version = '2.0.1'
  query = "version=#{version}&longUrl=#{long_url}&login=#{id}&apiKey=#{api_key}"
  result = JSON.parse(Net::HTTP.get("api.bit.ly", "/shorten?#{query}"))
  result['results'].each_pair {|long_url, value|
 return value['shortUrl']
  }
end

非常に分かりやすい参考動画 http://www.youtube.com/watch?v=vTMuI4ln6Rc

2010/09/07

GAEでのアップデートエラー

GAEでアップデート中にキャンセル等をすると次回以降エラーでアップデートできなくなるときがあります。エラー内容は次の様な形でrollbackしろとの指示が出ます。
undo the transaction with appcfg.py's "rollback" command.
その場合はターミナルから次のコマンドを入力します。
appcfg.py -verbose --no_cookies --email=アドレス --passin rollback 対象のディレクトリ

2010/08/18

MixiアプリのDeveloper登録

Mixiアプリを作るときはhttps://sap.mixi.jp/home.plからDeveloper登録を行ないます。
最後に携帯メールでの認証があるのですがiPhoneの場合は@i.softbank.jpの方にメールをしないとうまくいきません。

2010/07/30

macportのインストール

macのパッケージ管理はmacportが便利です。毎回ビルドするのでちょっと遅いですが。
インストール方法はオフィシャルサイトからイメージをダウンロード後、インストールします。その後、.bash_profileに次のパスを追記します。
export PATH=/opt/local/bin:/opt/local/sbin/:$PATH
export MANPATH=/opt/local/man:$MANPATH

環境はSnowLeopardです。
Leopardからアップデートした場合にmigrationが必要になる場合があるようです。
方法はオフィシャルサイトに書いてあります。
port installed > myports.txt
sudo port -f uninstall installed
sudo port clean --work --archive all
これで全て消したあと自動的に再インストールするスクリプトを実行。
curl -O http://svn.macports.org/repository/macports/contrib/restore_ports/restore_ports.tcl
chmod +x restore_ports.tcl
sudo ./restore_ports.tcl myports.txt
上がダメな場合はmyport.txtを見ながら手動で入れてくれとのこと。
sudo port install portname +variant1 +variant2 ...

公開鍵の作り方

sftpなどのための公開鍵の作り方についてまとめておきます。
$ whoami
(ユーザー名)
$ ssh-keygen -t rsa //カギを作成する
Generating public/private rsa key pair.
Enter file in which to save the key (/home/(ユーザー名)/.ssh/id_rsa):
Created directory '/home/(ユーザー名)/.ssh'.   
Enter passphrase (empty for no passphrase): //パスワードを入力
Enter same passphrase again: //もう一度パスワードを入力
Your identification has been saved in /home/(ユーザー名)/.ssh/id_rsa.
Your public key has been saved in /home/(ユーザー名)/.ssh/id_rsa.pub.
The key fingerprint is:
ff:8a:6b:d8:eb:ad:68:90:33:eb:2c:6c:d8:ea:98:41 (ユーザー名)@(PC名)
$ ls -la ~/.ssh //確認
合計 16
drwx------    2 xxx     xxx         4096 Feb  2 13:53 ./
drwx------   22 xxx     xxx         4096 Feb  2 13:53 ../
-rw-------    1 xxx     xxx          951 Feb  2 13:53 id_rsa     //秘密鍵
-rw-r--r--    1 xxx     xxx          236 Feb  2 13:53 id_rsa.pub //公開鍵
$ mv ~/.ssh/id_rsa.pub ~/.ssh/authorized_keys //authorized_keysにリネーム

SnowLeopardにPerl環境構築

基本はモダンなPerlの開発環境の構築方法を参考にする。

Xcodeは普通に入れて下さい。
Perlbrewを入れる。
$ curl -LO http://xrl.us/perlbrew
$ chmod +x perlbrew
$ ./perlbrew install
.bachrc_profileにsource ~/perl5/perlbrew/etc/bashrc を追記。
.bachrc_profileファイルは無かったので新規に作る。
ターミナルを再起動してPerlを最新版にする。
% perlbrew install perl-5.12.1
% perlbrew switch perl-5.12.1
ちょっと時間がかかるので待つ。
cpanmを入れる。今回はGitで入れました。
$ git clone git://github.com/miyagawa/cpanminus.git
$ cd cpanminus
$ perl Makefile.PL
$ make install

local::lib をインストールする。
$ cpanm local::lib
ここまでがリンク先で書かれていたPerl開発環境。

cpam moduleをアップデート。
$ cpanm App::cpanoutdated
$ cpan-outdated | cpanm -L ~/perl5
Plaggerをインストール。
$ git clone git://github.com/miyagawa/plagger.git
$ cd plagger
$ cpanm -L ~/perl5 .

2010/07/20

memcachedの起動メモ

memcachedの起動メモ。メモリ1Gで接続許可はローカルホストの場合
memcached -u memcached -d -m 1024 -l 127.0.0.1