牌語備忘録 -pygo

あくまでもメモです。なるべくオフィシャルの情報を参照してください。

牌語備忘録 -pygo

Emacs の whitespace-mode でタブと行末スペースと全角スペースに色付けするメモ

今まで font-lock で色つけたけど whitespace-mode に乗り換えた。

f:id:CortYuming:20160717170952p:plain

(progn
  (require 'whitespace)
  (setq whitespace-style
        '(
          face ; faceで可視化
          trailing ; 行末
          tabs ; タブ
          spaces ; スペース
          space-mark ; 表示のマッピング
          tab-mark
          ))
  (setq whitespace-display-mappings
        '(
          (space-mark ?\u3000 [?\u2423])
          (tab-mark ?\t [?\u00BB ?\t] [?\\ ?\t])
          ))
  (setq whitespace-trailing-regexp  "\\([ \u00A0]+\\)$")
  (setq whitespace-space-regexp "\\(\u3000+\\)")
  (set-face-attribute 'whitespace-trailing nil
                      :foreground "RoyalBlue4"
                      :background "RoyalBlue4"
                      :underline nil)
  (set-face-attribute 'whitespace-tab nil
                      :foreground "yellow4"
                      :background "yellow4"
                      :underline nil)
  (set-face-attribute 'whitespace-space nil
                      :foreground "gray40"
                      :background "gray20"
                      :underline nil)
  (global-whitespace-mode t)
  )

参考

Python で Ruby の each_slice みたいなやつメモ

(python2.7)

def each_slice(arr, n):
    return [arr[i:i + n] for i in range(0, len(arr), n)]

print(each_slice([1, 2, 3, 4, 5], 2))
print(each_slice([1, 2, 3, 4, 5], 3))
print(each_slice([1, 2, 3, 4, 5], 4))
# => [[1, 2], [3, 4], [5]]
# => [[1, 2, 3], [4, 5]]
# => [[1, 2, 3, 4], [5]]

参考