ros2

Respect/Validation のよくやる設定ミス

Respect/Validationライブラリで数値のチェックを行なっていると、コピペしすぎて0をうまく判定してくれない時がある。

Respect/Validationに「notEmpty」というメソッドがあって
空判定として呼び出していたけど、数値の0はnotEmpty()を通らないので下記のようになってしまう。


$type = 0;

var_dump( Validator::notEmpty()->intVal()->validate( $type ) );
=> False
var_dump( Validator::intVal()->validate( $type ) );
=> True

Cordova ( web3js, infura, ethereumjs-tx.js) でsendSignedTransaction



self.sendTransaction = function( account , toaddress , amountEth ) {
    var   deferred  = $q.defer();
    const amountWei = self.web3.utils.toWei( amountEth , 'ether');

    var tx = {
        from  : account.address,
        to    : toaddress,
        value : amountWei,
    };

    self.web3.eth.estimateGas( tx ).then( ( gasLimit ) => {
        // Gasを前もって仮計算するけど、その瞬間なのでちょっと多めにする。
        tx.gasLimit = self.web3.utils.toHex( gasLimit + 10000 );
        return self.web3.eth.getGasPrice();
    }).then( ( gasPrice ) => {
        // Gasを設定して、nonceを取得(Metamaskでこれが困ったことがあった..)
        tx.gasPrice = self.web3.utils.toHex( gasPrice );
        return self.web3.eth.getTransactionCount( account.address );
    }).then( ( count ) => {
        // 今回は1トランザクションだけど、複数送信の場合は注意
        tx.nonce = count;

        const transaction = new ethereumjs.Tx( tx );
        var privatekey  = account.privateKey;
        // keystoreから復元したら秘密鍵に0xが付いてたけど0xあるとsignで失敗する
        var prefix  = "0x";
        if( privatekey.indexOf( prefix ) === 0 ){
            privatekey = privatekey.slice( prefix.length ) ;
        }
        transaction.sign( ethereumjs.Buffer.Buffer.from( privatekey , 'hex' ) );
        const transactionHex = '0x'+transaction.serialize().toString( 'hex' )
        self.web3.eth.sendSignedTransaction( transactionHex ).once('transactionHash', (hash) => {
                console.log('transaction Hash', 'https://ropsten.etherscan.io/tx/' + hash);
              }).once('receipt', ( receipt ) => {
                console.log('receipt' , receipt );
              })
              .on('confirmation' , (confirmationNumber, receipt) => {
                console.log('confirmation', confirmationNumber, receipt);
              })
              .on('error', console.error );
        });

confirmationをonceにしたから、confirmationずっと流れると思ったけど24で終了した?
解除ってどうやるんだろう、それかonだけにするしかないかな。

OnsenUI2 ons-iconでmd-***してもmaterialデザインのアイコンが表示されない


//出る
<ons-icon icon="md-face"></ons-icon>
//出ない
<ons-icon icon="md-account_circle"></ons-icon>
//出る
<ons-icon icon="md-account-circle"></ons-icon>


勘違いしていました。
こっちだと思っていましたが違いました。
https://material.io/tools/icons/
OnsenUIのマテリアルアイコンはこっちでした。
http://zavoloklom.github.io/material-design-iconic-font/icons.html

と思ってましたが、別のPCでOnsenUIのリファレンス見てたら
やっぱりmaterial.ioへのリンクになってると思って見比べたら

https://ja.onsen.io/v2/api/angular1/ons-icon.html
のMaterial Iconsのリンクは
https://material.io/tools/icons/
だけど
https://onsen.io/v2/api/angular2/ons-icon.html#tutorial
のMaterial Iconsのリンクは
http://zavoloklom.github.io/material-design-iconic-font/icons.html
になってるな、なんだろう。

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

Android adbをWi-Fi接続

ケーブルをつないで、IPアドレスを調べる。


$ adb shell ipconfig
* daemon not running; starting now at tcp:5037
* daemon started successfully
/system/bin/sh: ipconfig: not found
RC211v-mbp:~ yuta$ adb shell ifconfig
lo        Link encap:UNSPEC  
          inet addr:127.0.0.1  Mask:255.0.0.0 
          inet6 addr: ::1/128 Scope: Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:1235 errors:0 dropped:0 overruns:0 frame:0 
          TX packets:1235 errors:0 dropped:0 overruns:0 carrier:0 
          collisions:0 txqueuelen:0 
          RX bytes:111363 TX bytes:111363 

wlan0     Link encap:UNSPEC  
          inet addr:172.16.20.19  Bcast:172.16.255.255  Mask:255.255.0.0 

tcpip <任意のポート>


$ adb tcpip 12345
restarting in TCP mode port: 12345

connect <上記の任意のポート>


$ adb connect 172.16.20.19:12345
connected to 172.16.20.19:12345

USBケーブル、Wifiそれぞれで接続ができている。


$ adb devices
List of devices attached
172.16.20.19:12345  device
P3P7N17500000000    device

cordova-iconコマンドで”throw er; // Unhandled ‘error’ event”

Cordovaでリリースアプリのアイコンを一括登録しようと、npmのcordova-iconを使ったらエラーになった。


yuta$ cordova-icon --config=config.xml --icon=www/icon.png 

Checking Project & Icon

✓ platforms found: android
✓ www/icon.png exists
✓ config.xml exists

Generating Icons for android

events.js:160
throw er; // Unhandled 'error' event
^

Error: spawn convert ENOENT
at exports._errnoException (util.js:1022:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:193:32)
at onErrorNT (internal/child_process.js:359:16)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickCallback (internal/process/next_tick.js:98:9)

image Magickインストールするの忘れてた。。


brew install imagemagick