2018年 7月 の投稿一覧

Cordova – Command failed with exit code 1 Error output: Could not merge source set folders:

Cordova buildがエラーになりました。


Error: /Users/dp/Dropbox/cordova/ethereumApp/platforms/android/gradlew: Command failed with exit code 1 Error output:
注意:一部の入力ファイルは非推奨のAPIを使用またはオーバーライドしています。
注意:詳細は、-Xlint:deprecationオプションを指定して再コンパイルしてください。
Could not merge source set folders:
[www/node_modules/semver/semver.browser.js] /Users/dp/Dropbox/cordova/ethereumApp/platforms/android/assets/www/node_modules/semver/semver.browser.js    [www/node_modules/semver/semver.browser.js] /Users/dp/Dropbox/cordova/ethereumApp/platforms/android/assets/www/node_modules/semver/semver.browser.js.gz: Error: Duplicate resources

semver?なんだこれ?


mac:dp dp$ npm ls --depth=2
net.dp.wallet@1.0.0 /Users/dp/Dropbox/cordova/ethereumApp
├─┬ cordova-android@6.2.3
│ ├─┬ cordova-common@2.0.2
│ │ ├── ansi@0.3.1
│ │ ├── bplist-parser@0.1.1
│ │ ├── cordova-registry-mapper@1.1.15
│ │ ├── elementtree@0.1.6 deduped
│ │ ├── glob@5.0.15
│ │ ├── minimatch@3.0.3
│ │ ├── osenv@0.1.4
│ │ ├── plist@1.2.0
│ │ ├── q@1.5.0 deduped
│ │ ├── semver@5.3.0
│ │ ├── shelljs@0.5.3 deduped
│ │ ├── underscore@1.8.3
│ │ └── unorm@1.4.1
│ ├─┬ elementtree@0.1.6
│ │ └── sax@0.3.5
│ ├─┬ nopt@3.0.6
│ │ └── abbrev@1.1.0
│ ├── properties-parser@0.2.3
│ ├── q@1.5.0
│ └── shelljs@0.5.3
└── cordova-plugin-whitelist@1.3.3

Cordovaのプロジェクト直下で依存を見てみると「cordova-android」の依存に「semver@5.3.0」がいました。

次にwwwに移動して依存をチェック


├─┬ gulp@3.9.1
│ ├── archy@1.0.0
│ ├─┬ chalk@1.1.3
│ │ ├── ansi-styles@2.2.1
つづく
│ ├── pretty-hrtime@1.0.3
│ ├── semver@4.3.6

いました、gulpの依存になっています。
gulp??devDependenciesなんだけどな。。。
bashのヒストリーを確認しましたが
npm installの際に、「–production」を忘れてdevDependenciesも入ってしまったようです。
node_modulesを一旦削除して、「npm install –production」でgulpがなくなったら
「cordova run android」も成功しました。

GulpでSass構文エラーで止まるのを防ぐ

https://github.com/dlmanning/gulp-sass/issues/44
を参考にonとerrorLogToConsoleを追加


gulp.task('sass', function(){
    gulp.src('./src/scss/*.scss')
    .pipe(sass({errLogToConsole: true}))
    .on('error', catchErr)
    .pipe(sass({style : 'expanded'}))
    .pipe(gulp.dest('./dist/css'));
});
function catchErr(e) {
    console.log(e);
    this.emit('end');
}

errLogToConsoleだけでもいいのかと思いましたがそれだと止まります。

Gulpとか設定面倒だよと思って http-server -c-1 と sass –watch scss:dist/css をターミナルで別々にやってた頃が恥ずかしい。

acquireLatestImageから取得するスクショ画像に黒い枠?

getPixelStrideとgetRowStrideを取得して、Bitmap.createBitmapしてたんだけど
自分の端末だと8px画像サイズが大きくなり、FullHDのはずだけど1088pxになって
余分の8pxは黒になってしまった。

他の端末だと、もっと黒枠が広くなることもあればない時もある。。
調べて見たらこれ?

