• 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
 
 

Scalaを勉強しなおすために、まずHaskellを勉強してからの方がScalaを理解しやすいという話を聞いたので、Haskellの勉強を始めることにしました。ということでまずはHaskellのコンパイラ、GHC(The Glasgow Haskell Compiler)をインストールしました。yumであっさりインストールできてしまいました。

   1  # yum install ghc
   2  Loaded plugins: fastestmirror
   3  Loading mirror speeds from cached hostfile
   4   * base: ftp.iij.ad.jp
   5   * epel: ftp.tsukuba.wide.ad.jp
   6   * extras: ftp.iij.ad.jp
   7   * remi: rpms.famillecollet.com
   8   * updates: ftp.iij.ad.jp
   9  Setting up Install Process
  10  Resolving Dependencies
  11  --> Running transaction check
  12  ---> Package ghc.x86_64 0:6.10.4-3.el5 set to be updated
  13  --> Processing Dependency: gmp-devel for package: ghc
  14  --> Processing Dependency: libgmp.so.3()(64bit) for package: ghc
  15  --> Running transaction check
  16  ---> Package gmp.x86_64 0:4.1.4-10.el5 set to be updated
  17  ---> Package gmp-devel.x86_64 0:4.1.4-10.el5 set to be updated
  18  --> Finished Dependency Resolution
  19  
  20  Dependencies Resolved
  21  
  22  ========================================================================================================================
  23   Package                      Arch                      Version                           Repository               Size
  24  ========================================================================================================================
  25  Installing:
  26   ghc                          x86_64                    6.10.4-3.el5                      epel                     43 M
  27  Installing for dependencies:
  28   gmp                          x86_64                    4.1.4-10.el5                      base                    201 k
  29   gmp-devel                    x86_64                    4.1.4-10.el5                      base                    569 k
  30  
  31  Transaction Summary
  32  ========================================================================================================================
  33  Install       3 Package(s)
  34  Upgrade       0 Package(s)
  35  
  36  Total download size: 44 M
  37  Is this ok [y/N]: y
  38  Downloading Packages:
  39  (1/3): gmp-4.1.4-10.el5.x86_64.rpm                                                               | 201 kB     00:00
  40  (2/3): gmp-devel-4.1.4-10.el5.x86_64.rpm                                                         | 569 kB     00:00
  41  (3/3): ghc-6.10.4-3.el5.x86_64.rpm                                                               |  43 MB     00:07
  42  ------------------------------------------------------------------------------------------------------------------------
  43  Total                                                                                   5.5 MB/s |  44 MB     00:08
  44  Running rpm_check_debug
  45  Running Transaction Test
  46  Finished Transaction Test
  47  Transaction Test Succeeded
  48  Running Transaction
  49    Installing     : gmp                                                                                              1/3
  50    Installing     : gmp-devel                                                                                        2/3
  51    Installing     : ghc                                                                                              3/3
  52  
  53  Installed:
  54    ghc.x86_64 0:6.10.4-3.el5
  55  
  56  Dependency Installed:
  57    gmp.x86_64 0:4.1.4-10.el5                               gmp-devel.x86_64 0:4.1.4-10.el5
  58  
  59  Complete!

コマンドが存在することを確認します。

   1  # which ghci
   2  /usr/bin/ghci
   3  # which ghc
   4  /usr/bin/ghc

バージョンの確認。

   1  # ghc --version
   2  The Glorious Glasgow Haskell Compilation System, version 6.10.4

対話モードで起動してみます。

   1  # ghci
   2  GHCi, version 6.10.4: http://www.haskell.org/ghc/  :? for help
   3  Loading package ghc-prim ... linking ... done.
   4  Loading package integer ... linking ... done.
   5  Loading package base ... linking ... done.
   6  Prelude>
   7  Prelude> :q
   8  Leaving GHCi.
   9  #

ひとまずコンパイラのインストールは問題なくできたようです。

