tohokuaikiのチラシの裏

技術的ネタとか。

milkodeのWindows8へのインストールでハマっている件

コード検索をfind&grepでやらなくても済むmilkodeというソフトがあります。

Rubyで書かれたWEBアプリなのでgemで簡単インストール。・・・・なのですが、ハマってます。以前インストールした際はそうでもなかったのですが、2年ぶりくらいにインストールしたらハマりました。

Rubyのインストール

FAQによると推奨バージョンがruby 1.9.3p392/2.0.0p0ということでRubyInstallerから1.9.3をインストール。Powershellなどで使えるようにRubyへのパスを環境変数PATHに追加。

PS C:\Users\Takashi> ruby -v
ruby 1.9.3p551 (2014-11-13) [i386-mingw32]

ついでに Devkitもインストールしておく。

gemでmilkodeのインストール

gemで簡単にインストールする。document関連のエラーが出るのが面倒なので-no-docをつける。たくさんの依存パッケージと共にインストールされる。

PS C:\Users\Takashi> gem install -no-doc milkode
Successfully installed milkode-1.8.8
1 gem installed

だけど、milkコマンドでエラーが出る。

PS C:\Users\Takashi> milk
C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- groonga.so (LoadError)
        from C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rroonga-6.0.0-x86-mingw32/lib/groonga.rb:46:in `rescue in <top (required)>'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rroonga-6.0.0-x86-mingw32/lib/groonga.rb:42:in `<top (required)>'
        from C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
        from C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/milkode-1.8.8/lib/milkode/database/groonga_database.rb:9:in `<top (required)>'
        from C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
        from C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/milkode-1.8.8/lib/milkode/cdstk/cdstk.rb:24:in `<top (required)>'
        from C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
        from C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/milkode-1.8.8/lib/milkode/cli.rb:4:in `<top (required)>'
        from C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
        from C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/milkode-1.8.8/bin/milk:7:in `<top (required)>'
        from C:/Ruby193/bin/milk:23:in `load'
        from C:/Ruby193/bin/milk:23:in `<main>'

groonga.soができてないということで怒られる。

んー、っということでcygwinで検索してみる。

Takashi@JUNOE-VAIOPRO13 ~
$ cd /cygdrive/c/Ruby193/lib
$ find . -name "groonga.so"|xargs ls -lh
-rwxrwx---+ 1 Takashi なし 384K 5月   2 19:49 ./ruby/gems/1.9.1/gems/rroonga-6.0.0-x86-mingw32/lib/2.1/groonga.so
-rwxrwx---+ 1 Takashi なし 384K 5月   2 19:49 ./ruby/gems/1.9.1/gems/rroonga-6.0.0-x86-mingw32/lib/2.2/groonga.so
-rwxrwx---+ 1 Takashi なし 384K 5月   2 19:49 ./ruby/gems/1.9.1/gems/rroonga-6.0.0-x86-mingw32/lib/2.3/groonga.so

なんかgroonga.soが既にあるような気がする。。。

rroonga単体でインストールしてみる。

PS C:\Users\Takashi> gem install rroonga
Successfully installed rroonga-6.0.0-x86-mingw32
1 gem installed

インストールできたっぽいが、milkコマンド実行してもダメ。前と同じエラー。

devkitの説明ページを見てみると、gemインストール時にオプションが必要みたい。 ということで、--platform=rubyをつけてみる。前と様子が変わる。

PS C:\Users\Takashi> gem install rroonga --platform=ruby
Fetching: rroonga-6.0.0.gem (100%)
Temporarily enhancing PATH to include DevKit...
Building native extensions.  This could take a while...
ERROR:  Error installing rroonga:
        ERROR: Failed to build gem native extension.

        C:/Ruby193/bin/ruby.exe extconf.rb
