リモートワークを始めて買ったもの

フットレスト

昔サンワの重々しい感じのものを使っていたが, ごついし, 固いし, 小指をぶつけたら痛いしということで処分して以降使っていなかったのだが, 家での作業が増えて検討してところよさげなものがあったので買ってみた. 感想としてはとてもよい. やわらかめで大きさも小さく, 足をぶつけても全く痛くない. 見た目も悪くない. ちょっと高めだけど, 十分その価値はあると感じる.

バリカン

美容室に行くことがリスク及び自分が害を及ぼす可能性が出てしまったので, セルフカット目的で購入. 正直安いのでよかったのだが, 手ごろな価格のものがほとんど品切れだったのと評判があんまりよくないのが多かったのでいっそのこと評価が良さげなプロ仕様のものを買った. 安いやつの 3-4倍の価格ではあるが, 1年セルフカットしたら余裕で元は取れる. 他のバリカンを知らないので適切な感想かは不明だが, 切れ味等に問題は全くなく, 難なく坊主(五分刈り)にできた. 坊主にしたのも 30数年ぶりだし, セルフカットもしたことなかったので一刈目を入れるのにすごく躊躇したが, 思い切ってバサッと入れて後戻りができない状態にしていこうはすんなり受け入れられた.

生まれて初めてのセルフカットになったわけですが, 坊主といえどきれいにやることはかなり難しく, これでいいだろうと思ってシャンプーしたら長い部分が残っていることに気づくということを 3回ほど繰り返してなんとか見た目は違和感ない程度にできた. ただそれでも後からじっくり触ってみると長さが微妙にバラバラであることに気づき, 難しさを感じた. 元の日常になったら面倒臭くて多分自分ではやらないだろうなぁと思うが, 1年はとりあえずセルフカットで済ます予定.

その他

ずっと家にいると物がたくさんあることが気になったのと, 会社マシンを家に運ぶことになったので, これを機会に諸々(古いモニタ, 使わなくなった PC etc)処分したり, スピーカを片づけたり, 配線周りをきれいにしたりした. 現状は以下のような感じ.

f:id:syohex:20200504213559j:plain

アケコンとか GCコンとかを全部無線に置き換えられたらさらにすっきりできそうなんだけど, そこはまだ代替手段がない.

Show smile in prompt if Git commit hash is lucky

Configuration

setopt re_match_pcre

## show git branch at right prompt                                                                                     
autoload -Uz vcs_info
zstyle ':vcs_info:*' formats '(%b)'
zstyle ':vcs_info:*' actionformats '[%s]-(%b|%a)'
precmd () {
  psvar=()
  LANG=en_US.UTF-8 vcs_info                                                  

  if [[ -n $vcs_info_msg_0_  ]]; then
    local rev=$(git rev-parse HEAD 2>/dev/null)
    if [[ $rev =~ '([0-9])\1{3}' ]]; then
      psvar[1]='😊 '
    fi
    psvar[2]="$vcs_info_msg_0_"
  fi                                                                                                       
}
_DIRPART=%B%{$fg[cyan]%}'[%(5~,%-2~/.../%2~,%~)]'%{$reset_color%}%b                                     
RPROMPT=%B"%1(v|%F{magenta}%1v%f%F{green}%2v%f|)"%b${_DIRPART}

Image

f:id:syohex:20200427224124p:plain

Commit ID is generated by commit_artist

Reference

zsh completion macOS screencapture command

It is bundled neither zsh sources nor zsh-completions, so I wrote it.

#compdef screencapture

__screencapture_files() {
  for ((i = 2;i < CURRENT;i++)) do
    if [[ $words[$i] == "-p" ]]; then
      return
    fi
  done

  _files
}

