森川敬一 CTO ブログ

unimediaでCTOやってます森川敬一です。エンジニアブログ。IoT、ウエアブルとか書いていきます。

iOS ライブラリ管理が超簡単な《CocoaPods》!!

CocoaPodsを使うと
iOS ライブラリ管理が超簡単という事で入れてみます。

1.最初は、gemで入れます。当然、ruby必要です。
MacBook-Pro:~ morikawakeiichi$ sudo gem install cocoapods

Fetching: i18n-0.7.0.gem (100%)
Successfully installed i18n-0.7.0
Fetching: thread_safe-0.3.5.gem (100%)
Successfully installed thread_safe-0.3.5
Fetching: tzinfo-1.2.2.gem (100%)
Successfully installed tzinfo-1.2.2
Fetching: minitest-5.8.1.gem (100%)
Successfully installed minitest-5.8.1
Fetching: activesupport-4.2.4.gem (100%)
Successfully installed activesupport-4.2.4
Fetching: nap-0.8.0.gem (100%)
Successfully installed nap-0.8.0
Fetching: fuzzy_match-2.0.4.gem (100%)
Successfully installed fuzzy_match-2.0.4
Fetching: cocoapods-core-0.38.2.gem (100%)
Successfully installed cocoapods-core-0.38.2
Fetching: claide-0.9.1.gem (100%)
Successfully installed claide-0.9.1
Fetching: colored-1.2.gem (100%)
Successfully installed colored-1.2
Fetching: xcodeproj-0.26.3.gem (100%)
Successfully installed xcodeproj-0.26.3
Fetching: cocoapods-downloader-0.9.3.gem (100%)
Successfully installed cocoapods-downloader-0.9.3
Fetching: cocoapods-plugins-0.4.2.gem (100%)
Successfully installed cocoapods-plugins-0.4.2
Fetching: cocoapods-stats-0.5.3.gem (100%)
Successfully installed cocoapods-stats-0.5.3
Fetching: cocoapods-try-0.4.5.gem (100%)
Successfully installed cocoapods-try-0.4.5
Fetching: netrc-0.7.8.gem (100%)
Successfully installed netrc-0.7.8
Fetching: cocoapods-trunk-0.6.4.gem (100%)
Successfully installed cocoapods-trunk-0.6.4
Fetching: molinillo-0.3.1.gem (100%)
Successfully installed molinillo-0.3.1
Fetching: escape-0.0.4.gem (100%)
Successfully installed escape-0.0.4
Fetching: cocoapods-0.38.2.gem (100%)
Successfully installed cocoapods-0.38.2
Parsing documentation for i18n-0.7.0
Installing ri documentation for i18n-0.7.0
Parsing documentation for thread_safe-0.3.5
Installing ri documentation for thread_safe-0.3.5
Parsing documentation for tzinfo-1.2.2
Installing ri documentation for tzinfo-1.2.2
Parsing documentation for minitest-5.8.1
Installing ri documentation for minitest-5.8.1
Parsing documentation for activesupport-4.2.4
unable to convert "\x84" from ASCII-8BIT to UTF-8 for lib/active_support/values/unicode_tables.dat, skipping
Installing ri documentation for activesupport-4.2.4
Parsing documentation for nap-0.8.0
Installing ri documentation for nap-0.8.0
Parsing documentation for fuzzy_match-2.0.4
Installing ri documentation for fuzzy_match-2.0.4
Parsing documentation for cocoapods-core-0.38.2
Installing ri documentation for cocoapods-core-0.38.2
Parsing documentation for claide-0.9.1
Installing ri documentation for claide-0.9.1
Parsing documentation for colored-1.2
Installing ri documentation for colored-1.2
Parsing documentation for xcodeproj-0.26.3
Installing ri documentation for xcodeproj-0.26.3
Parsing documentation for cocoapods-downloader-0.9.3
Installing ri documentation for cocoapods-downloader-0.9.3
Parsing documentation for cocoapods-plugins-0.4.2
Installing ri documentation for cocoapods-plugins-0.4.2
Parsing documentation for cocoapods-stats-0.5.3
Installing ri documentation for cocoapods-stats-0.5.3
Parsing documentation for cocoapods-try-0.4.5
Installing ri documentation for cocoapods-try-0.4.5
Parsing documentation for netrc-0.7.8
Installing ri documentation for netrc-0.7.8
Parsing documentation for cocoapods-trunk-0.6.4
Installing ri documentation for cocoapods-trunk-0.6.4
Parsing documentation for molinillo-0.3.1
Installing ri documentation for molinillo-0.3.1
Parsing documentation for escape-0.0.4
Installing ri documentation for escape-0.0.4
Parsing documentation for cocoapods-0.38.2
Installing ri documentation for cocoapods-0.38.2
20 gems installed
MacBook-Pro:~ morikawakeiichi$