posted by Png akanuma on Mon 18 Jun 2012 at 13:24

 Perl と cpanm がインストールされて入れば、Catalystをインストールするには cpanm Ctalyst::Devl を実行するだけでOK。

   1  $ cpanm Catalyst::Devel
   2  !
   3  ! Can't write to /usr/lib/perl5/site_perl/5.8.8 and /usr/bin: Installing modules to /home/akanuma/perl5
   4  ! To turn off this warning, you have to do one of the following:
   5  !   - run me as a root or with --sudo option (to install to /usr/lib/perl5/site_perl/5.8.8 and /usr/bin)
   6  !   - Configure local::lib your existing local::lib in this shell to set PERL_MM_OPT etc.
   7  !   - Install local::lib by running the following commands
   8  !
   9  !         cpanm --local-lib=~/perl5 local::lib && eval 500 500perl -I ~/perl5/lib/perl5/ -Mlocal::lib)
  10  !
  11  --> Working on Catalyst::Devel
  12  Fetching http://www.cpan.org/authors/id/B/BO/BOBTFISH/Catalyst-Devel-1.37.tar.gz ... OK
  13  Configuring Catalyst-Devel-1.37 ... OK
  14  ==> Found dependencies: Test::Fatal, Catalyst::Plugin::ConfigLoader, MooseX::Emulate::Class::Accessor::Fast, Starman, File::ChangeNotify, File::ShareDir, Config::General, Catalyst, MooseX::Daemonize, Moose, namespace::autoclean, Catalyst::Plugin::Static::Simple, Template, Module::Install, Catalyst::Action::RenderView, namespace::clean
  15  --> Working on Test::Fatal
  16  Fetching http://www.cpan.org/authors/id/R/RJ/RJBS/Test-Fatal-0.010.tar.gz ... OK
  17  Configuring Test-Fatal-0.010 ... OK
  18  ==> Found dependencies: Try::Tiny
  19  ~~~ 以下略 ~~~

posted by Png akanuma on Sun 17 Jun 2012 at 22:48

CentOS上からgithubを使えるようにしたので作業内容をメモ。

まずはyumでgitをインストールします。ちなみにCentOSのバージョンは5.8です。

   1  # yum install git
   2  Loaded plugins: fastestmirror
   3  Loading mirror speeds from cached hostfile
   4   * base: rsync.atworks.co.jp
   5   * epel: ftp.iij.ad.jp
   6   * extras: rsync.atworks.co.jp
   7   * remi: rpms.famillecollet.com
   8   * updates: rsync.atworks.co.jp
   9  Setting up Install Process
  10  Resolving Dependencies
  11  --> Running transaction check
  12  ---> Package git.x86_64 0:1.7.4.1-1.el5 set to be updated
  13  --> Processing Dependency: perl-Git = 1.7.4.1-1.el5 for package: git
  14  --> Processing Dependency: rsync for package: git
  15  --> Processing Dependency: perl(Error) for package: git
  16  --> Processing Dependency: perl(Git) for package: git
  17  --> Running transaction check
  18  ---> Package perl-Error.noarch 1:0.17010-1.el5 set to be updated
  19  ---> Package perl-Git.x86_64 0:1.7.4.1-1.el5 set to be updated
  20  ---> Package rsync.x86_64 0:3.0.6-4.el5_7.1 set to be updated
  21  --> Finished Dependency Resolution
  22  
  23  Dependencies Resolved
  24  
  25  ========================================================================================================================
  26   Package                      Arch                     Version                             Repository              Size
  27  ========================================================================================================================
  28  Installing:
  29   git                          x86_64                   1.7.4.1-1.el5                       epel                   4.5 M
  30  Installing for dependencies:
  31   perl-Error                   noarch                   1:0.17010-1.el5                     epel                    26 k
  32   perl-Git                     x86_64                   1.7.4.1-1.el5                       epel                    28 k
  33   rsync                        x86_64                   3.0.6-4.el5_7.1                     base                   347 k
  34  
  35  Transaction Summary
  36  ========================================================================================================================
  37  Install       4 Package(s)
  38  Upgrade       0 Package(s)
  39  
  40  Total download size: 4.9 M
  41  Is this ok [y/N]: y
  42  Downloading Packages:
  43  (1/4): perl-Error-0.17010-1.el5.noarch.rpm                                                       |  26 kB     00:00
  44  (2/4): perl-Git-1.7.4.1-1.el5.x86_64.rpm                                                         |  28 kB     00:00
  45  (3/4): rsync-3.0.6-4.el5_7.1.x86_64.rpm                                                          | 347 kB     00:00
  46  (4/4): git-1.7.4.1-1.el5.x86_64.rpm                                                              | 4.5 MB     00:00
  47  ------------------------------------------------------------------------------------------------------------------------
  48  Total                                                                                   4.1 MB/s | 4.9 MB     00:01
  49  Running rpm_check_debug
  50  Running Transaction Test
  51  Finished Transaction Test
  52  Transaction Test Succeeded
  53  Running Transaction
  54    Installing     : perl-Error                                                                                       1/4
  55    Installing     : rsync                                                                                            2/4
  56    Installing     : git                                                                                              3/4
  57    Installing     : perl-Git                                                                                         4/4
  58  
  59  Installed:
  60    git.x86_64 0:1.7.4.1-1.el5
  61  
  62  Dependency Installed:
  63    perl-Error.noarch 1:0.17010-1.el5        perl-Git.x86_64 0:1.7.4.1-1.el5        rsync.x86_64 0:3.0.6-4.el5_7.1
  64  
  65  Complete!

