version: '3'
services:
ubuntu:
build:
context: .
dockerfile: Dockerfile
container_name: ubuntu-test
stdin_open: true # docker run -i
tty: true # docker run -t
platform: linux/amd64
entrypoint: bin/bash
volumes:
- "/run/host-services/ssh-auth.sock:/tmp/ssh-agent.sock"
environment:
SSH_AUTH_SOCK: "/tmp/ssh-agent.sock"
最後のvolumeとenvironment がポイント。これはmacでのやり方なので、
linuxだとまた違うようだ。
2023年11月14日火曜日
docker のコンテナからホストのssh-agentを使う
docker を開発環境として使う場合、内部からsshにアクセスしたくなるが .ssh をbindマウントしたり、コピーしたりするのも面倒。
どうするのが正解なのかと思っていたら普通にホストのssh-agentを使う機能が用意されていた。すごいな。
2023年4月19日水曜日
seleniumでasciidocファイルをPDFに変換
これには
- selenium に asciidoctor extension を入れる
- PDFを指定して印刷する
Selenium に extensionを入れる
これには、- extensionのcrxファイルを入手する
- crxファイルを指定してドライバをつくる
crxファイルの入手
crxファイルを入手する方法は このブログ に書かれている。ダウンロードをやってくれるサイトがあるらしいのだが、ドメインが切れたらしく 怪しいことになっていたので、再パッケージする方法を使う。 基本的には、chromeのextension のページで、pack extension ボタンで、導入されているextensionのパスを指定すれば いいのだが、そのパスがわからない。そんなときは、 chrome://version のProfilePathを見ればわかる。この下のExtensions以下にIDのディレクトリがある。 ディレクトリ名はIDだが、個々のExtensionのIDはchromeのextensionsのページ chrome://extensions/ を見ればわかる。 manifest.jsonにも アプリ名が入っているはずなのだが、メッセージファイルを参照している場合もあるようで、grepしてもわからない。ドライバをつくる
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options=Options()
options.add_extension(pathToExtension)
driver = webdriver.Chrome("./chromedriver", options=options)
PDFを指定して印刷
こちらのサイトに書いてある。 しかしこれどうやって調べたんだろう。どこに書いてあるのかなあ。。注意点としては、savefile.default_directory の指定はどうも絶対パスでないといけないようなので、 Pathを使って作ってやる必要がある。
pathToExtension="2.7.0_0.crx"
def optionsSetUp():
#印刷としてPDF保存する設定
options=Options()
appState = {
"recentDestinations": [
{
"id": "Save as PDF",
"origin": "local",
"account":""
}
],
"selectedDestinationId": "Save as PDF",
"version": 2,
"isLandscapeEnabled": False, #印刷の向きを指定 tureで横向き、falseで縦向き。
"pageSize": 'A4', #用紙タイプ(A3、A4、A5、Legal、 Letter、Tabloidなど)
"isHeaderFooterEnabled": False, #ヘッダーとフッター
"isCssBackgroundEnabled": True, #背景のグラフィック
"isCollateEnabled": True #部単位で印刷
}
prefs = {'printing.print_preview_sticky_settings.appState':
json.dumps(appState),
"savefile.default_directory": str(Path('../rendered').resolve())
} #appState --> pref
options.add_experimental_option('prefs', prefs)
options.add_argument('--kiosk-printing')
options.add_extension(pathToExtension)
return options
driver = webdriver.Chrome("./chromedriver", options=options)
driver.get(URL)
time.sleep(2) # ページが確実にレンダリングされるのを待つ
driver.execute_script('window.print();')
2023年2月11日土曜日
chrome extention vimium
chrome をキーボード操作したい、という欲求が定期的に出てくる。いろいろ試して、だいたいなんか予想外の挙動が起きてはずしているのだけど、今度はvimiumというものを試してみる。ちょっと試した感じではGmailではキーイベントを取られてしまって動かないっぽい。
こちら にある。
チートシート を転載しておこう。なんかありすぎて わからないが、とりあえずFでリンクが出るのと、
HL でヒストリ移動、JKでタブ移動だけでも、便利。エスケープでモードから抜ける。
? show the help dialog for a list of all available keys
h scroll left
j scroll down
k scroll up
l scroll right
gg scroll to top of the page
G scroll to bottom of the page
d scroll down half a page
u scroll up half a page
f open a link in the current tab
F open a link in a new tab
r reload
gs view source
i enter insert mode -- all commands will be ignored until you hit Esc to exit
yy copy the current url to the clipboard
yf copy a link url to the clipboard
gf cycle forward to the next frame
gF focus the main/top frame
newpage
o Open URL, bookmark, or history entry
O Open URL, bookmark, history entry in a new tab
b Open bookmark
B Open bookmark in a new tab
find系
/ enter find mode
-- type your search query and hit enter to search, or Esc to cancel
n cycle forward to the next find match
N cycle backward to the previous find match
history
H go back in history
L go forward in history
tab
J, gT go one tab left
K, gt go one tab right
g0 go to the first tab. Use ng0 to go to n-th tab
g$ go to the last tab
^ visit the previously-visited tab
t create tab
yt duplicate current tab
x close current tab
X restore closed tab (i.e. unwind the 'x' command)
T search through your open tabs
W move current tab to new window
pin/unpin current tab
2023年1月28日土曜日
visual studio の単語区切り
visual studio には単語単位のforward backward 等があるが、
日本語の編集中にはあんまりうまく機能しない。
藤井大洋先生が、形態素解析を行うランゲージサーバでいれてなにかされている
ようだがそれは後で試すとして、とりあえず、単語区切りに「を」とか「が」とか「、」「。」あたりを入れるとちょっとましになる。ちょっとだけど。
こちら を参考に。
2023年1月15日日曜日
SVGファイルの周りを削除
http://alexlenail.me/NN-SVG/LeNet.html
で作った画像はSVGになるのだけど、大きい紙の真ん中に書かれている形になるので、
取り込むと周囲に空白ができて困る。bounding box で crop する方法を調べたら
あっさり
stack overflow にあった。便利だ。。
inkscape -o cropped.svg -D source.svg
2023年1月7日土曜日
jupyter nbconvert でベクタ図入りのノートブックを変換する
nbconvertはpdfやらsvgやらが入ったノートブックを変換すると、inkscapeを使用するらしく、こんなエラーがでる。
FileNotFoundError: [Errno 2] No such file or directory: 'inkscape'なので、inkscape をインストールして、下のようにしてpathを通す。inkscapeは、app storeからは インストールできないみたいなので、webページからダウンロードした。
ln -s /Applications/Inkscape.app/Contents/MacOS/inkscape \
/usr/local/bin/inkscape
nbconvert の日本語対応
こちらの記事に
まとまっている。 テンプレートファイル index.tex.j2 というファイルを見つけて
\documentclass[11pt]{article}
となっているところを、
\documentclass[xelatex,ja=standard]{bxjsarticle}
と直せばいいのだけど、このindex.tex.j2がどこにあるのかわからない。
こちらにあるように、
$ jupyter nbconvert --to pdf filename.ipynb --debugのようにdebugオプションをつけると、templateを探しに行くパスが表示されるのでそこを見ていけばいい。のだが、めちゃめちゃ数が多くてたいへんだった。
登録:
投稿 (Atom)