余白の書きなぐり

aueweのブログ

Gmailの外部アカウントのPOP3受信の遅延を無くす最強の方法

GmailPOP3機能で外部アカウントのメールを受信できる。 しかしその更新間隔が長く、しばしば1時間以上の遅延が起きる。

間違った対策

遅延対策としてあちこちのインターネットに書かれているのが メールを今すぐ確認するボタンを手動クリック という、あまりに原始的な方法。

f:id:auewe:20140518022539p:plain

これは根本的な解決になっていない。 外部アカウントがメールを受信すれば即座にGmailに反映されて欲しいわけだが、 この方法で受信間隔を短くするには、人間がPCの前で待機して メールを今すぐ確認するボタンを定期的に押さねばならないからだ。 要するに手動でPOP3してるようじゃ、遅延は解消できない。

最強の方法 → GMail POP3 Checker

GMail POP3 Checker を使えば メールを今すぐ確認するボタンを3分毎に自動クリック してくれる。 このスクリプトを導入したブラウザを常時立ち上げておけば、 外部アカウントがメールを受信したとき、 3分以内に Gmail の受信ボックスにもメールが届くというわけ。 圧倒的に最強なのです。

以下では FirefoxChrome のそれぞれについて、スクリプトの導入法をまとめておく。 (他のブラウザにも導入可能)

GMail POP3 Checker の導入方法 (Firefox)

まずアドオンの Greasemonkey を導入する。次に GMail POP3 Checker の"Click here to download this fancy script!" をクリックすると、自動的にインストールされる。 おもむろに Gmail を開くと、ページの右上に

f:id:auewe:20140513151332p:plain

このような "POP3 3:00 Donation" が表示されるはずだ。 あ、更新間隔は3分ではないかも。 寄付すれば更新間隔が変更できるが、寄付しなければ7分間隔になる。

GMail POP3 Checker の導入方法 (chrome)

まずアドオンの Tampermonkey を導入する。 次に GMail POP3 Checker の"Click here to download this fancy script!" をクリックしてインストールすれば準備完了。 Gmailにアクセスすれば、右上に "POP3 3:00 Donation" が表示される。

他のブラウザについては GmMail POP3 Checkerの Installation Directions を参照せよ。

はてなブログの LaTeX 数式表示がデフォルトで MathJax 化された

2014/05/10 における数式記入法まとめ

はてなブログLaTeX で数式を書くには以下のようにします。

[tex:{ \displaystyle
b_n = \sum_{m=0}^{N-1} a_m
}]

結果↓

{ \displaystyle
b_n = \sum_{m=0}^{N-1} a_m
}

数式は png画像ではなく MathJax で出力されるのでコピペ可能ですが、特に 数式をマウスで反転して「show math as」を選べば LaTeX形式でコピペできます。

以前から MathJax を使ってるはてなブロガー達へ

以前 はてなブログにLaTeXで数式を書く (Markdown記法用) という記事タイトルで、はてなブログMathJax で数式を出力する方法を紹介しました。 そこでは色々書きましたが、今後は

[tex:{ \displaystyle
b_n = \sum_{m=0}^{N-1} a_m
}]

を使って数式を入れましょう。

さて、あなたには2つの道が用意されています。

1. MathJax スクリプトの設定を残す

前回紹介した、サイドバーの設定

<script
  type="text/javascript"
  src="https://c328740.ssl.cf1.rackcdn.com/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"
></script>

