module.exports.models.migrate に、safe, alter, drop いずれかを指定しないと、処理がバックグラウンドで止まり、起動できない。
Sails config の書き方
把握するのに時間がかかったのでメモ。
./config/* の中身が設定としてロードされる。
記載されているルールとしては、例えば log.coffee (log.js) の場合は、
module.exports.log = { hoge: "aaaaa" }
module.exports.log までをドットでアクセスして、ファイル名とそろえている。
だがファイル名は、実際は何でもよく、
module.exports の中に入っている連想配列が、設定値となる。
config/env/* の中に入っているファイルは、config 直下にあるファイルの後にロードされ、
NODE_ENV の値に対応する ファイルだけが読み込まれる。
問題点
config/env/production.coffee などで、port を上書きしても、反映されなかった。
GridViewのCell などのサイズを比率で指定する
GridView は、横幅が自動計算されるため、比率を合わせるには、設定時に計算する必要がある。
FrameLayout を入れていた場合は、以下のように onMeasure を オーバーライドし、height を再計算する。
xml の 属性に、layout_height_ratio="0.8" のように指定すればよい。
xml を編集中にも、プレビューに反映され確認できます。
public class CustomFrameLayout extends FrameLayout { public CustomFrameLayout(Context context) { this(context, null); } public CustomFrameLayout (Context context, AttributeSet attrs) { this(context, attrs, 0); } public CustomFrameLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); _ratio = attrs.getAttributeFloatValue (null, "layout_heightRatio", 1.0f); } @Override public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { final int width = MeasureSpec.getSize (widthMeasureSpec); final int widthMode = MeasureSpec.getMode(widthMeasureSpec); final int height = (int)(width * _ratio); final int hSpec = MeasureSpec.makeMeasureSpec (height, widthMode); super.onMeasure(widthMeasureSpec, hSpec); } final float _ratio; }
android で view のサイズを取得する
void checkSize (View view) { final Point size = getWindowSize(); // window のサイズを 通知する view.measure (size.x, size.y); // サイズ取得! final int w = view.getMeasuredWidth(); final int h = view.getMeasuredHeight(); } Point getWindowSize () { final WindowManager wm = getWindowManager(); final Display disp = wm.getDefaultDisplay(); final Point size = new Point(); disp.getSize(size); return size; }
Rails で Base64 エンコードされたデータを Carrierwave で保存する
class Api::FilesController < Api::ApplicationController def create # file = params[:data] data_str = params[:data_str] file = File.new # file.data = data file.data_str = data_str end end
class File < ActiveRecord::Base mount_uploader :data, FileDataUploader def data_str= v f = Tempfile.open "temp", encoding: 'ascii-8bit' f.write Base64.decode64(v) self.data = f end end
さらに良い方法はこちら
Rails で Base64 エンコードされた文字を Carrierwave で保存する最も良い方法 - unching-starのブログ
Cloudn の Object Strage を PHP で S3 の代わりに使用する
composer で S3 の ライブラリを取得する
$ curl -sS https://getcomposer.org/installer | php
$ vi composer.json
{ "require": { "aws/aws-sdk-php": "*" } }
$ php composer.phar install
利用する
<?php require_once (dirname(__FILE__) . '/../vendor/autoload.php'); use Aws\S3\S3Client; use Aws\S3\Exception\S3Exception; define ('AWS_ENDPOINT', 'https://str.cloudn-service.com'); define ('AWS_ACCESS_KEY_ID', ' ... '); define ('AWS_SECRET_ACCESS_KEY', ' ... '); function upload_s3 ($s3, $bucket, $key, $file_path) { $res = fopen ($file_path, 'r'); $finfo = finfo_open (FILEINFO_MIME_TYPE); $mime = finfo_file ($finfo, $file_path); finfo_close ($finfo); $meta = array ('Metadata' => array('ContentType' => $mime)); $s3->upload ($bucket, $key, $res, 'public-read', array('params' => $meta)); } function main () { ... $s3 = S3Client::factory (array( 'key' => AWS_ACCESS_KEY_ID, 'secret' => AWS_SECRET_ACCESS_KEY, 'base_url' => AWS_ENDPOINT, )); upload_s3 ($s3, $bucket, $key, $file_path); }
inputAccessoryView が iPhone6 で キーボードにめり込む
Storyboard や、 xib ファイルから viewController を取得し、view を取り出したものを指定すると、表示が崩れる。
コード上でUIView や UIButton を生成し、inputAccessoryView に渡す必要がある。