2.次にSETUP
MacBook-Pro:~ morikawakeiichi$ pod setup
Setting up CocoaPods master repo

CocoaPods 0.39.0.beta.4 is available.
To update use: `gem install cocoapods --pre`
[!] This is a test version we'd love you to try.

For more information see http://blog.cocoapods.org
and the CHANGELOG for this version http://git.io/BaH8pQ.

Setup completed
MacBook-Pro:~ morikawakeiichi$

これで完了です。

3.次にライブラリを追加したいxcodeを一旦終了し . xcodeproj のディレクトリにprofileを作成しライブラリを追加します。
 今回は、cookpadさんのログ収集ライブラリ Pureeを使いたく指定しました。

MacBook-Pro: morikawakeiichi$ vi Podfile

pod "Puree"
~
~

4.最後に

MacBook-Pro: morikawakeiichi$ pod install
Updating local specs repositories

CocoaPods 0.39.0.beta.4 is available.
To update use: `gem install cocoapods --pre`
[!] This is a test version we'd love you to try.

For more information see http://blog.cocoapods.org
and the CHANGELOG for this version http://git.io/BaH8pQ.

Analyzing dependencies
Downloading dependencies
Installing CocoaLumberjack (1.9.2)
Installing Puree (1.0.0)
Installing YapDatabase (2.5.4)
Generating Pods project
Integrating client project

[!] Please close any current Xcode sessions and use `hoge.xcworkspace` for this project from now on.
Sending statsMacBook-Pro: morikawakeiichi$

あとは、上記の通り、`hoge.xcworkspace`を使えば良いだけです。
とても簡単。

また、削除は、profileを編集して「pod update」でプロジェクトから削除されまる様です。

モンゴル・UniLabo

f:id:m-kei1:20150415181735j:plain
昨年、モンゴル国立大学とモンゴル科学技術大学でUnimediaのラボを設置しました。

進捗を確認に行ってきました。

f:id:m-kei1:20150415181742j:plain


モンゴル国立大学では、進捗状況をプレゼンしてくれました。
f:id:m-kei1:20150415181737j:plain
f:id:m-kei1:20150415181736j:plain
f:id:m-kei1:20150415181738j:plain
f:id:m-kei1:20150415181743j:plain
f:id:m-kei1:20150415181739j:plain

実際に開発中のデモもしてもらいました。


これは、スマフォの盗難や見失い防止のためにWatchからBlueToothでスマフォ側の音を鳴らすアプリ。
f:id:m-kei1:20150415181744j:plain



googleGlassを使って人の顔を判定し人の情報を表示するアプリ。
f:id:m-kei1:20150415181740j:plain



よく事故が起こる交差点にiBeaconを設置して車で近づくとスマフォでアラートを出すアプリ。
f:id:m-kei1:20150415181741j:plain
f:id:m-kei1:20150415181734j:plain



スマフォのカメラから教室の看板を表示すると講師や授業の情報を出力したり、NFCタグを使って勤怠管理を行うアプリ。
f:id:m-kei1:20150415181748j:plain



CDMAGPS情報を取得しgoogleMapでマッピングするアプリ。自作です。これを使って馬に取り付けたり、子供のカバンにつけたりして位置を把握します。
f:id:m-kei1:20150415181747j:plain


その他、ゴミを見つけてドローンでゴミ箱にすてるアプリ等もあり、
色々と新しいアプリが生まれそうです。

モンゴル国立大学では、来期からうちのUniLaboに出席すれば単位が取れる様になるので更に加速しそうです。