を残し、新規に数式を書く場合は [tex:{ 形式を使用する。

2. MathJax スクリプトの設定を消す

今までに書いた \\(...\\)の数式を全て [tex:{ 形式に置換し、前回設定した <script... をサイドバーから削除する。

シェルスクリプトの平文パスワードをセキュアにする方法

追記: (2015/8/3) 大量のはてブが付いたので 続き を書きました。

sshを使用している人は文字列を手軽に暗号化・復号化できるという話。 このテクニックを使えば色々セキュアになるのでおすすめ。 今回はシェルスクリプト中の平文パスワードをセキュアに代替する。

平文パスワードはやめよう

シェルスクリプト中でパスワードが必要になったとき、 とりあえず平文で書いてしまいがち。

#!/bin/sh
PASSWORD="hoge"

これをセキュアにしたい。 面倒くさいのは嫌なので、なるべく手持ちのツールで暗号化、復号化したい。 ssh用の rsa 秘密鍵と、openssl(大抵の環境に入っている)を使って改善しよう。

秘密鍵の準備

パスワードを暗号化するにあたって、秘密鍵を使用する. sshを常用している場合は ~/.ssh/id_rsa という秘密鍵が存在するだろう。 もし秘密鍵が無ければ ssh-keygen で作成しよう。

$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/auewe/.ssh/id_rsa): # ENTER を押す
Enter passphrase (empty for no passphrase): # ENTER を押す
Enter same passphrase again: # ENTER を押す
Your identification has been saved in /home/auewe/.ssh/id_rsa
Your public key has been saved in /home/auewe/.ssh/id_rsa.pub
The key fingerprint is:
0f:2c:88:3d:40:13:0f:b5:a3:d4:0e:b7:e5:86:28:91 auewe@orenomachine
The key's randomart image is:
+--[ RSA 2048]----+
|   o.            |
| k = .           |
|   a   .      a  |
| o X B .  m      |
|. a B S S        |
| B   o . o       |
|      o          |
|                 |
|                 |
+-----------------+

これで秘密鍵 ~/.ssh/id_rsa が作成される。

openssl で文字列を暗号化、復号化

秘密鍵 ~/.ssh/id_rsa を用いて文字列やファイルを暗号化し、 pass.rsa というファイルに保存しよう。 openssl rsautl -encrypt を用いる。

  • 暗号化
# hoge という文字列を暗号化して pass.rsa に書き込むコマンド
$ echo 'hoge' | openssl rsautl -encrypt -inkey ~/.ssh/id_rsa > pass.rsa

# plain.txt というテキストファイルを暗号化して pass.rsa に書き込むコマンド
$ openssl rsautl -encrypt -inkey ~/.ssh/id_rsa -in plain.txt > pass.rsa

暗号化後のファイル pass.rsa を復号化するには openssl rsautl -decrypt を用いる。

  • 復号化
# 暗号化された pass.rsa を復号化して標準出力に表示するコマンド
$ openssl rsautl -decrypt -inkey ~/.ssh/id_rsa -in pass.rsa

従って、冒頭のインセキュアなシェルスクリプトは次のように書き換えよう。

#!/bin/sh

# 暗号化されたパスワードファイル pass.rsa は、あらかじめ用意しておく
PASSWORD=$(openssl rsautl -decrypt -inkey ~/.ssh/id_rsa -in pass.rsa)

補足

暗号化も復号化も秘密鍵を使用したが、 暗号化に関して言うと、原理的には公開鍵 ~/.ssh/id_rsa.pub を用いれば pass.rsa が得られるはずだ。 今回は秘密鍵ファイル中に含まれる公開鍵の情報を用いて暗号化している。

参考

ssh の RSA 鍵を openssl コマンドで扱ってみる

sshで多段接続 (ncも-Wもない人用)

sshで多段接続したい。多段接続について一番わかり易くまとまってるサイトは ncある限りぼくはどこまででもいけるッ! だと思う。ただ残念なことに、うちの環境には nc が入ってなかった。

$ ssh remote
bash: nc: command not found
ssh_exchange_identification: Connection closed by remote host

最近は nc を使わずに ssh -W オプションで代用できるらしい。 今後はこちらが推奨されるとのこと。 ProxyCommandによるsshの多段接続について

しかし僕の環境にはssh -Wもなかった。さてどうするか。

connect の導入

そういうときは connect を使う。 connect を使って簡単に多段 SSH を実現する方法 にそのへんの事情が載っている。

connectコマンドの導入はとても簡単で、 connect.c中継地に ダウンロードした後、

$ gcc connect.c -o connect

コンパイルすればおわり。

環境設定

localから、中継地stepを経由して、remoteに接続したい。 さっきも書いたけど、中継地に connect を導入すること。

local -----------> step -----------> remote
                ↑connect導入
localの環境

localでは~/.ssh/configだけ設定。

# local (~/.ssh/config)

Host remote
Hostname remote.url.jp   # remoteのurl
ProxyCommand ssh step /home/step/bin/connect %h %p
#                     ↑stepサーバー内でのconnectパスを指定
User remote_account_name # stepからremoteに接続するときのアカウント名

# ---------------

Host step
Hostname step.url.jp   # stepのurl
User step_account_name # localからstepに接続するときのアカウント名
stepの環境

stepでは~/.ssh/config~/.ssh/authorized_keysを設定。 まず~/.ssh/config

# step (~/.ssh/config)

Host remote
Hostname remote.url.jp   # remoteのurl
User remote_account_name # stepからremoteに接続するときのアカウント名

.ssh/authorized_keys

# step (~/.ssh/authorized_keys)
localの~/.ssh/id_rsa.pubを登録
remoteの環境

remoteでは~/.ssh/authorized_keysを設定。

# remote (~/.ssh/authorized_keys)
stepの~/.ssh/id_rsa.pubを登録
localの~/.ssh/id_rsa.pubも登録

http 接続できない環境で github から clone して neobundle を使う

http 接続できない環境で github にアクセスする方法を学んだのでメモ。 もし ssh接続が可能なら、githubからリポジトリをcloneできる。 そういう厳しい環境で neobundle を使う方法についてもメモ。

git clone できない悲しみ

$ git clone http://github.com/Shougo/neobundle.vim.git
Cloning into 'neobundle.vim'...
fatal: unable to access 'http://github.com/Shougo/neobundle.vim.git/'
     : Failed connect to github.com:443; Operation now in progress

解決法

まず github アカウントを作成して ssh鍵 (~/.ssh/id_rsa.pub とか) を登録する。

これで

$ git clone git@github.com:Shougo/neobundle.vim.git

が通るようになる。

次に ~/.gitconfig

[url "git@github.com:"]
  insteadOf = git://github.com/
  insteadOf = https://github.com/
  insteadOf = http://github.com/

と追記する。これで

$ git clone http://github.com/Shougo/neobundle.vim.git

が通るようになった。めでたしめでたし。

蛇足 neobundle を使う場

neobundle を使うだけなら ~/.gitconfig を編集する必要は無い。 とにかく neobundle.vim さえ手に入れれば、 以下のように .vimrc を設定することで vimプラグインがインストールされる。 要するに
NeoBundle 'thinca/vim-quickrun' ,{'type__protocol' : 'ssh' }
とすればよい。

" NeoBundle 'thinca/vim-quickrun'
"
" と書くと https で通信するのでエラーが出る
" [neobundle/install] (10/29): |vim-quickrun|
" git clone --recursive https://github.com/thinca/vim-quickrun.git
" ...
" Cloning into '/home/myname/.vim/neobundle/vim-quickrun'...
" fatal: unable to access 'https://github.com/thinca/vim-quickrun.git/'
"      : Failed connect to github.com:443; Operation now in progre

NeoBundle 'thinca/vim-quickrun' ,{'type__protocol' : 'ssh' }

" と書けば ssh が使用される。
" [neobundle/install] (10/29): |vim-quickrun|
" git clone --recursive git@github.com:thinca/vim-quickrun.git

Linux Mint で sshd コマンドが見つからず困った話

Linux Mint では何故か sshdssh なので、ややこしいという話。

sshd のインストール

$ sudo apt-get install openssh-server

設定ファイル sshd_config の場所

/etc/ssh/sshd_config

sshdの再起動

$ sudo service ssh restart

普通は $ sudo /etc/init.d/sshd restart
とか $ sudo service sshd restart
なのに。統一してほしい。


参考:
[LinuxMint]SSH server インストール -- とりぷる ぷぅ 技術メモ

Linux Mint の TeX Live で画像挿入するノウハウ

Linux MintTeX Live 2013 で画像を挿入したいのに、 コンパイルエラーが出て困った(そして解決した)という話。

latexファイルの書き方

[改訂第6版]LaTeX2e 美文書作成入門の120ページや151ページによると、 以下のようにして画像を挿入するのが良いらしい。

\documentclass{jsarticle}
\usepackage[dvipdfmx]{graphicx}
\begin{document}

\begin{figure}[htpd]
  \centering
  \includegraphics[width=5cm]{gazo.pdf}
  \caption{画像だよ}
  \label{fig:gazo}
\end{figure}

% \begin{figure}[H]にすれば、必ずその位置に画像を挿入
% \includegraphics[]{./figdir/gazo.pdf} も可能
% \includegraphics[]{../figdir/gazo.pdf} も可能
% \includegraphics[]{gazo.png} も可能。jpgも可能
% 今後は eps より pdf が推奨される
% ファイル名にアンダースコア_が含まれるとエラーになる

\end{document}

しかし上記ファイルのコンパイルを試みると、gazo.xbbが見つかりません 的なエラーメッセージが現れた。

$ platex hoge.latex
... いろいろ表示される ...
! LaTeX Error: File `gazo.xbb' not found.
Use -shell-escape option to generate automatically.

なんで画像入れるだけで怒られなあかんのや。

解決法: texmf.cnf を編集する

TeX Live 2013 のインストール時に作成される usr/share/texlive/texmf/web2c/texmf.cnf というファイルを編集し、 shell_escape_commands =extractbb を追加すれば、 コンパイルが通るようになった。

具体的には、texmf.cnf の547行目あたりに

%...
%
shell_escape_commands = \
bibtex,bibtex8,\
kpsewhich,\
makeindex,\
mpost,\
repstopdf,\

% we'd like to allow:
%...

という箇所を見つけたので、 以下のように extractbbを追加したらうまくいった。

%...
%
shell_escape_commands = \
bibtex,bibtex8,\
kpsewhich,\
makeindex,\
mpost,\
repstopdf,\
extractbb,\

% we'd like to allow:
%...

[追記 2014/01/10]

Windowsw32tex環境でも同様のコンパイルエラーが発生したので、 以下のように設定して問題を解決した。

....\w32tex\share\texmf-dist\web2c\texmf.cnf の485行目あたりの

% for being called from TeX.
% 
shell_escape_commands = \
bibtex,pbibtex,jbibtex,repstopdf,epspdf,extractbb,\
makeindex,mendex,mpost,pmpost,upmpost,kpsewhich

% we'd like to allow:

% for being called from TeX.
% 
shell_escape_commands = \
bibtex,pbibtex,jbibtex,repstopdf,epspdf,extractbb,\
makeindex,mendex,mpost,pmpost,upmpost,kpsewhich,\
extractbb

% we'd like to allow:

に変更すれば、コンパイルエラーが消えた。