`(blog ,garaemon)

ポップカルチャーを摂取して、コードを吐き出す機械

javascript版jupyterのようなobservable

beta.observablehq.com

observableはjavascript版のjupyterのようなサービス. d3.jsを利用した美しい可視化が特徴的.

どうやら今年の1月31日にサービスインしたらしい.

ここから基本的なサンプルを色々見ることができる. jupyterと正面から勝負するのは大変そうな気もするけど、出力となるノートはobservableの方がきれいなので注目している.

ちなみに、d3.expressというURLからも飛ぶことができる.

emacsでカーソル位置の単語をispellの辞書に追加する

emacsでカーソル位置の単語をispellの辞書に追加するelispコード

(require 'thingatpt)

(defun add-word-to-ispell-dictionary ()
  "Add word to dictionary file for ispell."
  (interactive)
  (let ((user-dictionary-file (expand-file-name "~/.aspell.en.pws")))
    (let ((buf (find-file-noselect user-dictionary-file)))
      (if (not (file-exists-p user-dictionary-file))
          (with-current-buffer buf
            (insert "personal_ws-1.1 en 0\n")
            (save-buffer)))
      (let ((theword (thing-at-point 'word)))
        (if theword
            (with-current-buffer buf
              (goto-char (point-max))
              (insert (format "%s\n" theword))
              (save-buffer))))
      )))

(global-set-key "\M-." 'add-word-to-ispell-dictionary)

emacsでカーソル位置の数字を上下させる

emacsでカーソル位置の数字を上下させるemacs lispコード. どこかから拾ってきたのかもしれないもの. 意外と便利.

(defun increment-number-at-point ()
  "Increase number at current cursor."
  (interactive)
  (skip-chars-backward "0123456789")
  (or (looking-at "[0123456789]+")
      (error
       "No number at point"))
  (replace-match (number-to-string (1+ (string-to-number (match-string 0))))))

(defun decrement-number-at-point ()
  "Decrease number at current cursor."
  (interactive)
  (skip-chars-backward "0123456789")
  (or (looking-at "[0123456789]+")
      (error
       "No number at point"))
  (replace-match (number-to-string (1- (string-to-number (match-string 0))))))

(global-set-key (kbd "C-c C-+") 'increment-number-at-point)
(global-set-key (kbd "C-c C--") 'decrement-number-at-point)

ambie + TT-BR06が悪くない

ambieは耳をふさがないイヤホンということで周囲の音が聞きやすいということを売りに出されているイヤホンだ.

ambie.co.jp

もともとはイヤホンジャックを備えている有線イヤホンとして販売されていた.

ambie.co.jp

先日Bluetoothによって無線化された新製品が発売された.

ambie.co.jp

しかしこの新製品、いくつかの残念な点がある.

個人的には旧有線ambieにtaotronicsのTT-BR06というBluetooth レシーバをつけて利用している.

TT-BR06 Bluetoothレシーバー

このTT-BR06という製品の素晴らしいところは

  • 連続再生時間が15時間(!)
  • 充電しながら利用できる

という2点である. また、Bluetooth 4.1なのでBluetooth 3.0の無線ambieに比べるとその点においても良い.

micropythonでm5stackをwifiにつなげる

m5stackでmicropythonを使ってwifiを利用するときは, wifisetupを利用すれば簡単に実装できる.

import wifisetup

ただ、再接続などを実現するためにどうしても自前で実装したかったので試してみた.

from m5stack import lcd
import utime
import network


def connect_wifi(target_ssid, target_passwd, timeout_sec=10):
    wlan = network.WLAN(network.STA_IF)  # create station interface
    wlan.active(True)                    # activate the interface
    for net in wlan.scan():
        ssid = net[0].decode()
        if ssid == target_ssid:
            lcd.println('Connecting to ' + ssid)
            wlan.connect(ssid, target_passwd)
            start_date = utime.time()
            while not wlan.isconnected():
                now = utime.time()
                lcd.print('.')
                if now - start_date > timeout_sec:
                    break
                utime.sleep(1)
            if wlan.isconnected():
                lcd.println('Success to connect')
                return True
            else:
                lcd.println('Failed to connect')
                return False
    return False

helm-miniのデフォルト値にカーソルのシンボルが渡ってしまう

helm-miniC-x bに割り振ってバッファ選択に使っているのだが、現在のカーソルがある位置のシンボル(いわゆるthing-at-point)がデフォルトで渡ってしまい、バッファの選択に不自由していた.

どうやら, helm関数の:defaultキーワードを与えないと、thing-at-pointがデフォルトとして 渡ってしまう。:defaultnilだとだめなので、空文字列を渡すようにすればいい.

(defun my-helm-mini ()
  "Customized version of helm-mini in order to disable 'thing-at-point'."
  (interactive)
  (require 'helm-x-files)
  (unless helm-source-buffers-list
    (setq helm-source-buffers-list
          (helm-make-source "Buffers" 'helm-source-buffers)))
  (helm :sources helm-mini-default-sources
        :buffer "*helm mini*"
        :default "" ;; important
        :ff-transformer-show-only-basename nil
        :truncate-lines helm-buffers-truncate-lines))
(define-key global-map (kbd "C-x b")   'my-helm-mini)