checking for GCC... yes
checking for Win32 OS... yes
downloading http://packages.groonga.org/windows/groonga/groonga-6.0.0-x86.zip... done
extracting... done
installing... done
removing binary archive... done
checking for groonga version (>= 6.0.0)... yes
checking for -Wl,-rpath is available... yes
checking for HAVE_RUBY_ST_H in ruby.h... yes
checking for rb_errinfo() in ruby.h... yes
checking for rb_sym2str() in ruby.h... no
checking for rb_to_symbol() in ruby.h... no
checking for rb_ary_new_from_args() in ruby.h... no
checking for rb_ary_new_from_values() in ruby.h... no
checking for enum ruby_value_type in ruby.h... yes
checking for --enable-debug-log option... no
checking for --enable-debug-build option... no
checking for --enable-untyped-data-warning option... no
creating Makefile

make
compiling rb-grn-accessor.c
compiling rb-grn-array-cursor.c
compiling rb-grn-array.c
compiling rb-grn-column.c
rb-grn-column.c: In function 'rb_grn_column_find_indexes':
rb-grn-column.c:769:5: warning: implicit declaration of function 'rb_ary_new_capa'
compiling rb-grn-config.c
compiling rb-grn-context.c
compiling rb-grn-database.c
compiling rb-grn-double-array-trie-cursor.c
compiling rb-grn-double-array-trie.c
compiling rb-grn-encoding-support.c
compiling rb-grn-encoding.c
compiling rb-grn-equal-operator.c
compiling rb-grn-exception.c
compiling rb-grn-expression-builder.c
compiling rb-grn-expression.c
compiling rb-grn-fix-size-column.c
compiling rb-grn-flushable.c
compiling rb-grn-geo-point.c
compiling rb-grn-greater-equal-operator.c
compiling rb-grn-greater-operator.c
compiling rb-grn-hash-cursor.c
compiling rb-grn-hash.c
compiling rb-grn-index-column.c
compiling rb-grn-index-cursor.c
compiling rb-grn-index.c
compiling rb-grn-less-equal-operator.c
compiling rb-grn-less-operator.c
compiling rb-grn-logger.c
compiling rb-grn-match-operator.c
compiling rb-grn-normalizer.c
compiling rb-grn-not-equal-operator.c
compiling rb-grn-object.c
rb-grn-object.c: In function 'rb_grn_object_key_accessor_p':
rb-grn-object.c:1707:14: warning: 'context' may be used uninitialized in this function
rb-grn-object.c:1708:14: warning: 'object' may be used uninitialized in this function
rb-grn-object.c: In function 'rb_grn_object_accessor_p':
rb-grn-object.c:1671:14: warning: 'context' may be used uninitialized in this function
rb-grn-object.c:1672:14: warning: 'object' may be used uninitialized in this function
rb-grn-object.c: In function 'rb_grn_object_scorer_procedure_p':
rb-grn-object.c:1645:14: warning: 'context' may be used uninitialized in this function
rb-grn-object.c:1646:14: warning: 'object' may be used uninitialized in this function
rb-grn-object.c: In function 'rb_grn_object_selector_only_procedure_p':
rb-grn-object.c:1619:14: warning: 'context' may be used uninitialized in this function
rb-grn-object.c:1620:14: warning: 'object' may be used uninitialized in this function
rb-grn-object.c: In function 'rb_grn_object_selector_procedure_p':
rb-grn-object.c:1593:14: warning: 'context' may be used uninitialized in this function
rb-grn-object.c:1594:14: warning: 'object' may be used uninitialized in this function
rb-grn-object.c: In function 'rb_grn_object_function_procedure_p':
rb-grn-object.c:1567:14: warning: 'context' may be used uninitialized in this function
rb-grn-object.c:1568:14: warning: 'object' may be used uninitialized in this function
rb-grn-object.c: In function 'rb_grn_object_procedure_p':
rb-grn-object.c:1541:14: warning: 'context' may be used uninitialized in this function
rb-grn-object.c:1542:14: warning: 'object' may be used uninitialized in this function
rb-grn-object.c: In function 'rb_grn_object_table_p':
rb-grn-object.c:1516:14: warning: 'context' may be used uninitialized in this function
rb-grn-object.c:1517:14: warning: 'object' may be used uninitialized in this function
rb-grn-object.c: In function 'rb_grn_object_builtin_p':
rb-grn-object.c:1491:14: warning: 'context' may be used uninitialized in this function
rb-grn-object.c:1492:14: warning: 'object' may be used uninitialized in this function
rb-grn-object.c: In function 'rb_grn_object_unlink':
rb-grn-object.c:626:14: warning: 'object' may be used uninitialized in this function
rb-grn-object.c:627:14: warning: 'context' may be used uninitialized in this function
rb-grn-object.c: In function 'rb_grn_object_close':
rb-grn-object.c:585:14: warning: 'object' may be used uninitialized in this function
rb-grn-object.c:585:14: note: 'object' was declared here
rb-grn-object.c:586:14: warning: 'context' may be used uninitialized in this function
rb-grn-object.c:586:14: note: 'context' was declared here
rb-grn-object.c: In function 'rb_grn_object_close_raw':
rb-grn-object.c:585:14: warning: 'object' may be used uninitialized in this function
rb-grn-object.c:586:14: warning: 'context' may be used uninitialized in this function
compiling rb-grn-operator.c
compiling rb-grn-patricia-trie-cursor.c
compiling rb-grn-patricia-trie.c
compiling rb-grn-plugin.c
compiling rb-grn-posting.c
compiling rb-grn-prefix-operator.c
compiling rb-grn-procedure-type.c
compiling rb-grn-procedure.c
compiling rb-grn-query-logger.c
compiling rb-grn-record.c
compiling rb-grn-regexp-operator.c
compiling rb-grn-snippet.c
compiling rb-grn-table-cursor-key-support.c
compiling rb-grn-table-cursor.c
compiling rb-grn-table-key-support.c
compiling rb-grn-table.c
compiling rb-grn-thread.c
compiling rb-grn-type.c
compiling rb-grn-utils.c
compiling rb-grn-variable-size-column.c
compiling rb-grn-variable.c
compiling rb-grn-windows-event-logger.c
compiling rb-groonga.c
rb-groonga.c: In function 'rb_grn_s_get_error_message':
rb-groonga.c:49:9: warning: implicit declaration of function 'rb_enc_str_new_cstr'
linking shared-object groonga.so
Creating library file: libruby-groonga.arb-grn-column.o: In function `rb_grn_column_find_indexes':
C:\Ruby193\lib\ruby\gems\1.9.1\gems\rroonga-6.0.0\ext\groonga/rb-grn-column.c:769: undefined reference to `rb_ary_new_capa'rb-groonga.o: In function `rb_grn_s_get_error_message':
C:\Ruby193\lib\ruby\gems\1.9.1\gems\rroonga-6.0.0\ext\groonga/rb-groonga.c:49: undefined reference to `rb_enc_str_new_cstr'collect2: ld returned 1 exit status
make: *** [groonga.so] Error 1


Gem files will remain installed in C:/Ruby193/lib/ruby/gems/1.9.1/gems/rroonga-6.0.0 for inspection.
Results logged to C:/Ruby193/lib/ruby/gems/1.9.1/gems/rroonga-6.0.0/ext/groonga/gem_make.out

んー、groongaのコンパイルに失敗しているくさい。。。

groongaは単体でインストールできるので、Windowsインストーラをダウンロードしてインストールしてみる。こんなん普通に考えてパス通らないんじゃないかと思うんだけど、果たしてその通り何も変わらなかった。

というところでハマり。

対応策

Twitterで教えてもらった。

Ruby2.3にしたら問題なくgemでインストール完了。 なんて楽なんだ・・・・。@ktouさんありがとうございます。

jQueryで排他的なCheckbox

一つチェックボックスしたら他のはチェックさせたくないってありますよね。

それならラジオボックス使えって話なのですが、ラジオは全部解除ができなくなってしまうからっていう。 (全部解除のUIってわかりにくいでしょ)

ということで、

<p rel="reserve">
<input type="checkbox" value="1">選択肢1
<input type="checkbox" value="1">選択肢2
</p>

に対して

jQuery((function($){
    return function(){
        var chks = $('p[rel="reserve"] input');
        chks.on('change firsttrigger', function(e) {
            var checked = chks.filter(':checked');
            if (checked.length == 0){
                chks.prop('disabled', false);
            }
            else {
                chks.each(function(i, chk){
                    $(chk).prop('disabled', chk != checked.get(0));
                });
            }
        }).trigger('firsttrigger');
    };
})(jQuery));

こんな感じで。

InternetExplorerのローカルファイルへのリンク読み込みの件でハマった件

前提&症状

インターネットからHTMLファイルとその周辺一式をZIPでファイルをダウンロードして、HTML/JavaScriptなどを編集していた。

ChromeFirefoxでは問題なかったのだが、IEでチェックしようとしたら編集したファイルだけが動作しない。

編集したJavaScriptは読み込みが拒否される様で「そんな関数はない」とエラーが出るし、HTMLにリンクしようとしたらリンクを拒否される。そもそもそこまで気づいたのはframeのsrc先に指定しても読み込まなくて真っ白だったからなんだけど。

やっかいだったのが、直接開けば開けるのだがリンクが効かないだけという件。

ファイルの権限?プロパティ?

ということで、Windowsのファイル権限を調べてみた。デジタルアドバンテージの打越さん、ありがとうございます!(お知り合いでもないけど)

全然関係なかった。

原因はこれ。

f:id:tohokuaiki:20160330122052j:plain

読み出しもとのファイルにこの制限がかかっている場合、このファイルからリンクしているものはこの制限が罹っているものとみなされるようだ。

ただし、同じく制限が掛かっているファイルであれば、リンクは有効なものとされるが、制限が外れたものにはリンクは無効となるらしい。で、ファイルを編集することによりこの制限が自動的に外れるので編集したファイルはリンクできなくなってしまったのだ。

なので、大本のindex.htmlの解除を外してやることで終了。

だと思うけど、とりあえず複数で一括解除する方法もあるみたいなのでそちらも。

複数のファイルをまとめて「ブロックの解除」をする方法 - Windows - Project Group

ダウンロードリンクが切れているのでこちらから

https://technet.microsoft.com/ja-jp/sysinternals/streams.aspxtitle]

使い方は簡単で、当該ディレクトリにcdしてから

streams -d -s .

WordPressで固定ページでHTMLをちまちま入力するのが面倒なのでHTMLファイルをインポートするだけのショートコードを作った

タイトルのまんま。

ちまちまと編集画面がとても大変なので、functions.phpにこんなの作った。

あとは編集画面に[include_static_html]と書いて静的HTMLをアップするだけ。

<?php
/**
 * @brief ページ制作に楽なショートコード
 * @param 
 * @retval
 */
function include_static_html_func($attr)
{
    extract(shortcode_atts(array(
        'path' => "",
        ), $attr));
    
    if (is_page()) {
        $page = get_post(get_the_ID());
        if (!$path){
            if ($page->post_parent){
                $path = sprintf('%s/%s',
                                get_page_uri($page->post_parent),
                                $page->post_name);
            } else {
                $path = $page->post_name;
            }
        }
        $path = sprintf('%s/static_html/%s.html',
                        get_template_directory(), $path);
        if (file_exists($path)){
            // return @file_get_contents($path);
            ob_start();
            include $path;
            return ob_get_clean();
        }
        return $path . " not exists.";
    }
    
    return "invalid include_static_html_func";
}
add_shortcode('include_static_html', 'include_static_html_func');

追記

PHPが効くようにincludeにした。

fireworksで長方形選択ができなくなってびびった件

なんか、長方形選択をしようとしても選択が解除されてしまう。あるいは変な領域が自動選択されてしまうなんで!?とか思ってgoogle:fireworks 長方形選択ツール 使えないとか検索してても全然ヒットしない。

んん~Fireworks壊れた?とか思ったけど、長方形選択ツールのここのプロパティを「アンチエイリアスをオフ」にしたら直った。よかった。。。

f:id:tohokuaiki:20160315111951p:plain