ドットインストールのNode.js入門の補足

ドットインストールの「Node.js入門」というレッスンでは、「#14 MongoDBに接続してみよう」というのがあるが、これを実施するためには事前にMongoDBのインストールが必要である(当たり前ではあるが)。

レッスンだと以下のようなコマンドを叩いているが、これはあくまでNode.js用のMongoDBドライバ(node-mongodb-native)をインストールしているだけである。

$ npm install mongodb

MongoDB自体のインストールとセットアップは、ドットインストールの「さくらのVPS入門」「#21 MongoDBを導入しよう」というのがあって、これを見れば良い。

奥さんの携帯を機種変更した際のメモ(ソフトバンク)

今月奥さんの携帯を機種変更した際の事をメモしておく。

Wホワイトの解約で少し手間取った。
店頭での説明だとカスタマーサポート【157】に電話すればすぐに解約出来るとの事だったが、自動音声のガイドだとWホワイトには未加入ということで、解約出来なかった。
そこで、157 → 4(各種変更手続き) → 9(その他、ご契約内容に関するお問い合わせ)で、カスタマーサポートの人に聞いてみると、Wホワイトへの変更申請中というステータスとのこと(一ヶ月単位での切り替えのためそうなっているだとか)。
ということで、その場で解約を依頼すると、変更申請のキャンセルという形ですぐに対応してもらえた。

PostgreSQLでtimestamp型のデフォルト値を現在時刻にするには

ドットインストールのPostgreSQL入門を勉強中に気づいた事をメモしておく。

#05 フィールドに制約をつけてみよう」でtimestamp型のデフォルト値を現在時刻にするために以下のように指定していた。

create table posts (
    id serial primary key,
    title varchar(255) not null, 
    body text check(length(body) > 5),
    is_draft boolean default TRUE,
    created timestamp default 'now' ★★★
);


しかし、これだとテーブル作成時の時刻がデフォルト値になってしまう。
データをInsertした際の現在時刻をデフォルト値とする場合には以下のように指定する必要がある。

create table posts (
    id serial primary key,
    title varchar(255) not null, 
    body text check(length(body) > 5),
    is_draft boolean default TRUE,
    created timestamp default CURRENT_TIMESTAMP ★★★
);


【参考記事】

SafariでThree.jsの練習をするために

ドットインストールThree.js入門が公開されたが、このレッスンをSafariで試そうとしたらいきなり躓いた。原因はSafariだとデフォルトでWebGLが有効になっていない事にあった。で、SafariWebGLを有効にする方法は以下。

  1. Safariの「環境設定」-「詳細」で「メニューバーに"開発"メニューを表示」にチェックを入れる
  2. メニューバーの「開発」で「WebGLを有効にする」を選択する

これでSafariでもThree.jsを試すことが出来るようになった。

【参考記事】

List of unit testing frameworks for Java

A programmer-oriented testing framework for Java

A Mocking framework that tastes really good

A JUnit extension to perform unit testing with database-driven programs

A Java logging API by means of a simple facade pattern (DbUnit uses SLF4J for logging purposes.).

A relational database management system written in Java

A YAML parser and emitter for the Java programming language

HUBOTのTips(警告"@http() is going to be deprecated in 3.0.0 use @robot.http()"への対処)

HUBOTに最初から含まれているサンプルのスクリプト(math.coffee、pugme.coffee、youtube.coffee等)を利用すると、以下のような警告が出るケースがある。

Hubot> hubot math me 1 + 2
Hubot> [Mon Jul 15 2013 00:22:55 GMT+0900 (JST)] WARNING @http() is going to be deprecated in 3.0.0 use @robot.http()
3
Hubot> 


警告が出ている理由はResponseクラスのhttpメソッドを利用しているためである(ResponseクラスのhttpメソッドはHUBOTのバージョン3.0.0で廃止予定と言っている)。
実際に警告を出している場所は以下(response.coffee)。

class Response
  ... snip ...
  http: (url) ->
    @robot.logger.warning '@http() is going to be deprecated in 3.0.0 use @robot.http()'
    @robot.http(url)

module.exports = Response


この警告を消すにはResponseクラスのhttpメソッドを利用する変わりに、Robotクラスのhttpメソッドを利用すれば良い。
具体的には以下のようにmath.coffeeを修正する。

module.exports = (robot) ->
  robot.respond /(calc|calculate|convert|math|maths)( me)? (.*)/i, (msg) ->
    # msg.httpの変わりにrobot.httpを使う
    # msg
    robot
      .http('https://www.google.com/ig/calculator')
      .query
        hl: 'en'
        q: msg.match[3]
  ... snip ...


【備考】
ver 2.6.0以降ではyoutube.coffeeは@robot.http()を利用するように修正されている。また、Responseクラスも警告メッセージを出さないよう修正されている。

How to use Hubot behind a proxy.

You may fail to run a bot which uses http connection with Hubot if you are behind a proxy such as Squid.
Hubot behind a proxy · Issue #287 · github/hubot · GitHub
For example, you'll have following type of error messages when you run "hubot youtube me [search key words]".

events.js:72
            throw er; // Unhandled 'error' event
                      ^
Error: connect ECONNREFUSED
  at errnoException (net.js:900:11)
  at Object.afterConnect [as oncomplete] (net.js:891:19)

In this case, you might be able to solve the issue to specify proxy address and proxy port in node-scoped-http-client which is one of the wrapper libraries of Node.js's HTTP client and used by Hubot.

How to modify the source code (hubot/node_modules/scoped-http-client/src/lib/index.js) is as follows.

port = this.options.port || ScopedClient.defaultPort[this.options.protocol] || 80;
req = (this.options.protocol === 'https:' ? https : http).request({
  // port: port,
  port: 3127,           // you have to specify a proxy port.
  // host: this.options.hostname,
  host: 'localhost',   // you have to specify a proxy server address or hostname.
  method: method,
  // path: this.fullPath(),
  path: 'http://' + this.options.hostname + this.fullPath(),
  headers: headers,
  agent: this.options.agent || false
});