続いてgithubのヘルプページを参考にして環境設定。 まずはコミット時に使うユーザ名とメールアドレスを設定します。

   1  $ git config --global user.name "h-akanuma"
   2  $ git config --global user.email "hiroaki.akanuma@gmail.com"

メールアドレスは正しいメールアドレスを設定する必要はなくて、コミットを識別するためのものなので、user@server のような形にしてどこからのコミットかを判別できるようにしても良いらしいです。

次はパスワードのキャッシュ設定。リモートサーバにアクセスするたびにパスワードを入力しなくても良いように、パスワードをキャッシュする設定をします。また、デフォルトのキャッシュの有効期限は15分間なので、とりあえず1時間に変更しておきます。

   1  $ git config --global credential.helper cache
   2  $ git config --global credential.helper 'cache --timeout=3600'

これだけでひとまず全体的な設定は終了なので、ブラウザでgithubにアクセスして新しくリポジトリを作成します。

そして再びCentOS上での作業です。バージョン管理対象にするディレクトリを作成して初期化します。

   1  $ mkdir PerlTools
   2  $ cd PerlTools/
   3  $ git init
   4  Initialized empty Git repository in /home/akanuma/scripts/PerlTools/.git/

バージョン管理したいファイルを作成し、ローカルリポジトリにコミットします。

   1  $ cp ../cut_time.pl .
   2  $ ls -la
   3  合計 16
   4  drwxrwxr-x 3 akanuma akanuma 4096  6月 10 00:29 .
   5  drwxrwxr-x 3 akanuma akanuma 4096  6月 10 00:28 ..
   6  drwxrwxr-x 7 akanuma akanuma 4096  6月 10 00:28 .git
   7  -rw-rw-r-- 1 akanuma akanuma 1336  6月 10 00:29 cut_time.pl
   8  $
   9  $ git add cut_time.pl
  10  $ git commit -m 'Script for cutting file content by time range'
  11  [master (root-commit) a677816] Script for cutting file content by time range
  12   1 files changed, 75 insertions(+), 0 deletions(-)
  13   create mode 100644 cut_time.pl

そしてローカルリポジトリへのコミット内容をgithubへpushします。

   1  $ git remote add origin https://github.com/h-akanuma/PerlTools.git
   2  $ git push origin master
   3  Username:
   4  Password:
   5  Counting objects: 3, done.
   6  Compressing objects: 100% (2/2), done.
   7  Writing objects: 100% (3/3), 757 bytes, done.
   8  Total 3 (delta 0), reused 0 (delta 0)
   9  To https://github.com/h-akanuma/PerlTools.git
  10   * [new branch]      master -> master

