2014年2月14日金曜日

CentOS6にFFMpegをyumでインストール

以前yumで入れたときはバージョンが古くて、結局ソースからコンパイルすることになって大変だったんだけど、RPM Fusionから新らし目のものを入れることができたのでメモっときます。

EPELレポジトリの導入
(既に導入済みだったので実際にはしてません。RPM Fusionが依存しているらしい)
# rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-5-4.noarch.rpm

RPM Fusionレポジトリの導入
# yum localinstall --nogpgcheck http://download1.rpmfusion.org/free/el/updates/6/x86_64/rpmfusion-free-release-6-1.noarch.rpm http://download1.rpmfusion.org/nonfree/el/updates/6/x86_64/rpmfusion-nonfree-release-6-1.noarch.rpm

普段のyum利用時に干渉しないよう以下のファイルを開き enable=0 にしておく
/etc/yum.repo.d/rpmfusion-free-updates.repo
/etc/yum.repo.d/rpmfusion-free-updates-testing.repo
/etc/yum.repo.d/rpmfusion-nonfree-updates.repo
/etc/yum.repo.d/rpmfusion-nonfree-updates-testing.repo

FFMpegのインストール
(思わず入れてしまったがffmpeg-develは必要ない)
# yum install --enablerepo=rpmfusion-free-updates install ffmpeg-devel
# yum install --enablerepo=rpmfusion-free-updates install ffmpeg

かなり簡単にインストール可能。

2014年2月6日木曜日

Apache 2.4 の設定ではまる

Apache 2.4(ほんとは2.3から)アクセス許可周り設定が変わっています。

xamppのバージョンを挙げていつもどおりにvirtual hostの設定をしても 404 access forbidden。
つながりません。

こういう理由でした。↓
http://httpd.apache.org/docs/2.4/upgrading.html#run-time

今まで(2.2まで)は、(バーチャルホスト用の)ディレクトリのアクセス許可の設定を以下のように書いてました。

Order allow,deny
Allow from all

2.4からは、以下のようになる。

Require all granted

ググってもなかなか出てこないもんで少しはまりました。
ちゃんと公式ドキュメントに載ってるのにね。

2013年11月11日月曜日

crontabについて

忘れるのでメモ

編集コマンド

crontab [-u ユーザ名] -e


基本書式

* * * * * [実行コマンド]

左から、分 時 日 月 曜日

以下の数値を設定可能
分 0-59
時 0-23
日 1-31
月 1-12
曜日 0-7 (0または7は日曜日)


日時の指定方法各種

各種時間指定方法
・カンマ区切りで列挙
(例)
0,15,30,45 * * * * /hoge/hoge
毎時0分15分30分45分に/hoge/hogeを実行

・ハイフンつなぎで期間を指定
(例)
「0-6」
0 0-6 * * * /hoge/hoge
0時から6時の間0分に/hoge/hogeを実行

・カンマ区切りとハイフンつなぎの両方
(例)
「0,4-6」
0 0,4-6 * * * /hoge/hoge
0時と4時5時6時の0分に/hoge/hogeを実行

・スラッシュで間隔を指定
(例)
*/5 * * * * /hoge/hoge
5分間隔で/hoge/hogeを実行


メール送信先の設定

デフォルトではcrontabのユーザにメールが送信される。

・メールの送信先を代える場合
crontabの先頭に
MAILTO="xxx@xxx.xx.xx"

・メールを受信したくない場合
crontabの先頭に
MAILTO=""
または、
0 * * * * /hoge/hoge >/dev/null 2>&1

・エラーメールを受信したい
0 * * * * /hoge/hoge 1> /dev/null

・エラー以外のメールを受信したい
0 * * * * /hoge/hoge 2> /dev/null


2013年11月1日金曜日

CodeIgniterでGET, POSTの動作を分ける

FuelPHPで最初に便利だったのがhttpdのメソッドでコントローラーのアクションを分岐できるところ。
FuelPHPが動かないサーバの案件でCodeIgniterを使ったときに真っ先に追加したのがこの機能。