Why does the output bitmap (currently I don’t do anything with it, because it’s still POC) have black margins in it? What’s wrong with the code in this matter?

You have black margins around your screenshot because you are not using realSize of the window you’re in. To solve this:

https://stackoverflow.com/questions/43705756/how-to-properly-take-a-screenshot-globally/43844977

https://github.com/AndroidDeveloperLB/ScreenshotSample

ImageReader.newInstanceに渡すサイズの設定が違ったみたい。
そして、copyPixelsFromBufferでgetRealSizeしたサイズのBitmapに流し込んでみたら
黒枠?がなくなってサイズは1080になった。


windowSize  = new Point();
WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
windowManager.getDefaultDisplay().getRealSize(windowSize);
width   = windowSize.x;
height  = windowSize.y;
imageReader = ImageReader.newInstance(width, height, PixelFormat.RGBA_8888, 10 );
virtualDisplay  = mediaProjection.createVirtualDisplay("Capturing Display", width, height, density, VIRTUAL_DISPLAY_FLAGS, imageReader.getSurface(), null, null);


int pixelStride = planes[ 0 ].getPixelStride(), rowStride = planes[ 0 ].getRowStride();
int rowPadding = rowStride - pixelStride * width;
bitmap = Bitmap.createBitmap( width + rowPadding / pixelStride, height, Bitmap.Config.ARGB_8888 );
bitmap.copyPixelsFromBuffer( buffer );
croppedBitmap = Bitmap.createBitmap( bitmap, 0, 0, windowSize.x, windowSize.y );

Muninでnginx_requestとnginx_statusがグラフに表示されない( ConohaVPS )

ConohaVPSで動かしているPythonアプリサーバー( Flask + OpenCV + nginx )を監視しようとおもい、久しぶりにMuninをインストールしたけどnginx_requestとnginx_statusがグラフに表示されない。

NginxのTest


curl http://localhost/nginx_status

403 Forbiddenになっていた。


location /nginx_status {
       stub_status on;
       access_log off;
       allow 127.0.0.1;
       deny all;
}

一見問題なさそうだけど
localhostにpingしたら「localhost6.localdomain6」になるのか。。


root@ocv-py3-ub:ping localhost
PING localhost(localhost6.localdomain6 (::1)) 56 data bytes
64 bytes from localhost6.localdomain6 (::1): icmp_seq=1 ttl=64 time=0.024 ms
^C
--- localhost ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms

「::1」をallowしたら表示された。


location /nginx_status {
       stub_status on;
       access_log off;
       allow 127.0.0.1;
       allow ::1;
       deny all;
}


root@ocv-py3-ub:~# curl http://localhost/nginx_status
Active connections: 1
server accepts handled requests
 106160 106160 108272
Reading: 0 Writing: 1 Waiting: 0

次にMuninのNginxプラグインをテスト


root@ocv-py3-ub:~#/usr/sbin/munin-run nginx_request
Use of uninitialized value $LWP::VERSION in sprintf at /etc/munin/plugins/nginx_request line 108.
Can't locate object method "new" via package "LWP::UserAgent" at /etc/munin/plugins/nginx_request line 108.
root@ocv-py3-ub:~#

「LWP::UserAgent」がない。。


root@ocv-py3-ub:~#sudo apt install libwww-perl

プラグインも動くようになった。


root@ocv-py3-ub:~#/usr/sbin/munin-run nginx_request
request.value 108282

よく使うComposerライブラリ

短いハッシュを生成するライブラリJavaなどもある。
ShortHash
https://github.com/ivanakimov/hashids.php
Install
composer require hashids/hashids

ランダム値の生成
Random
https://github.com/antonioribeiro/random
Install
composer require pragmarx/random

バリデーション
Validetion
https://github.com/Respect/Validation
Install
composer require respect/validation

LaravelのORM
Eloquent ORM
https://github.com/illuminate/database
Install
illuminate/database

ルーター
https://github.com/nikic/FastRoute
Install
composer require nikic/fast-route

キャッシュ
https://github.com/tedious/stash
Install
composer require tedivm/stash
Document
https://github.com/tedious/stash