これでgithubへコミット内容が反映されました。 他のリポジトリのForkはまだやっていないのでまたそのうち。

posted by Png akanuma on Sun 10 Jun 2012 at 00:53

Linux上でファイル名が文字化けする場合があります。

   1  $ ls result.log.*
   2  result.log.Fri
   3  result.log.Thu
   4  result.log.??
   5  result.log.??
   6  result.log.??

こうなると普通にファイル名を指定して操作することができません。

   1  $ wc -l 'result.log.??'
   2  wc: result.log.??: No such file or directory

この場合はlsの出力結果をnkfで変換して正しいファイル名を確認します。

   1  $ ls result.log.* | nkf -e
   2  result.log.Fri
   3  result.log.Thu
   4  result.log.金
   5  result.log.土
   6  result.log.木

確認したファイル名を指定することでファイルが操作できます。

   1  $ wc -l result.log.金
   2  409 result.log.金

posted by Png akanuma on Fri 8 Jun 2012 at 09:12 with 1 comment

 CGI::Sessionを使うためにCPANでインストールしようとしたところ、「サーバの応答にエラーがあるので、接続を終了します。再試行しています。」となって最終的にインストールに失敗してしまいました。ネットで検索したところ、FTPサーバに接続できていないためのようで、CPANのシェルから下記コマンドでurllistに他のFTPサーバを追加しました。
 参考サイト cpanを利用したperlモジュールインストール不具合

   1  cpan> o conf urllist push ftp://ftp.u-aizu.ac.jp/pub/CPAN
   2  
   3  cpan> o conf urllist push ftp://ftp.kddilabs.jp/CPAN/
   4  
   5  cpan> o conf urllist push ftp://ftp.jaist.ac.jp/pub/lang/perl/CPAN/
   6  
   7  cpan> o conf urllist push http://ftp.cpan.jp/
   8  
   9  cpan> o conf urllist push ftp://ftp.dti.ad.jp/pub/lang/CPAN/
  10  
  11  cpan> o conf urllist push ftp://ftp.ring.gr.jp/pub/lang/perl/CPAN/
  12  
  13  cpan>

 そして再度インストールを実行し、今度は成功しました。

   1  cpan> install CGI::Session
   2  Running install for module CGI::Session
   3  Running make for M/MA/MARKSTOS/CGI-Session-4.48.tar.gz
   4  ~~~ 中略 ~~~
   5  Writing /usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/auto/CGI/Session/.packlist
   6  Appending installation info to /usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/perllocal.pod
   7    /usr/bin/make install  -- OK

posted by Png akanuma on Thu 24 May 2012 at 21:34

 CPANからDate::Simpleをインストールしようとすると、make testで失敗してインストールできませんでした。

   1  # perl -MCPAN -e 'install Date::Simple'
   2  CPAN: Storable loaded ok
   3  Going to read /root/.cpan/Metadata
   4    Database was generated on Tue, 22 May 2012 05:43:03 GMT
   5  Running install for module Date::Simple
   6  Running make for I/IZ/IZUT/Date-Simple-3.03.tar.gz
   7  ~~~ 中略 ~~~
   8  make: *** [test_dynamic] エラー 1
   9    /usr/bin/make test -- NOT OK
  10  Running make install
  11    make test had returned bad status, won't install without force

 この場合は環境変数LANG=Cに設定すれば成功するようです。
参考サイト Date::Simpleのインストール失敗と、その対応

   1  # echo $LANG
   2  ja_JP.UTF-8
   3  # export LANG=C
   4  # echo $LANG
   5  C

 再実行します。

   1  # perl -MCPAN -e 'install Date::Simple'
   2  CPAN: Storable loaded ok
   3  Going to read /root/.cpan/Metadata
   4    Database was generated on Tue, 22 May 2012 05:43:03 GMT
   5  Running install for module Date::Simple
   6  Running make for I/IZ/IZUT/Date-Simple-3.03.tar.gz
   7  ~~~ 中略 ~~~
   8  Writing /usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/auto/Date/Simple/.packlist
   9  Appending installation info to /usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/perllocal.pod
  10    /usr/bin/make install  -- OK