function action_xxx (){
function get_xxx (){
function post_xxx (){

と書くだけで、GET, POSTによるアクションの分岐が可能になります。


以下の内容のMy_Controller.phpを作成。

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class MY_Controller extends CI_Controller
{
var $uploaded;
var $view_headers;
var $view_footers;
public function __construct()
{
parent::__construct();
}
// action_, post_, get_への振り分け
public function _remap($method, $params = array())
{
if ($method == '') $method = 'index';
if (strtolower($this->input->server('REQUEST_METHOD')) == 'post')
{
// POST
if (method_exists($this, 'post_'.$method))
{
return call_user_func_array(array($this, 'post_'.$method), $params);
}
elseif (method_exists($this, 'action_'.$method))
{
return call_user_func_array(array($this, 'action_'.$method), $params);
}
else
{
show_404();
}
}
else
{
// GET
if (method_exists($this, 'get_'.$method))
{
return call_user_func_array(array($this, 'get_'.$method), $params);
}
elseif (method_exists($this, 'action_'.$method))
{
return call_user_func_array(array($this, 'action_'.$method), $params);
}
else
{
show_404();
}
}
}
public function view($viewfile, $data)
{
foreach ($this->view_headers AS $header_file)
{
$this->load->view($header_file, $data);
}
$this->load->view($viewfile, $data);
foreach ($this->view_footers AS $footer_file)
{
$this->load->view($footer_file, $data);
}
}
}

require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'AUTH_Controller.php';
?>

2013年10月19日土曜日

CodeIgniterのFormヘルパーのバグ(form_prep())

最近はFuelを使っていたのだがFuelの動作要件を満たさないサーバに当たってしまったので久々にCodeIgniter (2.1.4)を利用。

なんだけども、CodeIgniterのFormヘルパーにバグがあって困った。

Formヘルパーの各種関数を使うとvalueに設定する値は文字参照に変換してくれるのだが、同じname属性のものを2回使うと2回目は文字参照に変換してくれない。

これ↓を参考にform_helper.phpを拡張するMY_form_helper.phpを作成してみた。
https://bitbucket.org/matsuu/codeigniter-reactor/commits/20ca07f73bc3/

先人に感謝
MY_form_helper.php
function form_prep($str = '', $field_name = '')
{
static $prepped_fields = array();
// if the field name is an array we do this recursively
if (is_array($str))
{
foreach ($str as $key => $val)
{
$str[$key] = form_prep($val);
}
return $str;
}
if ($str === '')
{
return '';
}
// we've already prepped a field with this name
// @todo need to figure out a way to namespace this so
// that we know the *exact* field and not just one with
// the same name
if (isset($prepped_fields[$field_name]) && $prepped_fields[$field_name] == $str)
{
return $str;
}
$str = htmlspecialchars($str);
// In case htmlspecialchars misses these.
$str = str_replace(array("'", '"'), array("'", """), $str);
if ($field_name != '')
{
$prepped_fields[$field_name] = $prepped_fields[$field_name] = $str;;
}
return $str;
}
/* End of file MY_form_helper.php */
/* Location: ./application/helper/MY_form_helper.php */

2013年8月1日木曜日

Adobe Readerの旧バージョン

Adobe Readerの旧バージョンがほしい時、Adobeのサイトでダウンロードできる。

http://get.adobe.com/jp/reader/otherversions/

ただし現時点でバージョン9.5以降。

もっと古いのがほしい場合、FTPでダウンロードできる。

ftp://ftp.adobe.com/pub/adobe/reader/

ダウンロードマネージャ版ではなく、完全なインストーラー版をダウンロードしないと古いバージョンはインストールできなさそうなので注意が必要。

oldversion.comとかにもあったんだけど英語版のみで、日本語のPDFファイルでうまく開かないものがあったりとかして日本語バージョンが必要だったんです。上のサイトなら各種言語版があります。

急遽旧バージョンが必要になって探しました。あって助かった。

windowsのコマンドプロンプトを開く

ここに紹介されているコマンドプロンプトの開き方がイイ!
パスを引き継げる。便利!

http://www.lifehacker.jp/2013/03/130320windows_cmd.html

エクスプローラーのアドレスバーに、cmd[Enter]