2012-04-17
array_multisortで配列の中身でソート
array_multisortが優秀すぎた。
http://jp2.php.net/manual/ja/function.array-multisort.php
<?php $data[] = array('volume' => 67, 'edition' => 2); $data[] = array('volume' => 86, 'edition' => 1); $data[] = array('volume' => 85, 'edition' => 6); $data[] = array('volume' => 98, 'edition' => 2); $data[] = array('volume' => 86, 'edition' => 6); $data[] = array('volume' => 67, 'edition' => 7); // 列方向の配列を得る foreach ($data as $key => $row) { $volume[$key] = $row['volume']; $edition[$key] = $row['edition']; } ?>
データを volume の降順、edition の昇順にソートする。
$data を最後のパラメータとして渡し、同じキーでソートする。
<?php array_multisort($volume, SORT_DESC, $edition, SORT_ASC, $data); ?>
cakePHPでmysqlのCOUNT
cakePHPでmysqlのCOUNT(*)の処理をする際に
下記のように配列が望んでいる形で返ってこない場合の対処
(※cakePHP1.2系)
$f = array("COUNT(`Model`.`field`) as `count_result`,"field_1","field_2");
array(1) {
[0]=>
array(2) {
[0]=>
array(1) {
["count_result"]=>
string(1) "0"
}
["Model"]=>
array(3) {
["field_1"]=>
NULL
["field_2"]=>
NULL
}
}
}
\\cake\libs\model\datasources\dbo_source.php
<?php function fetchResult() { if ($row = mysql_fetch_row($this->results)) { $resultRow = array(); $i = 0; foreach ($row as $index => $field) { list($table, $column) = $this->map[$index]; $resultRow[$table][$column] = $row[$index]; $i++; } return $resultRow; } else { return false; } } ?>
\\cake\libs\model\datasources\dbo_source.php
<?php function fetchResult() { if ($row = mysql_fetch_row($this->results)) { $resultRow = array(); $i = 0; # editer a9b $t_table = 0; foreach ($row as $index => $field) { list($table, $column) = $this->map[$index]; # editer a9b if(empty($table)){ $table = $t_table; }else{ $t_table = $table; } $resultRow[$table][$column] = $row[$index]; $i++; } return $resultRow; } else { return false; } } ?>
また、上記の修正ではフィールド指定の順序を持ってきたいフィールドの後ろに置かないと動きません。
$f = array("field_1","field_2","COUNT(`Model`.`field`) as `count_result`");
array(1) {
[0]=>
array(1) {
["Model"]=>
array(4) {
["field_1"]=>
NULL
["field_2"]=>
NULL
["count_result"]=>
string(1) "0"
}
}
}
1.3系の場合はバーチャルフィールドというものがあるらしいです。
2012-03-16
docomoのデザリングとパケホーダイの料金
apple storeのアプリをベンチするためにGALAXY S II SC-02Cのデザリングで
ipodtouchを繋ごうと思い料金などを調べた時のメモ
(※2011年3月現在の情報なので情報が古い場合は再度お調べください。)
http://www.nttdocomo.co.jp/charge/packet/pake_hodai_f/notice/index.html
※FOMA契約でテザリングをご利用時のパケット通信料金は、FOMAパケット定額サービス(パケ・ホーダイ フラットなど)
をご加入されている場合、「外部機器を接続した通信」の上限金額となります。
詳しくは各料金プラン・定額サービスの上限金額はパケット定額サービスで確認ください。
最大5,460円(税抜5,200円)が「外部機器を接続した通信」になるので最大で8,190円(税抜7,800円)になるようです。
PCも繋ぐことを考えれば手軽に使えるネット環境を2500円くらいで使うか迷うところですね。
また、xiなどは現在割安のようですが、2012年10月からデータ量が7GBを超えた場合、
当月末まで通信速度が送受信時最大128kbpsになるそうなので、そっちも調べてみました。
現在の利用用途は仕事でmobageなどのベンチしているので、一日中通常のデータ通信を行なっていますが、
動画などはほとんどPCで見ているので大容量の通信は発生しません。
毎月の利用量は約10,000,000パケットくらいなので約1Gと考えると、
動画とかを頻繁に見なければ相当ヘビーに使っても7Gまではいかないですね。
(※1パケット=128byte)
キャリアのサイトは探したい情報見つけるのに一苦労しますね。
参考URL
▼デザリング
http://www.nttdocomo.co.jp/service/func_tool/tethering/index.html
▼Xiパケ・ホーダイ フラット
http://www.nttdocomo.co.jp/charge/packet/xi_pake_hodai_f/index.html
▼パケ・ホーダイ フラット
http://www.nttdocomo.co.jp/charge/packet/pake_hodai_f/about/index.html
▼パケホーダイの注意事項
http://www.nttdocomo.co.jp/charge/packet/pake_hodai_f/notice/
2012-03-14
CentOSでvimを7.2系にUPDATE
[server@user]$ cd /usr/local/src
[server@user]$ wget ftp://ftp.vim.org/pub/vim/unix/vim-7.2.tar.bz2
[server@user]$ wget ftp://ftp.vim.org/pub/vim/extra/vim-7.2-extra.tar.gz
[server@user]$ wget ftp://ftp.vim.org/pub/vim/extra/vim-7.2-lang.tar.gz
[server@user]$ tar jxvf vim-7.2.tar.bz2
[server@user]$ tar zxvf vim-7.2-extra.tar.gz
[server@user]$ tar zxvf vim-7.2-lang.tar.gz
[server@user]$ cd vim72
必要なパッチを当てます。※2012/03/14日現在は446個あるようです。
[server@user]$ mkdir patches
[server@user]$ cd patches
[server@user]$ wget ftp://ftp.vim.org/pub/vim/patches/7.2/7.2.001-100.gz
[server@user]$ wget ftp://ftp.vim.org/pub/vim/patches/7.2/7.2.101-200.gz
[server@user]$ wget ftp://ftp.vim.org/pub/vim/patches/7.2/7.2.201-300.gz
[server@user]$ wget ftp://ftp.vim.org/pub/vim/patches/7.2/7.2.301-400.gz
[server@user]$ gunzip 7.2.001-100.gz
[server@user]$ gunzip 7.2.101-200.gz
[server@user]$ gunzip 7.2.201-300.gz
[server@user]$ gunzip 7.2.301-400.gz
[server@user]$ curl -O 'ftp://ftp.vim.org/pub/vim/patches/7.2/7.2.[401-446]'
[server@user]$ cd ..
[server@user]$ cat patches/7.2.* | patch -p0
[server@user]$ ./configure
エラーで止まった。
no terminal library found
checking for tgetent()... configure: error: NOT FOUND!
You need to install a terminal library; for example ncurses.
Or specify the name of the library with --with-tlib.
[server@user]$ cd /usr/local/src
[server@user]$ wget http://ftp.gnu.org/pub/gnu/ncurses/ncurses-5.9.tar.gz
[server@user]$ tar xvzf ncurses-5.9.tar.gz
[server@user]$ cd ncurses-5.9
[server@user]$ ./configure
[server@user]$ make
[server@user]$ make install
もう一度
[server@user]$ ./configure
[server@user]$ make
[server@user]$ make install
ついでに下記のようにしておくと便利かも
.bashrc
参考URL
http://d.hatena.ne.jp/Arko/20100402/1270175973
http://tochiii.blog119.fc2.com/blog-entry-227.html
http://d.hatena.ne.jp/naskin/20100211/1265859796
2012-03-23 こちらの方が楽でした。
http://blog.ville.jp/2011/03/11/536
[server@user]$ yum install mercurial
[server@user]$ cd /usr/local/src
[server@user]$ hg clone https://vim.googlecode.com/hg/ vim
[server@user]$ cd vim
[server@user]$ ./configure --enable-multibyte --enable-xim --enable-fontset --disable-selinux --with-features=huge
make && make install
2012-01-05
githubでwgetできなかったからcurl使った
[server@user]$ wget https://github.com/a9b/hoge/zipball/master
とやってみたらSSL関係のエラーが出たので調べてみると
githubの仕様がちょこちょこ変わっている模様です。
参考URL
http://d.hatena.ne.jp/tmatsuu/20110614/1308010044
wgetの最新版を入れるという選択肢もあるが、面倒なので
[server@user]$ curl -L -o hoge.zip https://github.com/a9b/hoge/zipball/master
curl: (60) SSL certificate problem, verify that the CA cert is OK. Details:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
More details here: http://curl.haxx.se/docs/sslcerts.html
curl performs SSL certificate verification by default, using a "bundle"
of Certificate Authority (CA) public keys (CA certs). The default
bundle is named curl-ca-bundle.crt; you can specify an alternate file
using the --cacert option.
If this HTTPS server uses a certificate signed by a CA represented in
the bundle, the certificate verification probably failed due to a
problem with the certificate (it might be expired, or the name might
not match the domain name in the URL).
If you'd like to turn off curl's verification of the certificate, use
the -k (or --insecure) option.
中間証明がおかしいようなので、警告を無視してみる。
[server@user]$ curl -L -o hoge.zip https://github.com/a9b/hoge/zipball/master --insecure
無事取得できました。