posted by Png akanuma on Thu 24 May 2012 at 06:47

平河町1-3-9 ブルービル別館 1Fにあるオー・プロヴァンソーに行きました。 フレンチのお店です。二度目の訪問になります。

食べログはこちら
お店のHPはこちら

ランチは、

DejeunerA
本日のスープ、本日の魚料理又は肉料理、デザート、コーヒー(紅茶、エスプレッソ、ハーブティーなど)  2,500円

DejeunerB
色々な前菜からお好みの一皿、本日の魚料理又は肉料理、デザート、コーヒー(紅茶、エスプレッソ、ハーブティーなど)  3,000円

DejeunerC
色々な前菜からお好みの一皿、シェフ特選魚料理、シェフ特選肉料理、デザート、コーヒー(紅茶、エスプレッソ、ハーブティーなど)  6,000円

DejeunerD
色々な前菜からお好みの一皿、ちょっと美味しいハヤシライス、デザート、コーヒー(紅茶、エスプレッソ、ハーブティーなど)  4,300円(限定5食)

です。 前回訪問時と比較して、 DejeunerDが200円安くなりました。

DejeunerA以外にも800円で本日のスープを付けられます。
このときはグリーンピースのスープでした。
前菜は前回と変わらず、
野菜のムースと小海老のコンソメゼリー添え
魚介のサラダ仕立て 黒トリュフソース
フォワグラのテリーヌ いちじくの赤ワイン煮
ジャンボマッシュルームのグラタン ボルドー風
サーモンと帆立貝、季節の野菜のゼリー寄せ
本日の前菜から選ぶようになっていました。

今回はDejeunerBを注文しました。

DSC_0030.JPG
・パン
3種類のパンがありました。前回は印象の良かったパンですが、今回はあまりおいしく感じませんでした。

DSC_0035.JPG
・前菜
ジャンボマッシュルームのグラタン ボルドー風にしました。 普通のグラタンのようなものを想像していたのでびっくりしました。器がマッシュルームです。本当に大きいです。 器にはマッシュルーム軸の部分?とベーコンが入っていたように思いますが、確かではないです。 茸が好きな方ならお勧めです。

DSC_0041.JPG
・メイン
子牛の冷温ローストだったと思います。 柔らかめのお肉で食べやすかったです。前回のメインより印象がいいですが、すごくおいしいというほどではなかったです。おいしくないわけではないですが、普通においしいくらいです。

DSC_0043.JPG
・デザート
こちらのお店の一番の楽しみのワゴンデザートです。
挙動不審にしていたらワゴンの状態で撮影させてもらえました。
手前からベイクドチーズケーキ、ガトーショコラ、苺のロールケーキ、抹茶とホワイトチョコのケーキ、ココナッツのブラマンジェ、クレームブリュレでした。
DSC_0046.JPG
今回も全品頼みました。ガトーショコラとクレームブリュレは前回と同じで、ロールケーキは中身が違いました。 ベイクドチーズケーキはチーズそのものを食べているような濃厚な味わいです。 ロールケーキは相変わらずスポンジがふわふわです。 抹茶とホワイトチョコは抹茶が強かったですが、ホワイトチョコもしっかり感じます。 ココナッツのブラマンジェはクリーム状でおいしかったです。 どれも良かったです。
DSC_0044.JPG
こちらはロールケーキのみを注文した場合です。 当然ですが、厚さが結構違います。

同伴者が注文したものも載せておきます。

DSC_0033.JPG
・前菜
サーモンと帆立貝、季節の野菜のゼリー寄せです。

DSC_0037.JPG
・本日のスープ
グリーンピースっぽさはあまりなく、チーズのような味わいだったようです。

