neo4jが起動しない時

/etc/init.d/neo4j-service startとかしたら

cat: /etc/neo4j/data/neo4j-service.pid: No such file or directory
process []... waiting for server to be ready. Failed to start within 120seconds
.
Neo4j Server may have failed to start, please check the logs.
rm: cannot remove `/etc/neo4j/data/neo4j-service.pid': No such file or
directory

みたいな感じで
neo4j-service.pidがないよ!とかって怒られたら
まず、neo4jのプロセスが生きてないか確認 死んでるのに怒られてたら
$NEO4J_HOME/data/graph.db/schema/label/lucene/write.lock とかあるか確認
あれば削除しないと起動時に起動中だと誤認識して終了しようとしてコケます

Unity でiOS向けビルドをする際にLinkerエラー

UnityでOpenCVを使ってiOS向けにアプリを書いているのですが、
エラーでハマったので備忘録

Apple Mach-O Linker Error:
Undefined symbols for architecture armv7:
  "_Init", referenced from:
      RegisterMonoModules() in RegisterMonoModules.o

のようなエラーが発生した場合
iOSProject/Libraries/RegisterMonoModules.cpp
を確認します

void RegisterMonoModules()
{
    gEnableGyroscope = false;
#if !(TARGET_IPHONE_SIMULATOR)
	mono_aot_only = true;
	mono_ficall_flag = false;
	mono_aot_register_module(mono_aot_module_Assembly_CSharp_info);
	mono_aot_register_module(mono_aot_module_UnityEngine_info);
	mono_aot_register_module(mono_aot_module_mscorlib_info);

	mono_dl_register_symbol("Init", (void*)&Init);
	mono_dl_register_symbol("UpdateTexture", (void*)&UpdateTexture);
	mono_dl_register_symbol("UnityNSObject_RetainObject", (void*)&UnityNSObject_RetainObject);
	mono_dl_register_symbol("UnityNSObject_ReleaseObject", (void*)&UnityNSObject_ReleaseObject);
	mono_dl_register_symbol("UnityNSError_Code", (void*)&UnityNSError_Code);
	mono_dl_register_symbol("UnityNSError_Description", (void*)&UnityNSError_Description);
	mono_dl_register_symbol("UnityNSError_Reason", (void*)&UnityNSError_Reason);
	mono_dl_register_symbol("UnityNSNotification_Name", (void*)&UnityNSNotification_Name);
#endif // !(TARGET_IPHONE_SIMULATOR)
}

ここの mono_dl_register_symbol("Init", (void*)&Init);
という行がイケないようです。
事実.csなファイルで以下のように行っていました。
このInitの実態はありません。

	[DllImport ("__Internal")]
	private static extern void Init();

cppから該当のexternの行を削除した後
UnityのBuild SettingsからBuild and Runを実行しプロジェクトごとReplaceしたら正常にビルドができました。
Replaceしなくてもいいかもしれません。

SoapUI がMarvericksで正常に動かない

SoapUIというRESTとかSOAPのテストを行えるツールがあるのですが
http://www.soapui.org/

少し操作をすると、すぐに応答無しになってしまい困っていました。
Forumに解決策があったのでメモ書きしておきます。

High CPU Load on OSX Mavericks when running mock service
http://forum.soapui.org/viewtopic.php?f=13&t=22377


/Applications/SoapUI-4.6.3.app/Contents/vmoptions.txt
の最下部に以下を追加

-Dsoapui.jxbrowser.disable=true

これだけで、さくさくRequestの詳細などを開けるようになりました!

とりあえずSquare


OpenCVには大量のサンプルがあります。

今回は、SquareをUnityで動かしてみました。

若干手を入れていて、
各関数はMatではなくIplimageで受け取るように
そのためmixChannelsが動かない?ので処理を省いています。
また、polylinesが動かない?ので検出した点が4つであればcvLineで囲むようにしました。

https://gist.github.com/lis2501/8231948

UnityとiPhoneとOpenCVでなにかやる

iPhoneアプリ作ってみたい
Unityってどうなんだろ
ARっていったらOpneCVだよね

っていう短絡的な考えのもと
Unity@iPhoneOpenCVを使えないかここ数日取り組んでいます。

結果的に言うと
Unity@iPhoneOpenCVを使うならばNativePluginでやるしかないっぽいです。

UnityでOpenCVを使うのであればOpenCVSharpっていうOpneCVのC#用ラッパーを使うのが一般的みたいなんですけど、
dylibを認識してくれないorビルドが通らなくなるってことで

とりあえずNativePluginでやってくことにしました。

以下のページを参照しました。
UnityでOpenCVを使う(iOS編)



とりあえずUnityで新規プロジェクト作成からのメモ書きを以下にしておきます。

Unityで新規プロジェクト作成
Planeを追加

Game Object -> Create Other -> Plane

Directional Lightを追加

Game Object -> Create Other -> Directional Light

Planeにスクリプトを追加
    1. 画面左の一覧からPlaneを選択
    2. 画面右のInspectorでAdd Component
    3. New Scriptを選択 imageProcessingとか名前をつけておきます。

なおこの時Planeの位置を(上部Transform内Position)を0 0 0ぐらいにしておきます。
カメラは右下のプレビューでPlane全体が映る程度にしたほうがいいです。
あと今回はiPhone5で行いました。Xを90度回転とかさせたほうがいいかもです。
とりあえずiPhoneの画面に映るものというのはCameraの設定で弄れるとおぼえておいてください
スクリプトで処理をした結果をPlaneのテクスチャに反映させ、それをカメラで映し出しています。

スクリプトの編集

AssetsフォルダにimageProcessing.csが表示されていると思います
それをダブルクリックするとMonoDevelopperが表示されるので
下記に編集してください

using UnityEngine;
using System.Collections;
using System.Runtime.InteropServices;

public class imageProcessing : MonoBehaviour {
	
	[DllImport ("__Internal")]
	private static extern void UpdateTexture(System.IntPtr colors, int width, int height);
	WebCamTexture webcamTexture;
	Texture2D texture = null;
	
	// Use this for initialization
	void Start () {
		WebCamDevice[] devices = WebCamTexture.devices;
		if (devices.Length > 0) {
			webcamTexture = new WebCamTexture(devices[0].name ,320, 240, 10);
			webcamTexture.Play();
		} 

	}
	
	// Update is called once per frame
	void OnGUI() {
		Color32[] pixels = webcamTexture.GetPixels32();
		GCHandle pixelsHandle = GCHandle.Alloc(pixels, GCHandleType.Pinned);
		UpdateTexture(pixelsHandle.AddrOfPinnedObject(), webcamTexture.width, webcamTexture.height);
		if (texture) Destroy(texture);
		texture = new Texture2D(webcamTexture.width, webcamTexture.height);
		texture.SetPixels32(pixels);
		texture.Apply();

		pixelsHandle.Free();
		renderer.material.mainTexture = texture;
	}
}

iPhone5 でいうとdevices[0]が背面のカメラ devices[1]が全面のカメラになります
print(devices[i].name)とかして確認して下さい
解像度は320x240で10FPSをターゲットとして要求します。

NativePluginの作成

Assetsの中にPlugins/iOSフォルダを作成します(ここにおいておくとXcode起動時に自動で入れてくれるらしいです。)
その中にPlaneに設定したスクリプト名と同名のファイルを作成します。
今回はimageProcessing.csなのでimageProcessing.cppになります。
中身は以下のようにしてください

#ifdef __cplusplus
#import <opencv2/opencv.hpp>
#endif

extern "C" {
  void UpdateTexture(char* data, int width, int height);
} 

void UpdateTexture(char* data, int width, int height)
{
    IplImage* p = cvCreateImageHeader(cvSize(width, height), IPL_DEPTH_8U, 4);
    cvSetData(p, data, p->widthStep);
    IplImage* g = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 1);
    cvCvtColor(p, g, CV_RGBA2GRAY);
    cvCanny(g, g, 50.0, 200.0);
    cvCvtColor(g, p, CV_GRAY2RGBA);
    cvReleaseImageHeader(&p);
    cvReleaseImage(&g);
}

ここまで設定ができればあとはビルドです。

iOSへのビルド設定をする
    1. File->Build Settingsを選択
    2. 上部のAdd Currentで今のSceneを追加します
    3. 画面下のPlatformでiOSを選択します。
    4. この時Development Buildにチェックを入れてください
iOSへBuildする

Build and RunをクリックするとXcodeが立ち上がります。
このままでは動かないので更に設定が必要です
ビルドにコケても驚かないでください。

Frameworkを追加する

Unity-iPhone.xcodeprojをクリックBuild Phasesで Link Binary with Libraries
opencv2.framework(作成方法は参考URLへ)
libc++.dylibを追加

これでビルドができます。
あと dSYMの作成に時間かかりまくるので
Build Settings Debug Information FormatでDWARFだけにしておくと早いです。

まとめ

Class 名
Planeに追加したスクリプトのファイル名
Plugins/iOS内においた.cppファイルのファイル名
はいずれも同じにしてください
大文字小文字もあります。

Windows7でブート時のスタートアップ修復を無効にする

必要なときにだけディスプレイやマウスは接続する形でサーバーとして利用しているWin7機を再起動かけたら立ち上がらなくなって焦ったのでメモ

バイスインストールに失敗したりしていると次回起動時にデフォルトでスタートアップ修復が選択されてしまうようなので、それを無効化します。

参考:Windows7起動時のスタートアップ修復を無効にするには

コマンドプロンプトを「管理者として実行」で実行

  bcdedit /set {default} recoveryenabled No
  bcdedit /set {default} bootstatuspolicy ignoreallfailures

その後 bcdeditだけで起動しオプションに適用されていればOK

とりあえず様子を見てみます。

ssh-config がよくわからない

複数のgithubアカウントを使う必要が出てきて
レポジトリごとに使い分けたいと考えました。

たとえばこんなふうなふうに ~/.ssh/configに書きます

Host A.github
User git
HostName github.com
IdentityFile ~/.ssh/A_id_rsa

Host B.github
User git
HostName github.com
IdentityFile ~/.ssh/B_id_rsa

~/.ssh/にはA_id_rsaとB_id_rsaとconfigしかありません
githubにはそれぞれ公開鍵を登録してあります。

その後 git remote set-url origin ssh://A.github/A/hogehoge.gitとかすればうまくいくかなーとか思ったんですけどBとして登録されている公開鍵だからだめだよ!と怒れれてしまいました。

この時
ssh -T A.github としても ssh -T B.githubとしても ssh -T github.comとしても
どちらも
Hi B! You've successfully authenticated, but GitHub does not provide shell access.

と出てきてしまいます。

もちろん鍵はどちらも異なっています。
というか ssh-configってHostではなくHostName単位で管理してたりするんでしょうか

詳しく処理を追って見る

ssh -v オプションを教えてもらったので、試してみました。
うーん
/Users/---/.ssh/id_rsaはないんですけどね・・・

➜ .ssh ssh -v -T A.github
OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011
debug1: Reading configuration data /Users/---/.ssh/config
debug1: /Users/---/.ssh/config line 6: Applying options for A.github
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug1: /etc/ssh_config line 102: Applying options for *
debug1: Connecting to github.com [192.30.252.128] port 22.
debug1: Connection established.
debug1: identity file /Users/---/.ssh/A_id_rsa type -1
debug1: identity file /Users/---/.ssh/A_id_rsa-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.2
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.9p1 Debian-5ubuntu1+github5
debug1: match: OpenSSH_5.9p1 Debian-5ubuntu1+github5 pat OpenSSH_5*
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Server host key: RSA xx:xx:xx:xx:.......
debug1: Host 'github.com' is known and matches the RSA host key.
debug1: Found key in /Users/---/.ssh/known_hosts:1
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /Users/---/.ssh/id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 279
debug1: Authentication succeeded (publickey).
Authenticated to github.com ([192.30.252.128]:22).
debug1: channel 0: new [client-session]
debug1: Requesting no-more-sessions@openssh.com
debug1: Entering interactive session.
debug1: Remote: Forced command.
debug1: Remote: Port forwarding disabled.
debug1: Remote: X11 forwarding disabled.
debug1: Remote: Agent forwarding disabled.
debug1: Remote: Pty allocation disabled.
debug1: Remote: Forced command.
debug1: Remote: Port forwarding disabled.
debug1: Remote: X11 forwarding disabled.
debug1: Remote: Agent forwarding disabled.
debug1: Remote: Pty allocation disabled.
debug1: Sending environment.
debug1: Sending env LANG = ja_JP.UTF-8
debug1: Sending env LC_CTYPE = ja_JP.UTF-8
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug1: client_input_channel_req: channel 0 rtype eow@openssh.com reply 0
Hi B! You've successfully authenticated, but GitHub does not provide shell access.
debug1: channel 0: free: client-session, nchannels 1
Transferred: sent 3136, received 2920 bytes, in 0.4 seconds
Bytes per second: sent 7570.4, received 7049.0
debug1: Exit status 1

解決

ssh-agentが何故か保持してました。

ssh-add -lで確認
ssh-add -Dで全削除
の上再度試すと正常に動作しました。

ちなみに

unset SSH_AUTH_SOCK とかしておけばssh-agentを殺せるようです。