_arguments \
  '-c[force screen capture to go to the clipboard]' \
  '(-i -J -s -w -W)-b[capture touch bar only non interactive modes]' \
  '(-b -i -J -s -w -W)-C[capture the cursor as well as the screen only in non interactive modes]' \
  '-d[display errors to the user graphically]' \
  '(-b -C)-i[capture screen interactively. ctrl clipboard, space toggle mode, escape cancel]' \
  '-m[only capture the main monitor]' \
  '-D[screen capture or record from the display specified]:display_number:' \
  '(-b -s)-o[in window capture mode, do not capture the shadow of the window]' \
  '-p[screen capture will use the default settings for capture]' \
  '-M[screen capture output will go to a new Mail message]' \
  '-P[screen capture output will open in Preview or QuickTime Player]' \
  '-I[screen capture output will open in Messages]' \
  '-B[screen capture output will open in app with bundle ID]:bundle_id:' \
  '(-b -i -w -W)-s[only allow mouse selection mode]' \
  '-S[in window capture mode, capture the screen not the window]' \
  '-J+[sets the starting of interactive capture]:style:(selection window video)' \
  '(-p)-t[image format to create default is png]:format:(pdf jpg tiff gif)' \
  '-T+[take the picture after a delay of seconds]:seconds:' \
  '(-b -i -s -W)-w[only allow window selection mode]::->interactive' \
  '(-b -i -s -w)-W[start interaction in window selection mode]::->interactive' \
  '-x[do not play sounds]' \
  '-a[do not include windows attached to selected windows]' \
  '-r[do not add dpi meta data to image]' \
  '-l[capture this windows ID]:window_id:' \
  '(-b -i -s -w -W)-R[capture screen rect]:rect:' \
  '(-b)-v[capture video recording of the screen]::->video' \
  '-V+[limits video capture to specified seconds]:seconds:' \
  '-g[captures audio during a video recording using default input]' \
  '-G[captures audio during a video recording using audio ID specified]' \
  '-k[show clicks in video recording mode]' \
  '-U[Show interactive toolbar in interactive mode]' \
  '-u[present UI after screencapture is complete]' \
  '*:files:__screencapture_files'

WFH雑感

完全 WFHを初めて早二ヶ月が過ぎた. 結論からいると成果はそれほど上がっていないのだが, その中で私が試したことについて示す. 今月半ばぐらいからぼちぼち改善しているような気はするので引き続き改善を行っていきたい

早寝早起き生活に変えた

オフィスに通っていた頃はひどいときだと朝 3 - 4時ぐらいに寝て, 10時頃に起きて, 1時間ぐらいで仕度してオフィスに行くということをしていたが, 家で仕事をするとなるとだらけてしまい 10時に起きたら仕事のやる気が出てくるのが 13時-14時になってしまってい, 焦りを生んでいたのでそれを改めるために早寝早起き生活にシフトした. 当然突然切り替えられるわけはなかったが, 1ヶ月ぐらいで徐々に早寝早起きできるようになり, 今では 1時までには寝て, 7時程度には起きられるようになった. これで朝だらけたいなぁと思っても 1-2時間の余裕があるので 10時程度には仕事モードに切り替えられるようになり気分的に楽になった.

slackのチャネルからひたすら leave

仕事に直接的に関係ないチャネルからほとんど leaveした. 会社の workspaceも privateで入っている workspaceも. times channel, 雑談チャネル, 会社の偉い人のチャネル, あまり興味ない技術チャネルなどなどひたすら leave. みんな WFHだと雑談チャネルとかオフィスにいたときでは出てこなかった話題がたくさん出て興味深く面白いわけだが, その手のものを見るといくらでも時間を潰せるし, いくらでも気が散るので見ないようにした. 最悪メンションなり DMが来るだろうの精神. 現状だらだらと slackチャネル巡りをするということはほぼなくなった

SNSの見直し

気が散るのもあるが, 時期が時期でありやたらと政治的な意見が増えた人がいる. 語るのは悪くないが, あの人そんな思想だったんだ, とか知りたくもことが多々ありメンタル的にもよくないので, その手の人は積極的に unfollow, blockするなどするようにした. 技術的な知見を得る機会は減るかもしれないが, メンタルがすり減らされるよりはよほどマシである.

ゲームを控える

