カテゴリー: 技術系

  • ウェブサーバのSSL設定のコンフィグを生成してくれるジェネレータ

    ウェブサーバのSSL設定のコンフィグを生成してくれるジェネレータを、Mozillaが公開している。 NginxもApacheもAWS ELBも生成してくれるので、便利。証明書のパスなどは自分で書き換える必要があるが、ベースになるコンフィグを作ってくれるので、楽。

    もちろん、必要に応じてチューニングは必要だが、ベースは重要。

  • 特定バージョンのRuby on Railsをインストールする

    バージョンを指定したRailsのインストールは、下記。

    gem install rails -v インストールするバージョン
    

    インストールされているRailsのバージョンを表示するコマンドは下記。

    rails -v
    

    例: Rails 5.2.2.1をインストールする

    zen:~$ gem install rails -v 5.2.2.1
    Fetching thread_safe-0.3.6.gem
    Fetching tzinfo-1.2.5.gem
    Fetching i18n-1.6.0.gem
    Fetching activesupport-5.2.2.1.gem
    Fetching mini_portile2-2.4.0.gem
    Fetching nokogiri-1.10.1.gem
    Fetching concurrent-ruby-1.1.5.gem
    Fetching rails-dom-testing-2.0.3.gem
    Fetching rails-html-sanitizer-1.0.4.gem
    Fetching loofah-2.2.3.gem
    Fetching builder-3.2.3.gem
    Fetching actionview-5.2.2.1.gem
    Fetching rack-2.0.6.gem
    Fetching crass-1.0.4.gem
    Fetching rack-test-1.1.0.gem
    Fetching erubi-1.8.0.gem
    Fetching actionpack-5.2.2.1.gem
    Fetching activemodel-5.2.2.1.gem
    Fetching activejob-5.2.2.1.gem
    Fetching arel-9.0.0.gem
    Fetching activerecord-5.2.2.1.gem
    Fetching mini_mime-1.0.1.gem
    Fetching mail-2.7.1.gem
    Fetching globalid-0.4.2.gem
    Fetching nio4r-2.3.1.gem
    Fetching actionmailer-5.2.2.1.gem
    Fetching websocket-extensions-0.1.3.gem
    Fetching websocket-driver-0.7.0.gem
    Fetching actioncable-5.2.2.1.gem
    Fetching mimemagic-0.3.3.gem
    Fetching marcel-0.3.3.gem
    Fetching activestorage-5.2.2.1.gem
    Fetching thor-0.20.3.gem
    Fetching rails-5.2.2.1.gem
    Fetching method_source-0.9.2.gem
    Fetching sprockets-3.7.2.gem
    Fetching sprockets-rails-3.2.1.gem
    Fetching railties-5.2.2.1.gem
    Successfully installed concurrent-ruby-1.1.5
    Successfully installed thread_safe-0.3.6
    Successfully installed tzinfo-1.2.5
    
    HEADS UP! i18n 1.1 changed fallbacks to exclude default locale.
    But that may break your application.
    
    Please check your Rails app for 'config.i18n.fallbacks = true'.
    If you're using I18n (>= 1.1.0) and Rails (< 5.2.2), this should be
    'config.i18n.fallbacks = [I18n.default_locale]'.
    If not, fallbacks will be broken in your app by I18n 1.1.x.
    
    For more info see:
    https://github.com/svenfuchs/i18n/releases/tag/v1.1.0
    
    Successfully installed i18n-1.6.0
    Successfully installed activesupport-5.2.2.1
    Successfully installed mini_portile2-2.4.0
    Building native extensions. This could take a while...
    Successfully installed nokogiri-1.10.1
    Successfully installed rails-dom-testing-2.0.3
    Successfully installed crass-1.0.4
    Successfully installed loofah-2.2.3
    Successfully installed rails-html-sanitizer-1.0.4
    Successfully installed erubi-1.8.0
    Successfully installed builder-3.2.3
    Successfully installed actionview-5.2.2.1
    Successfully installed rack-2.0.6
    Successfully installed rack-test-1.1.0
    Successfully installed actionpack-5.2.2.1
    Successfully installed activemodel-5.2.2.1
    Successfully installed arel-9.0.0
    Successfully installed activerecord-5.2.2.1
    Successfully installed mini_mime-1.0.1
    Successfully installed mail-2.7.1
    Successfully installed globalid-0.4.2
    Successfully installed activejob-5.2.2.1
    Successfully installed actionmailer-5.2.2.1
    Building native extensions. This could take a while...
    Successfully installed nio4r-2.3.1
    Successfully installed websocket-extensions-0.1.3
    Building native extensions. This could take a while...
    Successfully installed websocket-driver-0.7.0
    Successfully installed actioncable-5.2.2.1
    Successfully installed mimemagic-0.3.3
    Successfully installed marcel-0.3.3
    Successfully installed activestorage-5.2.2.1
    Successfully installed method_source-0.9.2
    Successfully installed thor-0.20.3
    Successfully installed railties-5.2.2.1
    Successfully installed sprockets-3.7.2
    Successfully installed sprockets-rails-3.2.1
    Successfully installed rails-5.2.2.1
    Parsing documentation for concurrent-ruby-1.1.5
    Installing ri documentation for concurrent-ruby-1.1.5
    Parsing documentation for thread_safe-0.3.6
    Installing ri documentation for thread_safe-0.3.6
    Parsing documentation for tzinfo-1.2.5
    Installing ri documentation for tzinfo-1.2.5
    Parsing documentation for i18n-1.6.0
    Installing ri documentation for i18n-1.6.0
    Parsing documentation for activesupport-5.2.2.1
    Installing ri documentation for activesupport-5.2.2.1
    Parsing documentation for mini_portile2-2.4.0
    Installing ri documentation for mini_portile2-2.4.0
    Parsing documentation for nokogiri-1.10.1
    Installing ri documentation for nokogiri-1.10.1
    Parsing documentation for rails-dom-testing-2.0.3
    Installing ri documentation for rails-dom-testing-2.0.3
    Parsing documentation for crass-1.0.4
    Installing ri documentation for crass-1.0.4
    Parsing documentation for loofah-2.2.3
    Installing ri documentation for loofah-2.2.3
    Parsing documentation for rails-html-sanitizer-1.0.4
    Installing ri documentation for rails-html-sanitizer-1.0.4
    Parsing documentation for erubi-1.8.0
    Installing ri documentation for erubi-1.8.0
    Parsing documentation for builder-3.2.3
    Installing ri documentation for builder-3.2.3
    Parsing documentation for actionview-5.2.2.1
    Installing ri documentation for actionview-5.2.2.1
    Parsing documentation for rack-2.0.6
    Installing ri documentation for rack-2.0.6
    Parsing documentation for rack-test-1.1.0
    Installing ri documentation for rack-test-1.1.0
    Parsing documentation for actionpack-5.2.2.1
    Installing ri documentation for actionpack-5.2.2.1
    Parsing documentation for activemodel-5.2.2.1
    Installing ri documentation for activemodel-5.2.2.1
    Parsing documentation for arel-9.0.0
    Installing ri documentation for arel-9.0.0
    Parsing documentation for activerecord-5.2.2.1
    Installing ri documentation for activerecord-5.2.2.1
    Parsing documentation for mini_mime-1.0.1
    Installing ri documentation for mini_mime-1.0.1
    Parsing documentation for mail-2.7.1
    Installing ri documentation for mail-2.7.1
    Parsing documentation for globalid-0.4.2
    Installing ri documentation for globalid-0.4.2
    Parsing documentation for activejob-5.2.2.1
    Installing ri documentation for activejob-5.2.2.1
    Parsing documentation for actionmailer-5.2.2.1
    Installing ri documentation for actionmailer-5.2.2.1
    Parsing documentation for nio4r-2.3.1
    Installing ri documentation for nio4r-2.3.1
    Parsing documentation for websocket-extensions-0.1.3
    Installing ri documentation for websocket-extensions-0.1.3
    Parsing documentation for websocket-driver-0.7.0
    Installing ri documentation for websocket-driver-0.7.0
    Parsing documentation for actioncable-5.2.2.1
    Installing ri documentation for actioncable-5.2.2.1
    Parsing documentation for mimemagic-0.3.3
    Installing ri documentation for mimemagic-0.3.3
    Parsing documentation for marcel-0.3.3
    Installing ri documentation for marcel-0.3.3
    Parsing documentation for activestorage-5.2.2.1
    Installing ri documentation for activestorage-5.2.2.1
    Parsing documentation for method_source-0.9.2
    Installing ri documentation for method_source-0.9.2
    Parsing documentation for thor-0.20.3
    Installing ri documentation for thor-0.20.3
    Parsing documentation for railties-5.2.2.1
    Installing ri documentation for railties-5.2.2.1
    Parsing documentation for sprockets-3.7.2
    Installing ri documentation for sprockets-3.7.2
    Parsing documentation for sprockets-rails-3.2.1
    Installing ri documentation for sprockets-rails-3.2.1
    Parsing documentation for rails-5.2.2.1
    Installing ri documentation for rails-5.2.2.1
    Done installing documentation for concurrent-ruby, thread_safe, tzinfo, i18n, activesupport, mini_portile2, nokogiri, rails-dom-testing, crass, loofah, rails-html-sanitizer, erubi, builder, actionview, rack, rack-test, actionpack, activemodel, arel, activerecord, mini_mime, mail, globalid, activejob, actionmailer, nio4r, websocket-extensions, websocket-driver, actioncable, mimemagic, marcel, activestorage, method_source, thor, railties, sprockets, sprockets-rails, rails after 40 seconds
    38 gems installed
    zen:~$
    zen:~$ rails -v
    Rails 5.2.2.1
    
  • Ubuntu でユーザをグループに追加する

    Ubuntuでユーザをグループに追加するには、usermod -aGコマンドを使用する。 “-a”オプションも使用しないと、グループに追加されるわけではなく、副グループが切り替わってしまうので、注意。

    sudo usermod -aG グループ名 ユーザ名
    

    実行例)

    $ sudo usermod -aG developers zen
    $ groups
    zen sudo developers
    

  • aptの公開鍵の追加でエラー

    下記のように、aptの公開鍵を追加しようとしたところ、エラーが出た。

    zen:~$ sudo curl -sL "http://keyserver.ubuntu.com/pks/lookup?op=get&search=0xF1656F24C74CD1D8" | sudo apt-key add
    E: gnupg, gnupg2 and gnupg1 do not seem to be installed, but one of them is required for this operation
    

    gnupgがインストールされていないのが、原因なので、aptでインストール。

    sudo apt install gnupg
    

    gnupgのインストール後に、再度、試したところ、正常にapt公開鍵の追加が完了した。

  • Ubuntu Server 18.04でIPアドレスを確認する

    Ubuntu Server 18.04 には、ifconfigがインストールされていないので、ipコマンドを使用する。

    IPアドレスの確認であれば、”ip addr” で確認できる。

    ip addr
    

    ifconfigがなくなるとは。。。

  • なぜ、Ruby on Railsの動作にNode.jsが必要なのか

    Roby on Railsの環境を用意しないといけなくなったので、Ubuntuでの構築方法を調べていたところ、インストールの中に、Sqlite3-devとNode.jsがあった。Sqlite3-devは、Railsの管理のために必要ということなので、納得。だが、Node.jsがわからない。Node.jsはサーバサイドのJavaScript実行環境なので、rubyは関係ない。関係ないが、Railsには必要だという。気持ち悪いので、調べた。

    それでわかったことは

    • Rails3.1以降、Ubuntuでの開発にはJavaScriptのランタイムが必要になった。
    • JavaScriptのランタイムは、Railsアセットパイプライン(Rails asset pipeline)のコードをコンパイルするのに必要。
    • Node.jsをインストールすることで、サーバサイドでのJavaScriptの実行環境が整う。
    • 参照元: http://railsapps.github.io/installrubyonrails-ubuntu.html

    ということ。Railsの一部をコンパイルするときにJavaScriptのランタイムが必要で、それを準備するための最適解がNode.jsのインストール。すっきり。

    なお、Node.jsをインストールしない場合は、ビルドするRailsアプリケーションのGemfileに下記の設定追加が必要。

     gem 'therubyracer'
    
  • Googleで英語サイトを検索する

    Googleで英語のキーワードをいれて、検索しても日本語のサイトから検索されてしまい、英語のサイトが検索されない。エラーコードや設定などを検索するときは、どうしても英語のサイトの方がよいことがある(日本語の情報が少ないから)。

    Googleで英語サイトを検索する方法を調べていたら、下記のURLを使えば、アメリカのGoogle検索を使えるとのこと。

    参照元: https://www.suzukikenichi.com/blog/how-to-search-on-google-com-in-english-from-japan/

    問題解決、ありがたい。

  • Redmineの記法をMarkdownに変更する

    Redmineでは、テキスト装飾の記法に、textile(デフォルト)の他に、Markdownを選択することができる。(Redmine2.5以降)

    切替は、

    1. 「管理」→「設定」→「全般」タブを開く
    2. 「テキスト書式」の部分で、Markdownを選択する
    3. 保存をクリックする

    記法の切り替えは後からでもできるが、切り替えると登録済みのテキストは崩れるので注意。TextileとMarkdownで記法が異なるため、パースするときに崩れる。そのため、すでに作成したチケットやWikiのページは修正する必要がある。

  • VAIOの電源が入らないときのバッテリーリセット

    VAIO(VAIO PF)の電源ボタンを教えても、電源が入らなかったときは、バッテリーリセットを試す。

    内蔵型バッテリーのときは、物理的なバッテリーのつけ外しができないため、バッテリー接続の回路をきるためのスイッチが設けられている。このスイッチを使うことでバッテリーを外したときと同じ効果がある。

    1. VAIOからACアダプタを外す。
    2. VAIOを裏返す。
    3. LANポート横にある小さい穴を探す(モデルによって場所が異なる)。
    4. 伸ばしたクリップなどの先を使って、穴を押し、カチっとした感触があれば、3秒ほど押し続ける。
    5. 5分待つ。
    6. 電源を入れる。これで電源が入り、OSのデスクトップまで立ち上がればOK。

    以上で終わり。

  • GASのウェブアプリをIEで使うと、POSTしたデータが文字化けする

    Google Apps Scripts(GAS)で、ウェブアプリを作成できる。 IEでそのフォームを使って、Spreadsheetにデータの書き込みをすると文字化けする。 Chromeだと、問題なく文字化けせず書き込める。

    GASのウェブアプリなので、いろいろと制限だらけなので、HTMLの文字コードの指定などもうまくいかず。 ブラウザでの文字コードの認識を確認してみると、ChromeではUTF-8、IE11はUTF-8以外で認識されていた。 GASのウェブアプリにアクセスした際に、ブラウザをみて文字コードを変えているようで、IE11でUTF-8を指定すると文字化けする。

    GASのコードで文字コードの指定をしたが、UTF-8で指定されず。 いろいろと試した結果、フォームに送信するときの文字コード指定するコードして、UTF-8でPOSTすることにより、IE11でもPOSTしたデータの文字化けを防ぐことができた。

    formタグで、「accept-charset=”utf-8″」を指定することで、データ送信時の文字コードをUTF-8(それ以外も可)にすることができる。