Owncloud VS Pydio
以前「Pydioを選ぶぞ!」って書いたけど、Pydioのアンドロイドクライアントの日本語未対応っぷりに辟易した。なのでOwncloudに切替中。
Laravelでファイルを生成せずにファイルダウンロード
Laravelでファイルを生成せずにファイルダウンロードしたときのメモ
$stream = fopen('php://temp', 'w'); foreach (Title::all() as $title) { fputcsv($stream, $title->toArray()); } rewind($stream); $csv = mb_convert_encoding(str_replace(PHP_EOL, "\r\n", stream_get_contents($stream)), 'SJIS', 'UTF-8'); $headers = array( 'Content-Type' => 'text/csv', 'Content-Disposition' => 'attachment; filename="' . $filename . '"' ); return Response::make($csv, 200, $headers);
Laravelでファイルダウンロード1
Laravelでファイルをダウンロードしたときのメモ。
public function export() { $tables = Table::all(); $filename = 'downloadfile.csv'; $handle = fopen($filename, 'w+'); fputcsv($handle, array('created at')); foreach ($tables as $row) { fputcsv($handle, array($row->created_at)); } fclose($handle); $headers = ['Content-Type' => 'text/csv']; return Response::download($filename, $filename $headers);
NetBeansのPSRでエラー
NetBeansでLaravelのソースを書いていたら、Lalasniffの記述チェックで
The closing brace for the class must go on the next line after the body
というメッセージが出てしまった。
これは閉じカッコ前に空行があるので間違っている。
<?php class User extends \Eloquent { public static $rules = []; protected $guarded = ['id']; 【ここに空行がある】 }
NetBeansの「ツール」⇒「オプション」⇒「エディタ」⇒「空行」⇒「フィールドの後」と「クラス終了の前」を0にして自動整形すれば、エラーは消える。
phpDocumentorをインストールする
phpDocumentorをインストールするコマンドは以下の通り。
pear channel-discover pear.phpdoc.org pear install phpdoc/phpDocumentor
でも、たいてい失敗する。その場合は
pear clear-cache
キャッシュクリアしてもう一度実行する。
ちなみにphpdocコマンドを使う前には、事前にpearコマンドが必要だ。
pear phpdoc run -d app/controllers -t doc/controllers
Python3でキーボードの入力待ち
Python3でキーボードの入力待ちをするにはinput()を使う。
key = input('続けるには y を入力してください。')
lalasniffでスペースの入れ忘れ
lalasniff使っていたら以下のエラーが出た。functionの後にスペースの入れ忘れたのが原因だった。
Expected 1 space after FUNCTION keyword; 0 found
誤:$this->app->share(function($app) {
正:$this->app->share(function ($app) {
Python3で円マーク付きの文字列を扱う
文字列にrをつけるみたい。
folder_path=(r"\\127.0.0.1\xampp")
Laravelでパッケージ用のConfigをコピーする
Laravelでパッケージを使う場合には、Configをコピーしてから使う。オリジナルのConfigはcomposer updateのたびにデフォルトに戻るからだ。
「config:publish ベンダ名/パッケージ名」でConfigがapp/config/packagesにコピーされる。
>php artisan config:publish schickling/backup Configuration published for package: schickling/backup
Windowsでlaravel/installerを使ってみる
一応メモを残すけどlaravel/installerは不便だった。「composer create-project」のほうが便利。
Windowsだと「laravel new」が失敗する。
> composer global require "laravel/installer=~1.1" Changed current directory to C:/Users/futari/AppData/Roaming/Composer ./composer.json has been updated Loading composer repositories with package information Updating dependencies (including require-dev) Nothing to install or update Generating autoload files >laravel new five 'laravel' は、内部コマンドまたは外部コマンド、 操作可能なプログラムまたはバッチ ファイルとして認識されていません。
フルパスを指定しなきゃダメみたい。
C:\Users\futari\AppData\Roaming\Composer\vendor\laravel\installer>php laravel new five Crafting application... Application ready! Build something amazing.
Winscpを使って自動ダウンロード処理を書く
winscp.comをCMDから直接実行する際に/scriptオプションでテキストを指定する。
"C:\Program Files (x86)\WinSCP\winscp.com" /script="myserver.txt"
myserver.txtの中身。
option batch on open admin:password@127.0.0.1 get /tmp/backup.tar close exit
Pythonのsubprocessの標準出力を入手する
Pythonのsubprocessを使って標準出力を入手したい。
import subprocess cmdline = 'echo test' p = subprocess.Popen(cmdline, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE) while True: line = p.stdout.readline() if not line: break print(line.strip())
ところが、この場合「test」ではなく「b'test'」と表示される。
b'test'
デコードすれば結果だけを表示できる。
print(line.strip().decode('ascii'))