シリーズものをメモするChrome拡張機能を練習がてら作成
【Pandasでエラー】TypeError: pivot_table() got an unexpected keyword argument 'rows'
CentOS6にnode + mysql
インストール
- Nodeのインストール
$ sudo yum install epel-release $ sudo yum install node npm
- MySQLのインストール
$ sudo yum install mysql-server mysql $ sudo service mysqld start # サービス起動 $ sudo ckconfig mysqld on # 自動起動
$ npm install mysql
MySQL設定
データベース、テーブルを作成し1列挿入しておく
set password = password('パスワード'); create database node use node create user 'node'@'localhost' identified by 'secret'; grant select , insert , update on node.* to node; create table Position ( student_id int auto_increment primary key, latitude Decimal(10,7) , longitude Decimal(10,7) , altitude Decimal(10,7) , message char(100) ) insert into Position (latitude , longitude , message ) values (41.1 , 135.5 , "メッセージ");
コードを作成
/* app.js */ var mysql = require('mysql'); var connection = mysql.createConnection({ host : process.env.DB_HOST || 'localhost' , user : process.env.USER || 'root' , password : process.env.DB_PASS || 'vagrant' , database : process.env.DB_NAME || 'node' }); connection.query('select * from node.Student' , function(err , rows) { if(err != null) { console.log("Error"); } console.log(rows); });
nodeを実行し、接続できることを確認.とりあえずrootでやってしまった。
# node app.js
実行結果
[ { student_id: 1, latitude: 41.1, longitude: 135.5, message: 'a?!a??a?≫a??a?,' } ]
【Mac】qtbindingsをインストール中のエラー Undefined symbols for architecture x86_64:
クロスプラットフォームであり、複数の言語でGUIアプリケーションを開発したいと思い検索をしてみたところ、Qtというフレームワークを使用するとそれが実現できそうであるとわかった
そんなQtをrubyを使ってコーディングを行うためにgemを使って気軽にインストールする
まずはQt自体のインストール(Homebrew使ってます)
これでqt4とcmakeがインストールされる
brew install automoc4
次にRubyで使用するためにqtbindingsを導入
gem install qtbindings
しかしエラー
[ 83%] Building CXX object ruby/qtruby/src/CMakeFiles/qtruby4shared.dir/marshall_types.o Linking CXX shared library libqtruby4shared.dylib Undefined symbols for architecture x86_64: "_rb_float_new", referenced from: unsigned long primitive_to_ruby<float>(float) in handlers.o unsigned long primitive_to_ruby<double>(double) in handlers.o marshall_QListqreal(Marshall*) in handlers.o marshall_QVectorqreal(Marshall*) in handlers.o marshall_QPairqrealQColor(Marshall*) in handlers.o marshall_doubleR(Marshall*) in handlers.o "_rb_funcallv", referenced from: method_missing(int, unsigned long*, unsigned long) in Qt.o class_method_missing(int, unsigned long*, unsigned long) in Qt.o QtRuby::VirtualMethodCall::callMethod() in marshall_types.o funcall2_protect(unsigned long) in marshall_types.o QtRuby::InvokeSlot::invokeSlot() in marshall_types.o "_rb_gc_writebarrier_unprotect", referenced from: rb_obj_wb_unprotect(unsigned long, char const*, int) in marshall_types.o "_rb_str_cat_cstr", referenced from: _rb_str_catf in Qt.o marshall_QString(Marshall*) in handlers.o marshall_QByteArray(Marshall*) in handlers.o "_rb_str_new_static", referenced from: method_missing(int, unsigned long*, unsigned long) in Qt.o class_method_missing(int, unsigned long*, unsigned long) in Qt.o _prettyPrintMethod in Qt.o "_rb_sym2id", referenced from: method_missing(int, unsigned long*, unsigned long) in Qt.o class_method_missing(int, unsigned long*, unsigned long) in Qt.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)
調べてみるとRubyをインストールする際に –enable-shared オプションが必要であるそうだ
rubyのライブラリをダイナミックリンクとして出力してくれるらしく、Qtではそのライブラリを使用しているのだろうか
自分はrbenvを使用しているのでrbenvでRubyをインストールし直すとこうなる(バージョンは2.2.0)
CONFIGURE_OPTS="--enable-shared" rbenv install 2.2.0
もう一度gemコマンドを実行すると無事にqtrubyをインストールできた
Macでgithubから拾ってきたrailsプロジェクトをbundleしたらnokogiriのインストールエラー
nokogiriってなんだろう
学校で進めていたrailsプロジェクトフォルダを家でも使いたいためgithubに上げておいた 家に帰ってgit cloneコマンドでコピーするところまでうまく行ったのだが、bundleするとnokogiriがインストールできず止まる その後ググった内容を見て色々いじってしまいわけがわからなくなった。
そもそもGemfileにnokogiriなんて入れてないがなんらかの別のアプリが利用しているのだろう nokogiriがインストール出来ないのはlibxml2がインストールされていないからだと判明したので最新版のlibxml2を入れた すると↓のエラーが出てくる
[bash] /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby extconf.rb –use-system-libraries –with-xml2-include=/Users/dwt/Library/Homebrew/opt/libxml2/include/libxml2 –with-xml2-lib=/Users/dwt/Library/Homebrew/opt/libxml2/lib –with-xslt-dir=/Users/dwt/Library/Homebrew/opt/libxslt –with-iconv-include=/Users/dwt/Library/Homebrew/opt/libiconv/include/ Building nokogiri using system libraries. libxml2 version 2.9.0 and later is not yet supported, but proceeding anyway. checking for xmlParseDoc() in libxml/parser.h… no checking for xmlParseDoc() in -lxml2… no
checking for xmlParseDoc() in -llibxml2… no
libxml2 is missing. please visit http://nokogiri.org/tutorials/installing_nokogiri.html for help with installing dependencies.
[/bash]
何が何だかと思ったがよく見るとlibxml2のバージョンが新しすぎて対応していないらしい 解決策はないかとググっていると見つけたのがこれ
[bash] brew unlink libxml2 libiconv libxslt sudo xcode-select –install bundle config build.nokogiri –use-system-libraries bundle install [/bash]
インストールしたlibxml2その他2つの参照をはずし 古いlibxml2等をxcode-select –installでインストールできるらしい その後nokogiriのインストールにそのライブラリを使うことを宣言しインストール
無駄に時間を費やした
AndroidでVolleyを使ったシンプルな通信
もうね書くのが面倒だからソースをそのまま書いていく アクセスが無いとこうなるのかな
[java] String url ="http://www.google.co.jp/"; if(mQueue == null) mQueue = Volley.newRequestQueue(getApplicationContext());
StringRequest stringRequest = new StringRequest(Request.Method.GET , url ,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
text1.setText(response.toString());
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
text1.setText("That didn't work... " + error.getMessage());
}
}
);
mQueue.add(stringRequest);
mQueue.start();
[/java]
ネットワーク接続を許可するためAndroidManiphest.xmlをいじる必要が有ることと、結果のテキストはresponse.toString()に格納されることを意識すれば特に問題はない。 さて付加情報を単純にテキストをいじって作ればいいか。別にクラスを用意するか悩むところだ。
IDEに言われるがままにimportしたパッケージたち [java] import com.android.volley.Request; import com.android.volley.RequestQueue; import com.android.volley.Response; import com.android.volley.VolleyError; import com.android.volley.toolbox.StringRequest; import com.android.volley.toolbox.Volley; [/java]
mQueueはメンバ変数として先にRequestQueue型で宣言。 またソース中のテキストビューも同様に宣言し、別のところでfindViewByIdしてますよ。
通信が楽になったしエラーもerror.getMessage()で詳しく教えてくれるから便利だなあ。