by shigemk2

当面は技術的なことしか書かない

brew PR 3668

lines_cop.rbの変更で、homebrewのFormulaのdepends_onの書き方が一部変わった。 github.com

たとえばPython3は、このように書かないといけない。

  depends_on "python3"

以前と同じようにこう書くと、

  depends_on :python3

auditしたときに以下のようなエラーになる。

$ brew audit --strict ./Formula/you-get.rb
you-get:
  * C: 17: col 3: :python3 is deprecated. Usage should be "python3".
Error: 1 problem in 1 formula

このようなエラーを出すように指示しているのがLibrary/Homebrew/rubocops/lines_cop.rbで、去年末くらいにpython3とかperlとかが該当するようになった。でもドキュメントにこの変更が反映されていない。

スクショ

f:id:shigemk2:20180112145247p:plain

該当ドキュメント

HomebrewのrubydocにはYARDが使われており、関数のコメントをドキュメントに変換してくれている。今回修正すべきドキュメントはそのままlines_cop.rbに記載されていたので、そこを直した。

github.com

(メンテナーが追加でドキュメントを修正してました。あと他の方も別のドキュメントで プルリクを投げています)

max

max

Oracleだけど。たとえばこういうクエリがあったとして、抽出されるデータは全レコードの中からの最大値の入ったレコードではなく、部門別の最大値。だから、複数レコードが返って来る可能性は大いにある。

SQL> select dept, MAX(salary)
  2  from max_sample group by dept;
name dept salary
鈴木 管理部 300000
高橋 管理部 400000
佐藤 開発部 500000
小林 開発部 500000
山本 開発部 200000
青木 開発部 NULL

ldconfig

ldconfig

http://www.infraeye.com/study/linuxz6.html

他のプログラムから利用するプログラム

ライブラリ 説明 メリット デメリット
静的ライブラリ プログラム作成時にその実行ファイル内に組み込まれたライブラリ 1つのプログラムだけで動作するので別環境で動作可 プログラムのファイルが大きい
共有ライブラリ プログラム実行時にロードされて複数のプログラム間で共有 プログラムのサイズが小さい プログラム実行時に適切に配置されたライブラリが必要

プログラムからライブラリの機能を呼び出す

リンク 説明
スタティックリンク プログラム作成時にライブラリの機能をプログラム本体に組み込む。静的ライブラリ
ダイナミックリンク プログラム実行時にライブラリの機能を呼び出す。共有ライブラリ