次回は、RaspberryPiとAruduinoを持って来ます!!

iWatchを見て思った未来

ドタバタしてるのとブログネタがあまりないので、
最近周りの人に言ってることを書いてみる。

というのも、先日のiWatch Editionを見たときの話です。

http://cdn.thefiscaltimes.com/cdn/farfuture/_SppZ_gS4nH-eB5xdCB7zP_A2Q6Pq45hcnWiyWcaj3s/mtime:1425925460/sites/default/files/media/apple-event-apple-watch-edition-5597.jpg

Apple - Apple Watch - Edition

ネット上では、100万超える値段に批判?高すぎると話題になってましたが、
僕はあれを見てアップルすげーなーって思いました!!

すごいんですよ。アップル。

昔、PCと携帯電話でどちらが勝つみたいな話がありました。

最終的にどーなったかというと携帯電話がスマフォに進化しました。

メインのものをベースにして進化させるパターンが一番しっくりくる。
これはシンプルでPCに携帯機能をつけてもダメで、携帯にPCの機能を付けたって事なんです。

スマートウォッチで考えると、時計に通信機能をつけるのがベストなんです。

ところがAndroidWatchとか見てるとあくまでもスマフォが時計になってる。

これ何が違うかと言うと、いま、腕時計を付けてる人ってオシャレなブランド品を付けてるんです。
今時、時間をみるだけに腕時計を付けてる人はいない。
ダサい格好のスマートウォッチなんか誰も付けたくないんですよ。

ここをアップルはしっかりマーケット把握して出してきたんだと思って感動しました。

きっと5年後くらいには、数十万するローレックスやシャネルとかの高級時計メーカーがスマートウォッチを発売して、皆んな、そんな高級スマートウォッチを付けてると思う。

オシャレな時計に決済機能や交通フェリカやメンバーカードとして機能して、健康データとか色々と使いやすいなら当然買うと思う。

と思った森川でした。

RaspberryPi 作り直し

RaspberryPiってUSBで電源供給してるので、つい抜き差しをやっちゃいます。

それが原因だと思うのですが、RaspberryPiが起動しなくなりました。

シリアル接続で見てみると、fsckで止まってました。
チープな処理マシンで36GのSDカードのfsckは無理っぽいです。

なので、最初から入れ直したのですが、今度はmacでやってみました。

まずは、ディスクユーリティでSDカードを初期化

次にRaspberryPIのサイトからRASPBIANの"download ZIP"でダウンロード

Downloads | Raspberry Pi

sudo diskutil listでSDカードのデバイス名を把握します。

MorikawaKeiichi-no-MacBook-Pro:~ morikawakeiichi$ sudo diskutil list
Password:
/dev/disk0
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *251.0 GB   disk0
   1:                        EFI EFI                     209.7 MB   disk0s1
   2:          Apple_CoreStorage                         250.1 GB   disk0s2
   3:                 Apple_Boot Recovery HD             650.0 MB   disk0s3
/dev/disk1
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:                  Apple_HFS Macintosh HD           *249.8 GB   disk1
                                 Logical Volume on disk0s2
/dev/disk2
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:     FDisk_partition_scheme                        *31.6 GB    disk2
   1:             Windows_FAT_32 boot                    58.7 MB    disk2s1
   2:                      Linux                         3.2 GB     disk2s2
MorikawaKeiichi-no-MacBook-Pro:~ morikawakeiichi$ 

僕のは、disk2s2でした。

あとは、ダウンロードしたRaspberryPIのイメージファイルを書き込みです。
sudo dd bs=1m if=./Downloads/2015-02-16-raspbian-wheezy.img of=/dev/disk2
20分くらいかかりました。

2度間違えました。
1度目は、ダウンロードした後にzipを解凍せずにそのまま書き込みました・・
でかいのでwget取得したら拡張子が付いてなかったので・・

2度名は、デバイス名を/dev/disk2s2としてたら、認識されなかった
/dev/disk2にしたら大丈夫でした。

次にmacにドライバーをinstall
ここからmac用を入れました。
http://www.prolific.com.tw/US/ShowProduct.aspx?p_id=229&pcid=41
ここのページに書かれてる様にドライバーを入れる前に設定を変更