DSC_0039.JPG
・ちょっと美味しいハヤシライス
お肉の塊がのっています。見た目は濃厚そうです。これまで食べたハヤシライスの中では一番おいしいと言っていました。

posted by Png mari2 on Tue 22 May 2012 at 21:47
15th Tue

ハラカラ。

世田谷区三軒茶屋2-16-8にあるハラカラ。に行きました。
ハンバーガーのお店です。

DSC_0007.JPG

食べログはこちら
お店のHPはこちらtitle

DSC_0012.JPG

ハンバーガー850円
チーズバーガー950円
パインバーガー950円
目玉焼きバーガー1,000円
クリームチーズバーガー1,050円
鬼おろししそバーガー1,050円
アボガドバーガー1,100円
ベーコンバーガー1,100円
チーズ三昧バーガー1,100円
ダブルバーガー1,150円
トリプルバーガー1,450円

DSC_0013.JPG

などがあります。
他にサンドイッチやトッピング、サイドオーダー、サラダなどがあります。
セットメニューにはドリンクセットとスペシャルセットがあります。
ドリンクセットはハンバーガーやサンドイッチに100円でドリンクを追加できます。
スペシャルセットはドリンクセット+サードオーダーやスープを250円で追加できます(ただし、量はSサイズの半分です)。

DSC_0017.JPG

パインバーガーを注文しました。
パインの酸味がハンバーガーに良く合います。

DSC_0021.JPG

こちらのハンバーガーはパンもとってもおいしいです。パンだけでもおいしく食べられると思います。
ハンバーグもジューシーでおいしいです。
テーブルにはハンバーガーを入れる袋と、フォークとナイフがあります。
袋に入れて食べてもいいですし、カットして食べても良いようになっています。
いつも袋に入れて食べています。

DSC_0002.JPG

2011年10月22日から、ぷりぷり海老とアボガドのサンドイッチ900円と、ヴィシソワーズスープが追加されています。

DSC_0004.JPG

ヴィシソワーズスープはお試しのミニスープ(280円)、Sサイズ(480円)、Lサイズ(580円)があります。冷製も温製もできます。
写真はSサイズのものです。

また、今回はアンケートがテーブルの片隅に置いてありました。
トマトが苦手な人が多い、高価ということで、トマトを抜いてレタスを増量する案があるようです。
トマトは好きなので抜かないでもらいたいですが、抜いたとしてもレタスの増量はいらないように思いました。すでにかなりボリュームがあるので。

posted by Png mari2 on Tue 15 May 2012 at 10:30

港区南青山2-13-7 マトリス 1Fにあるgrace Kihachirou HACHISUKAに行きました。 自然栽培野菜にこだわったフレンチのお店です。

食べログはこちら
お店のHPはこちら

ランチのコースは、自然栽培野菜のミジョテと魚料理、肉料理とデザートの組み合わせになります。 2,500円~6,500円までの5種類のコースがあります。 すべてのコースにスペシャリテである自然栽培野菜のミジョテがつきます。 3,500円のコースを注文しました。

DSC_0003.JPG

テーブルにお皿にのったコイン状のものがありました。席につくと店員さんがそれに水をかけてくれます。 長く伸びていってお手拭になりました。面白かったです。

DSC_0005.JPG

はじめに薄いパイのようなものが提供されました。 塩味だったような気がします。

DSC_0011.JPG DSC_0013.JPG

・パン
パンとバターです。 バターについていた塩がすごくおいしかったです。

DSC_0016.JPG

・アミューズ
新玉ねぎのスープでした。

DSC_0018.JPG

・前菜
佐賀産ホワイトアスパラガスと埼玉産田ゼリ、和歌山産稚鮎、氷見産ホタルイカ、春の温製サラダ仕立て 葉わさびの香り 緑のソースが葉わさびです。確かにちょっと辛みがありました。ホタルイカは苦味がありました。しっかりしたホワイトアスパラガスはおいしかったです。

DSC_0020.JPG

・自然栽培野菜のミジョテ
たくさんの野菜を食べられました。酸味が強かったです。