オフィスに通っていた頃は, オフィスに行けば仕事モードに切り替えられるので, 家でゲームをしても会社でやりたいと思うことは皆無だったが, ずっと家にいると仕事中でも続きが気になるとなってしまい, 仕事が手につかない. 現在ワンルームのせまい部屋で生活しており, ゲーム環境 = 仕事環境であり, 眼の前に switch(+GCコン), PS4(アケコン)がある中で仕事をせざるを得ないのでなるべくゲームのことを考えなく済むようゲームを控えるようにした. (フィットボクシング, リングフィットアドベンチャー除く. FF7Rは買ってまで 2日かやっていないが特に禁断症状的なものは出ていない. 代わりにといってはあれだが, ここ数年間ろくに家で勉強していなかったが, 勉強時間を取るようにした.

その他

tagomoris.hatenablog.com

上記にあるように現状成果が十分でないことを認めないといけないと考えるが, いつまでもというわけにはいかないし, 自虐的な私は特にそういう状況にいつまでも耐えられると思えないので, 少しずつ改善していきたいと考える.

strlen for string literal

Environment

Sample code

#include <string.h>

size_t string_const_size() {
    return strlen("hello world");
}

Compile with gcc -O0

gcc -O0 -c strlen.c
objdump -S strlen.o
strlen.o:     file format elf64-x86-64


Disassembly of section .text:

0000000000000000 <string_const_size>:
   0:   f3 0f 1e fa             endbr64 
   4:   55                      push   %rbp
   5:   48 89 e5                mov    %rsp,%rbp
   8:   b8 0b 00 00 00          mov    $0xb,%eax ;; 0xb=11 is string length of "hello world"
   d:   5d                      pop    %rbp
   e:   c3                      retq   

strlen for string literal is calculated at compiling time even if optimization is disabled

Compile with clang -O0

I got same result as gcc

strlen.o:     file format elf64-x86-64


Disassembly of section .text:

0000000000000000 <string_const_size>:
   0:   55                      push   %rbp
   1:   48 89 e5                mov    %rsp,%rbp
   4:   b8 0b 00 00 00          mov    $0xb,%eax ;; here
   9:   5d                      pop    %rbp
   a:   c3                      retq   
   b:   0f 1f 44 00 00          nopl   0x0(%rax,%rax,1)

Compile with gcc -O0 -fno-builtin

It looks strlen is called

strlen.o:     file format elf64-x86-64


Disassembly of section .text:

0000000000000000 <string_const_size>:
   0:   f3 0f 1e fa             endbr64 
   4:   55                      push   %rbp
   5:   48 89 e5                mov    %rsp,%rbp
   8:   48 8d 3d 00 00 00 00    lea    0x0(%rip),%rdi        # f <string_const_size+0xf>
   f:   e8 00 00 00 00          callq  14 <string_const_size+0x14>
  14:   5d                      pop    %rbp
  15:   c3                      retq   

Summary

I suppose I can use strlen for litaral string without runtime overhead and I don't need hack as below

const size_t some_length = sizeof("Hello World") -1;

Build GCC 4.9.4 x86_64 on Ubuntu 19.10

Apply patch

libgcc of gcc4.9.4 has issue on newer environment

diff -ur gcc-4.9.4/libgcc/config/i386/linux-unwind.h new-gcc-4.9.4/libgcc/config/i386/linux-unwind.h
--- gcc-4.9.4/libgcc/config/i386/linux-unwind.h   2014-01-03 07:25:22.000000000 +0900
+++ new-gcc-4.9.4/libgcc/config/i386/linux-unwind.h   2020-04-17 11:25:54.600423882 +0900
@@ -58,7 +58,7 @@
   if (*(unsigned char *)(pc+0) == 0x48
       && *(unsigned long long *)(pc+1) == RT_SIGRETURN_SYSCALL)
     {
-      struct ucontext *uc_ = context->cfa;
+      ucontext_t *uc_ = context->cfa;
       /* The void * cast is necessary to avoid an aliasing warning.
          The aliasing warning is correct, but should not be a problem
          because it does not alias anything.  */
@@ -138,7 +138,7 @@
    siginfo_t *pinfo;
    void *puc;
    siginfo_t info;
-  struct ucontext uc;
+   ucontext_t ucontext uc;
       } *rt_ = context->cfa;
       /* The void * cast is necessary to avoid an aliasing warning.
          The aliasing warning is correct, but should not be a problem

Configure & make

# apply patch
cd gcc-4.9.4
mkdir build
cd build
../configure --prefix=$HOME/local/gcc-4.9 --enable-languages=c --disable-multilib --disable-libsanitizer
make
make install

libsanitaizer of gcc 4.9.4 cannot be built with recent glibc.

Minimum setup for node native module development with VScode

It is difficult to develop node native module without IDE. Because V8 API is difficult to use, complicated, often changed. node-gyp can generate Visual Studio solution file but other IDE is not supported well. I show how to setup writing native module on VScode

Install node headers

Install header files of node.js via node-gyp configure

node header is installed under user cache directory

  • Windows %LOCALAPPDATA%\Cache\node-gyp
  • macOS ~/Library/Caches/node-gyp
  • Linux ~/.cache/node-gyp

Set include paths

Do C/C++: Edit configurations (JSON) via command palette and open c_cpp_properties.json.

Add above header path to includePath list

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**",
                "${env:HOME}/.cache/node-gyp/12.16.1/include/node" // 12.16.1 is node version, you need to change to your node version
            ],
            "defines": [],
            "compilerPath": "/usr/bin/clang",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "clang-x64"
        }
    ],
    "version": 4
}

Screenshot

f:id:syohex:20200405153245g:plain

Enjoy