http://itpro.nikkeibp.co.jp/article/COLUMN/20140127/532504/

  • ldconfigで共有ライブラリのリンク情報を作成/更新する
    • キャッシュファイルからライブラリを呼び出す
    • confファイル /lib /usr/lib /etc/ld.so.conf.d/* の設定を読み込む

ldconfig creates the necessary links and cache to the most recent shared libraries found in the directories specified on the command line, in the file /etc/ld.so.conf, and in the trusted directories, /lib and /usr/lib (on some 64-bit architectures such as x86-64, lib and /usr/lib are the trusted directories for 32-bit libraries, while /lib64 and /usr/lib64 are used for 64-bit libraries).

Oracleのアレ

https://askubuntu.com/questions/159939/how-to-install-sqlplus http://d.hatena.ne.jp/rougeref/20160126

  • Ubuntu 17.10
  • 共有ライブラリの情報がないと怒られる sqlplus: error while loading shared libraries: libsqlplus.so: cannot open shared object file: No such file or directory
  • /etc/ld.so.conf.d/oracle-lib.conf を作成して、/usr/lib/oracle/#{version}/client/lib を書き込む
  • ldconfigで共有ライブラリの情報を追加する

brew 1.4.3

brew 1.4.3

lines_copの基準がちょっとよくわからない

  • upgrade: skip formula if upgrade fails due to unsatisfied requirement.
  • Use hgpath instead of "hg" to fix --HEAD hg builds
  • docs: fix audit warning in Python formula example
  • Update formulae.brew.sh URL (@alyssais)
  • lines_cop: flag depends_on :perl => "1.0".
  • audit: pass explicit sort to handle APFS
  • pathname: Use CI env variable rather than TRAVIS
  • LD64Dependency is needed on macOS only

url-http-create-request Multibyte text in HTTP request

25.3.2 で死ぬやつ。url-retrieveで日本語データが入ったJSONをPOSTすると死ぬ。

url-http-create-request: Multibyte text in HTTP request

(defun url-http-post (url args)
  "Send ARGS to URL as a POST request."
  (let (
        (response-string nil)
        (url-request-method "POST")
        (url-request-extra-headers
         '(("Content-Type" . "application/json")))
        (url-request-data
         (json-encode args)))
    (switch-to-buffer
     (url-retrieve-synchronously url))
    (goto-char (point-min))
    (re-search-forward "\n\n")
    (setq response-string
          (buffer-substring-no-properties (point) (point-max)))
    (kill-buffer (current-buffer))
    response-string))
(url-http-post "http://httpbin.org/post"  '(("hoge" . "fuga") ("piyo" . "鍵")))

bug#23750: 25.0.95; bug in url-retrieve or json.el

Multibyte text in HTTP request

url-http-create-request Multibyte text in HTTP request

Emacs25からurl-http-create-requestするとき、マルチバイト文字列データをリクエストしようとするとエラーになる

** The URL package now insists on sending only unibyte strings to server This means packages that use URL cannot bind 'url-request-data' to multibyte strings. If non-ASCII characters should be part of the URL payload, then 'url-request-data' should be encoded to become a unibyte string.

https://lists.gnu.org/archive/html/bug-gnu-emacs/2016-08/msg00031.html

http://misohena.jp/blog/2016-10-27-problem-org2blog-multibyte-text.html

たとえばrequest.elで、こんなのを投げるとエラーになる。url-retrieveをバックエンドにしてrequestを投げると、 Multibyte text in HTTP request エラーがでる。

(setq request-backend 'url-retrieve)
  (request
   "http://httpbin.org/put"
   :type "PUT"
   :data (json-encode '(("key" . "値1") ("key2" . "値2")))
   :headers '(("Content-Type" . "application/json"))
   :parser 'json-read
   :success (cl-function
             (lambda (&key data &allow-other-keys)
               (message "I sent: %S" (assoc-default 'json data)))))

request.elでマルチバイト文字の入ったJSONをPOSTできない

結論

パッチを投げました。

github.com

概要

EmacsのHTTPクライアント request.el というものがあります。これはcurlのラッパーみたいなもので、GETしたりPOSTしたりするのに大変便利なのですが、以下のようにマルチバイト文字の入ったJSONデータをPOSTしたりPUTしようとしたりすると死にます。POSTできませんが、elisp側でエラーは検出されません。

(request
 "http://httpbin.org/put"
 :type "PUT"
 :data (json-encode '(("key" . "値1") ("key2" . "値2")))
 :headers '(("Content-Type" . "application/json"))
 :parser 'json-read
 :success (cl-function
           (lambda (&key data &allow-other-keys)
             (message "I sent: %S" (assoc-default 'json data)))))

直接の原因はここです。curlでデータを送信するときにテンポラリのバッファにデータを入れているのですが、このときバッファのエンコーディングが 'binary になっているので、マルチバイト文字はユニコードに変換されたうえでHTTPリクエストされます。そのためにリクエストがエラーになってしまいます。

   (when data
     (let ((tempfile (request--make-temp-file)))
       (push tempfile (request-response--tempfiles response))
       (let ((file-coding-system-alist nil)
             (coding-system-for-write 'binary))
         (with-temp-file tempfile
           (setq buffer-file-coding-system 'binary)
           (set-buffer-multibyte nil)
           (insert data)))
       (list "--data-binary" (concat  "@" (request-untrampify-filename tempfile)))))

https://github.com/tkf/emacs-request/blob/master/request.el#L917-L926

んじゃあここの buffer-file-coding-system'utf-8 にして、 set-buffer-multibyte の設定をやめたらいいのでは?と思うのですが、これWindowsなど別の文字コードをベースにしてrequestするとまた別の問題が発生するかもしれないので、ココの部分を変数でもってユーザー側で変更できるようにしました。デフォルトは 'binary なので、既存のものはそのまま使えます。

ほんとはココと結構被るのですが、テストコードやドキュメントを追加した感じになります。

github.com

と言った感じの備忘録です。

問題点

最後のメンテが2017/1で1年近くメンテされておらず、誰がメンテナーなのかわかりません。ので、取り込まれるどころかレビューされるかどうかも怪しいです。気長にまとうと思います。

defcustom

decustom

defcustom Macro: Declare SYMBOL as a customizable variable. SYMBOL is the variable name; it should not be quoted. STANDARD is an expression specifying the variable’s standard value. It should not be quoted. It is evaluated once by ‘defcustom’, and the value is assigned to SYMBOL if the variable is unbound. The expression itself is also stored, so that Customize can re-evaluate it later to get the standard value. DOC is the variable documentation.

  • defvarは初期化で、setqは代入であること
  • ユーザカスタマイズを目的とする変数を宣言するにはdefcustomを使うこと
  • defcustomで定義された変数の変更には常にcustom-set-variablesを用いるべきであること。

http://d.hatena.ne.jp/rubikitch/20100201/elispsyntax

http://memo.sugyan.com/entry/20120104/1325604433

http://kawamuray.hatenablog.com/entry/2013/11/03/180543