DSC_0029.JPG

・肉料理
メニューにはイノシシとありましたが、変更になっていました。 子牛のバラ肉のコンフィでした。 お肉が大きかったです。程よい柔らかさがありました。野菜もおいしかったです。

DSC_0034.JPG

・デザート
茨城県産フルーツトマトと栃木産あまおうのヴルーテ モッツァレラチーズとバジルの香り 結構しっかりトマト味です。多少の青臭さもありますがおいしかったです。

DSC_0040.JPG DSC_0043.JPG

・紅茶
紅茶、コーヒー、エスプレッソなどがありました。 カヌレが付きます。カヌレはスイートポテトのような味がしましたが、賛同は得られませんでした。外側は硬いです。

シェフの方がテーブルまで挨拶に来てくれましたし、帰りもシェフを含め三人くらいの方で見送ってくれました。 味も良かったですが、雰囲気も良いお店です。 特に野菜が好きな方にはお勧めです。野菜はこだわっているだけあっておいしいのですが、味が濃かったりするので、野菜が苦手な人にも大丈夫、というものではないと思います。物によっては普段食べているものより苦手になるかと思います。

posted by Png mari2 on Sat 12 May 2012 at 17:54

Base32 URL はでっちあげたもの。

   1  
   2  static	char* sBase16Table1 = "0123456789ABCDEF";
   3  static	char* sBase16Table2 = "0123456789abcdef";
   4  
   5  static	NSString*
   6  StringEncodedByHEX( NSData* p )
   7  {	char* w = (char*)p.bytes;
   8  	int wNumOutputBytes = p.length * 2;
   9  	char v[ wNumOutputBytes ];
  10  	for ( int i = 0; i < p.length; i++ )
  11  	{	v[ i * 2 ] = ( w[ i ] >> 4 ) & 0x0f;
  12  		v[ i * 2 + 1 ] = w[ i ] & 0x0f;
  13  	}
  14  	for ( int i = 0; i < wNumOutputBytes; i++ ) v[ i ] = sBase16Table1[ v[ i ] ];
  15  	return [ [ NSString alloc ] initWithBytes:v length:wNumOutputBytes encoding:NSUTF8StringEncoding ];
  16  }
  17  
  18  
  19  static	NSData*
  20  DataDecodedByHEX( NSString* p )
  21  //	If the number of valid characters is odd number, the last one will be ignored.
  22  {	char wBuffer[ p.length ];
  23  	int	wValidCharCounter = 0;
  24  	for ( int i = 0; i < p.length; i++ )
  25  	{	char* wPtr = strchr( sBase16Table1, [ p characterAtIndex:i ] );
  26  		if ( wPtr ) wBuffer[ wValidCharCounter++ ] = wPtr - sBase16Table1;
  27  		else
  28  		{	wPtr = strchr( sBase16Table2, [ p characterAtIndex:i ] );
  29  			if ( wPtr ) wBuffer[ wValidCharCounter++ ] = wPtr - sBase16Table2;
  30  		}
  31  	}
  32  	int wSize = wValidCharCounter * 4 / 8;
  33  	char v[ wSize ];
  34  	for ( int i = 0; i < wSize; i++ ) v[ i ] = ( wBuffer[ i * 2 ] << 4 ) | wBuffer[ i * 2 + 1 ];
  35  	return [ NSData dataWithBytes:v length:wSize ];
  36  }
  37  
  38  static	char* sBase32URLTable1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
  39  static	char* sBase32URLTable2 = "abcdefghijklmnopqrstuvwxyz";
  40  
  41  static	NSString*
  42  StringEncodedByBase32URL( NSData* p )
  43  //	Although there is no standard named Base32URL but we need it.
  44  //	The difference with Base32 is that it doesn't use padding charater i.e. '='.
  45  {	int	wNumInputBits = p.length * 8;
  46  	int wNumOutputBytes = ( wNumInputBits + 4 ) / 5;
  47  	char* w = (char*)p.bytes;
  48  	char v[ wNumOutputBytes ];
  49  	for ( int i = 0; i < wNumOutputBytes; i++ ) v[ i ] = 0;
  50  	for ( int i = 0; i < wNumInputBits; i++ ) v[ i / 5 ] |= ( ( w[ i / 8 ] >> ( 7 - i % 8 ) ) & 1 ) << ( 4 - i % 5 );
  51  	for ( int i = 0; i < wNumOutputBytes; i++ ) v[ i ] = sBase32URLTable1[ v[ i ] ];
  52  	return [ [ NSString alloc ] initWithBytes:v length:wNumOutputBytes encoding:NSUTF8StringEncoding ];
  53  }
  54  
  55  static	NSData*
  56  DataDecodedByBase32URL( NSString* p )
  57  {	char wBuffer[ p.length ];
  58  	int	wValidCharCounter = 0;
  59  	for ( int i = 0; i < p.length; i++ )
  60  	{	char* wPtr = strchr( sBase32URLTable1, [ p characterAtIndex:i ] );
  61  		if ( wPtr ) wBuffer[ wValidCharCounter++ ] = wPtr - sBase32URLTable1;
  62  		else
  63  		{	wPtr = strchr( sBase32URLTable2, [ p characterAtIndex:i ] );
  64  			if ( wPtr ) wBuffer[ wValidCharCounter++ ] = wPtr - sBase32URLTable2;
  65  		}
  66  	}
  67  	int wSize = wValidCharCounter * 5 / 8;
  68  	char v[ wSize ];
  69  	for ( int i = 0; i < wSize; i++ ) v[ i ] = 0;
  70  	for ( int i = 0; i < wSize * 8; i++ ) v[ i / 8 ] |= ( wBuffer[ i / 5 ] >> ( 4 - i % 5 ) ) << ( 7 - i  % 8 );
  71  	return [ NSData dataWithBytes:v length:wSize ];
  72  }
  73  
  74  static	char* sBase64URLTable = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
  75  
  76  static	NSString*
  77  StringEncodedByBase64URL( NSData* p )
  78  {	int	wNumInputBits = p.length * 8;
  79  	int wNumOutputBytes = ( wNumInputBits + 5 ) / 6;
  80  	char* w = (char*)p.bytes;
  81  	char v[ wNumOutputBytes ];
  82  	for ( int i = 0; i < wNumOutputBytes; i++ ) v[ i ] = 0;
  83  	for ( int i = 0; i < wNumInputBits; i++ ) v[ i / 6 ] |= ( ( w[ i / 8 ] >> ( 7 - i % 8 ) ) & 1 ) << ( 5 - i % 6 );
  84  	for ( int i = 0; i < wNumOutputBytes; i++ ) v[ i ] = sBase64URLTable[ v[ i ] ];
  85  	return [ [ NSString alloc ] initWithBytes:v length:wNumOutputBytes encoding:NSUTF8StringEncoding ];
  86  }
  87  
  88  static	NSData*
  89  DataDecodedByBase64URL( NSString* p )
  90  {	char wBuffer[ p.length ];
  91  	int	wValidCharCounter = 0;
  92  	for ( int i = 0; i < p.length; i++ )
  93  	{	char* wPtr = strchr( sBase64URLTable, [ p characterAtIndex:i ] );
  94  		if ( wPtr ) wBuffer[ wValidCharCounter++ ] = wPtr - sBase64URLTable;
  95  	}
  96  	int wSize = wValidCharCounter * 6 / 8;
  97  	char v[ wSize ];
  98  	for ( int i = 0; i < wSize; i++ ) v[ i ] = 0;
  99  	for ( int i = 0; i < wSize * 8; i++ ) v[ i / 8 ] |= ( wBuffer[ i / 6 ] >> ( 5 - i % 6 ) ) << ( 7 - i  % 8 );
 100  	return [ NSData dataWithBytes:v length:wSize ];
 101  }
 102  

posted by Face Saturn on Mon 7 May 2012 at 13:22