1. Run "System Preferences" in Mac OS X and click "Security & Privacy" settings.
2. Set Allow apps downloaded from to "Anywhere" (as shown below).

最後は、そのSDカードをRaspberryPIを指して起動させます。
そしてmacのターミナルから

screen /dev/tty.usbserial 115200

でつなげます!

無事復活。

mysqlの断片化対策

大量のデータの再作成処理を行う様な場合には、mysqlのtableやindexが断片化されて
パフォーマンス劣化が起きます。

mysqlの断片化された時には、

ALTER TABLE tbl1 ENGINE InnoDB;

で解消される。

ちなみに断片化されたかどうかは、

mysql> show table status like 'tbl1';
Rows | Avg_row_length | Data_length
37158577 | 4831 | 179544539136

1 row in set (0.04 sec)

mysql>

37158577x4831
(Rows) x Avg_row_length
=179,544,539,136

とData_lengthを比較する。

179,544,539,136=179,513,085,487
ほぼ一緒なので断片化が解消された。

言語ランキング

ちょっと調べてたら見つけた。


The RedMonk Programming Language Rankings: January 2015 – tecosystems

1 JavaScript
2 Java
3 PHP
4 Python
5 C#
5 C++
5 Ruby
8 CSS
9 C
10 Objective-C
11 Perl
11 Shell
13 R
14 Scala
15 Haskell
16 Matlab
17 Go
17 Visual Basic
19 Clojure
19 Groovy

githubに登録されてるソースで言語ランキングをつけてる様です。
Javaってやっぱり強いんですね。

node.jsでインターネットにストリーミング配信

先日書いたRaspberryカメラストリーミングをインターネットに公開してみたいなぁと思いました。


RaspberryPi B+でカメラモジュール使ってnode.jsとsocket.ioでストリーミング配信してみる - 森川敬一 CTO ブログ

ローカルマシンなので簡単にグローバルに公開できません。

そこで公開サーバーを1台用意して、そことSocket.IOで中継してみました。

cliet.js

これを起動時に動かしてカメラ画像を公開サーバー(hogehoge)に転送します。

var express = require('express');
var app = express();
var fs = require('fs');
var path = require('path');

var spawn = require('child_process').spawn;
var proc;

var dateformat = require("dateformat");

app.use('/', express.static(path.join(__dirname, 'stream')));

var client = require('socket.io-client');
var socket = client.connect('http://hogehoge:3001');
socket.on('connect', function() {
	console.log('Connection - ');

	var args = ["-bm", "-w", "320", "-h", "240", "-o", __dirname + "/stream/image_stream.jpg", "-t", "999999999", "-tl", "500", "--nopreview"];
	proc = spawn('raspistill', args);
	console.log('Watching for changes...');

	fs.watchFile(__dirname+'/stream/image_stream.jpg', function(current, previous) {
		fs.readFile(__dirname+'/stream/image_stream.jpg', function(err, buf){
			socket.emit('liveStream', { image: true, buffer: buf, time:dateformat(new Date(), "yyyy/mm/dd HH:MM:ss") });
			console.log('emmit liveStewam 2 server');
		});
	})

});

サーバー側は、画像を受け取ってファイルに保管します。
同時に二つsocket.ioを使えれば、受け取りながら、配信も出来るので、
以前の配信の部分もくっつけてます。

////////////////////////////////////////////
http_rasp.listen(3001, function() {
	console.log('listening on *:3001');
});

io_rasp.on('connection', function(socket) {
	sockets[socket.id] = socket;
	console.log("Total clients connected[rasp] : ", Object.keys(sockets).length);

	socket.on('liveStream', function(data) {
		console.log("receive liveStream[rasp] : ");
		fs.writeFile(__dirname+'/stream/image_stream.jpg', data.buffer);
	});

	socket.on('disconnect', function() {
		delete sockets[socket.id];
	});
});

以前は、窓際だったんですが、席替えしたので、何映せてませんが、夜になると暗くなると思います(w
the view from my office

最後にソースをgithubにあげときました。

k1morikawa/RaspberryPI_LiveStreaming_2 · GitHub