Skip to content

Instantly share code, notes, and snippets.

use std::fs::File;
// Err を扱いやすくする anyhow と thiserror
use anyhow::{Context, Result};
use thiserror::Error;
/// `thiserror::Error` を derive して enum のそれぞれの要素に対して `#[error("message")]` とすることで
/// `impl fmt::Display for ApiError` に変わってエラーメッセージの振る舞いを追加することができる
#[derive(Debug, Error)]
enum ApiError {
fn add(a: i32, b: i32) -> i32 {
a + b
}
#[derive(Debug, PartialEq, Eq)]
struct Book {
name: String
}
/// `cfg()` マクロ ... 環境に応じてコンパイルを切り替える属性風マクロ
fn main() {
let input: Result<&str, &str> = Ok("test");
let input = input.unwrap(); // 回復可能なエラーも回復不可能なエラーにしてしまうので注意
println!("{:?}", input);
// let hoge: Option<&str> = Some("hoge");
let hoge: Option<&str> = None;
let hoge = hoge.expect("error!"); // エラー時に定めた文字列を出力してから panic する
println!("{:?}", hoge)
/// Rust では回復可能なエラーを Result 型で扱う
/// ```
/// enum Result<T, E> {
/// Ok<T>,
/// Err<E>,
/// }
/// ```
/// https://doc.rust-jp.rs/rust-by-example-ja/error/result.html
/// エラー発生時に即時 return したいとき、Rust では
/// Err<E> であるとき即時 return する糖衣構文 `?` が用意されている
# convert
iconv -f sjis -t utf8 {targetfile-path}
# save
iconv -f sjis -t utf8 {targetfile-path} > tmp.txt
mv tmp.txt {targetfile-path}
#!/bin/bash
# please set $VM_NAME
virt-install \
--name ${VM_NAME} \
--ram 8192 \
--disk path=/var/kvm/images/${VM_NAME}.img,size=100 \
--vcpus 4 \
--os-type linux \
--os-variant ubuntu18.04 \
# This file is generated from information provided by
# the datasource. Changes to it will not persist across an instance.
# To disable cloud-init's network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
ethernets:
enp0s25:
dhcp4: false
bridges:
#!/bin/bash
guestmount -d ${VM_NAME} -i /mnt
ln -s /mnt/lib/systemd/system/getty@.service /mnt/etc/systemd/system/getty.target.wants/getty@ttyS0.service
umount /mnt
@sudachi0114
sudachi0114 / create_kvm.sh
Last active April 21, 2021 05:08
shell script for create kvm
#!/bin/bash
virt-install \
--name ${VM_NAME} \
--ram 4096 \
--disk path=/var/kvm/images/${VM_NAME}.img,size=30 \
--vcpus 2 \
--os-type linux \
--os-variant ubuntu18.04 \
--network bridge=br0 \
@sudachi0114
sudachi0114 / docker_jupyterNotebook.md
Last active November 23, 2020 10:26
memo of how to launch jupyter notebook with docker container.

起動スクリプト ( 結論 )

docker run -v `pwd`:/home/jovyan/work -p 18888:8888 --name jpserver jupyter/scipy-notebook

この後にブラウザから localhost:18888 にアクセスすると、接続される。

Host のカレントディレクトリを docker container 内の (デフォルトの) ワーキングディレクトリにマウントしているので、 作成したノートブックはカレントに保存される。嬉しいね o(^▽^)o