金魚亭日常

読書,ガジェット,競技プログラミング

SonicPi 起動できない問題

Windows 10, Sonic Pi 3.1.0

ポート関係は OK だが Sonic Pi Server が起動しなかった.

よく見ると,オーディオ関係のところでエラーが出ている.

issue 見に行くと 同じような症状で起動しないって言ってる人が多いみたい. で,オーディオ関係のエラーに関するこの issue

github.com

にある通り, ASIO ドライバを入れて,ソースコードの該当箇所(Ruby)をサーバー起動時の引数にASIOを使うように修正すると,起動するようになった.

ggplot2 の軸をいじる

boxplot をグループごとに並べて表示したときに legend をx軸にもってきたい,とかいうことが起こった場合,描画された各要素の座標を取ってくればできるのではないか,とやってみた実験.

実用的には,パワポとかで編集した方がはやい.

gtable にして中身をしらべる. grob のid がプロットごとに変わるので,grep してがんばる. 文字の大きさとかはもう少しいい感じにできると思う.

Before

gyazo.com

After

gyazo.com

 library("ggplot2")
 library("dplyr")
 library("grid")
 library("stringr")
 library("purrr")
 
 # 元のグラフ
 gp <- ggplot(data = iris, aes(Species, Sepal.Length)) +
   geom_boxplot(aes(colour = Sepal.Width < 3.2)) + 
   scale_x_discrete(name="")
 gp
 
 # 種名(後で使う)
 species_names <- c("setosa", "versicolor", "virginia")
 
 # ggplot の各レイヤーの情報を取得
 gt <- ggplotGrob(gp)
 
 # 各ボックスプロットの座標を取得
 # レイヤー名などは毎回変わる
 # 6番目のpanel 指定
 # gt$grobs[[6]]
 # そこから children をたどって geom_boxplot.gTree.xxx というのを探す
 # これの children が boxplot を描画している要素 
 # 各boxplot の children から segment を探す
 ## segment はエラーバーを描画している
 ## ない場合は boxplot の頂点の座標から計算する
 # segment の x0 が求めたい座標
 
 filter_child <- function(node, pattern){
   node %>% 
     pluck("children") %>% 
     attributes() %>% 
     pluck("names") %>% 
     str_subset(pattern)
 }
 
 
 filter_grobs <- function(node, pattern){
   node %>% 
     pluck("grobs") %>% 
     map_chr(function(x){
       x$name
     }) %>% 
     str_which(pattern)
 }
 
 id.panel <- grep("panel", gt$layout$name)
 
 geom_boxplot_name <- gt$grobs[[id.panel]] %>% 
   filter_child("^geom_boxplot.gTree")
 
 x <- gt$grobs[[id.panel]] %>% 
   pluck("children") %>% 
   pluck(geom_boxplot_name) %>% 
   pluck("children") %>% 
   map_dbl(function(x){
     grid_segments_name <- x %>% 
       filter_child("^GRID.segments")
     x %>% 
       pluck("children") %>% 
       pluck(grid_segments_name) %>% 
       pluck("x0") %>% 
       pluck(1)
   }) %>% 
   unit("native")
 
 # 軸の情報を変更
 # ラベルのx座標
 id.axis <- grep("axis-b", gt$layout$name)
 id.axis_text_x_bottom <- filter_grobs(gt$grobs[[id.axis]]$children$axis, "^axis.text.x.bottom..titleGrob")
 grid_text_name <- gt$grobs[[id.axis]]$children$axis$grobs[[id.axis_text_x_bottom]] %>% 
   filter_child("^GRID.text")
 
 x_org <- unit(gt$grobs[[id.axis]]$children$axis$grobs[[id.axis_text_x_bottom]]$children[[grid_text_name]]$x, "native")
 
 gt$grobs[[id.axis]]$children$axis$grobs[[id.axis_text_x_bottom]]$children[[grid_text_name]]$x <- unit.c(x, x_org)
 
 # ラベル名
 l <- c("FALSE", "FALSE", "FALSE", "TRUE", "TRUE", "TRUE")
 gt$grobs[[id.axis]]$children$axis$grobs[[id.axis_text_x_bottom]]$children[[grid_text_name]]$label <- c(l, species_names)
 
 # ラベルのy座標
 y <- rep(unit(1, "npc"), 6)
 gt$grobs[[id.axis]]$children$axis$grobs[[id.axis_text_x_bottom]]$children[[grid_text_name]]$y <- unit.c(y, unit(rep(0, 3), "npc"))
 
 
 # x軸目盛(tick)の変更
 # x座標
 id.axis_ticks_x_bottom <- filter_grobs(gt$grobs[[id.axis]]$children$axis, "^axis.ticks.x.bottom")
 gt$grobs[[id.axis]]$children$axis$grobs[[id.axis_ticks_x_bottom]]$x <- sort(rep(x, 2))
 
 # y座標
 gt$grobs[[id.axis]]$children$axis$grobs[[id.axis_ticks_x_bottom]]$y <- rep(gt$grobs[[id.axis]]$children$axis$grobs[[id.axis_ticks_x_bottom]]$y, 2)
 
 # id.length?
 gt$grobs[[id.axis]]$children$axis$grobs[[id.axis_ticks_x_bottom]]$id.lengths <- c(2, 2, 2, 2, 2, 2)
 
 plot(gt)

VSCode の Solargraph がいくつも起動してしまう問題

VSCodeRuby 書くときに使っている Solargraph ,別のフォルダを開いたり,Window をリロードすると solargraph server が終了せずに新しく起動してしまう,という問題があったが, gem 0.31.0 でなおった.

vscode extention の方に issue 報告したけど,gem の方でなおったようだ.

2018年に読んだ本

ブクログによると,86冊読んで うち59冊がマンガだったらしい.

今年は 後半にMediamarker から ブクログに移動した. ブクログは レビュー主体というのと メニューがどこに何があるかよくわからない というのでやめていたのだが,仕方ない.

マンガ以外からベスト3を挙げようとしたがシリーズものしかほとんど読んでなくて,

  1. Wシリーズ
  2. ヴォイド・シェイパ
  3. ゲド戦記

だった.

ノンフィクションだと,『デジタル・ゴールド』と『人間をお休みしてヤギになってみた結果』も良かったが,『うつ病九段』 が圧倒的.

2018年12月に読んだ本

マンガばっかり

whattalnkの本棚 - 2018年12月 (7作品)
powered by Booklog

YubiKey 買った

正確には セキュリティキー by Yubico です.

2段階認証,スマホGoogle Authenticater にあるけど,スマホを失くした場合とか,機種変のときとかにめんどくさいので 前から検討していたところに zaim のブログに記事が出ていたので,思い切って購入.

https://blog.zaim.co.jp/n/n8d318075d8d2blog.zaim.co.jp

とりあえず GoogleGithubDropbox を設定. lastpass と bitwarden はプレミアムにしないと使えないっぽかった. Microsoft アカウントは使えないらしい.

メインブラウザがFirefox な人は, about.config で設定しないと使えない. 設定すると Chrome 使いましょう,みたいな表示はでなくなる.

https://support.yubico.com/support/solutions/articles/15000017511-enabling-u2f-support-in-mozilla-firefoxsupport.yubico.com

www.reddit.com

www.yubico.com