haiju's 開発メモ

開発に必要な情報を自分用にメモ

ssh接続でプライベートリポジトリにバックアップ作成

ようやくBitbucketにssh接続できるようになったので、

ローカルのターミナル環境からブラウザにアクセスせず

sshのみでバックアップしてみるテスト。

[手順]

1. バックアップしたいプロジェクトディレクトリへ移動し、以下実行。

% cd helloFParsecTest

% git init

Initialized empty Git repository in $HOME/workspace/helloFParsecTest/.git/

2. リモートのマスターリポジトリを設定。

% git remote add origin ssh://git@bitbucket.org/username/hellofparsectest.git

3. 1のプロジェクトを2に追加、push。

% git add .

% git commit
[master (root-commit) 40f7f14] helloFParsecTest created
6 files changed, 127 insertions(+)
create mode 100644 helloFParsecTest.sln
create mode 100644 helloFParsecTest.userprefs
create mode 100644 helloFParsecTest/AssemblyInfo.fs
create mode 100644 helloFParsecTest/Main.fs
create mode 100644 helloFParsecTest/MainWindow.fs
create mode 100644 helloFParsecTest/helloFParsecTest.fsproj

% git push origin master

Counting objects: 9, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (9/9), done.
Writing objects: 100% (9/9), 2.38 KiB | 0 bytes/s, done.
Total 9 (delta 0), reused 0 (delta 0)
To ssh://bitbucket.org/username/hellofparsectest.git
* [new branch] master -> master
Branch master set up to track remote branch master from origin.

[参考サイト]

qiita.com

bitbucketに鍵を登録してssh接続可能にする

個人開発のためにbitbucketにアカウントを作って

勉強してることをどんどんバックアップするのをもっと

手軽にしたいということで、ssh接続を設定する方法に

ついて調べたのでまとめる。

※基本的に、mercurialもgitも同じ。

[手順]

1. 開発PCのhomeディレクトリで鍵を生成。

% mkdir .ssh

% cd .ssh/

% ssh-keygen -t rsa -f id_rsa

パスフレーズなし 

2. 秘密鍵の登録。

 ssh接続時にid_rsaを指定したアドレスで使うように登録。

2-1. 秘密鍵のアクセス権を変更。

% chmod 600 id_rsa

2-2. .ssh/configファイルに下記を追記。

Host bitbucket.org

     HostName bitbucket.org

     IdentityFile ~/.ssh/id_rsa

     User hg

2-3. .sshディレクトリのアクセス権を変更。

% chmod 700 .ssh 

3. 公開鍵の登録

URLは「https://bitbucket.org/account/user/username/ssh-keys

3-1.「アカウントの管理」から「鍵を追加」をクリックして公開鍵

  を登録。

3-2. Labelの欄には分かりやすいように開発PCの名前を入力。

 (ex) my_vaio_duo11

3-3. 公開鍵(id_rsa.pub)を開いてラベルの下の欄にコピペ。

% cat ~/.ssh/id_rsa.pub 

4. 疎通確認とサーバ登録

4-1. 疎通確認のため、以下を実行。

ssh -v -T hg@bitbucket.org 

 接続すると can't be established などと言われて、続けるか?と

 聞かれるので、「yes」を選択すると、~/.ssh/known_host に

 サーバが登録される。

4-2. BitbucketにSSH接続を試みて、以下のようになれば正しく接続できている。

debug1: Authentication succeeded (publickey).

Authenticated to bitbucket.org ([104.192.143.2]:22).

... (省略)

debug1: client_input_channel_req: channel 0 rtype exit-status reply 0

logged in as username(account).

You can use git or hg to connect to Bitbucket. Shell access is disabled.

5.  終わったら、とりあえずもう一度、確認してみる。

ssh -v -T hg@bitbucket.org

6. bitbucketにログインして、リポジトリのClone部分のプルダウンが

 SSHを選択されててURLがsshで開始されているのを確認できればOK。

(ex) ssh://hg@bitbucket.org/username/docs

[参考サイト]

qiita.com

qiita.com

qiita.com

RustのWebフレームワークRocket.rsを試してみる

この記事はRust その2 Advent Calendar 2016 の24日目の記事です。

自分がRustでやってみたいと思っていたことはWebアプリの

開発です。

それで、たまたまTwitterを見ていたら、Rocket.rsという新しい

フレームワークを知ったので、早速、Hello Worldを表示する

サンプルプログラムを作ってみます。

[手順]

※前提条件

RocketにはNightly版のRustが必要とQuickstartの冒頭に

書いてあることに注意。

(見落としていたため、stable版で大量のエラーを吐いたw)

1. RustのNightlyの最新をインストールする必要があるので以下

 コマンドを実行。

% rustup default nightly

info: syncing channel updates for 'nightly-x86_64-unknown-linux-gnu'
info: downloading component 'rustc'
51.7 MiB / 51.7 MiB (100 %) 1.5 MiB/s ETA: 0 s
info: downloading component 'rust-std'
71.7 MiB / 71.7 MiB (100 %) 3.1 MiB/s ETA: 0 s
info: downloading component 'cargo'
4.0 MiB / 4.0 MiB (100 %) 1.2 MiB/s ETA: 0 s
info: installing component 'rustc'
info: installing component 'rust-std'
info: installing component 'cargo'
info: default toolchain set to 'nightly-x86_64-unknown-linux-gnu'

 

nightly-x86_64-unknown-linux-gnu installed - rustc 1.15.0-nightly (71c06a56a 2016-12-18)

2. バージョンを確認。

% rustc --version

rustc 1.15.0-nightly (71c06a56a 2016-12-18)  --- 最新であることを確認

3. cargoコマンドでhello-rocketプロジェクトを作成し、hello-rocketディレクト

 へ移動。

% cargo new hello-rocket --bin

     Created binary (application) `hello-rocket` project

% cd hello-rocket

4. Getting Startedにある通りにCargo.toml の[dependencies]にRocketを追加。

[dependencies]
rocket = "0.1.1"
rocket_codegen = "0.1.1"

5. src/main.rs を以下の通りに書き換えて保存。

#![feature(plugin)]
#![plugin(rocket_codegen)]


extern crate rocket;

#[get("/")]
fn index() -> &'static str {
     "Hello, world!"
}

fn main() {
       rocket::ignite().mount("/", routes![index]).launch();
}

6. cargo run で実行すると、4で追加したWebフレームワークの

 rocketと依存ライブラリのインストールが始まる。

% cargo run
Updating registry `https://github.com/rust-lang/crates.io-index`
Downloading rocket_codegen v0.1.1
Downloading rocket v0.1.1
Compiling typeable v0.1.2
Compiling unicode-normalization v0.1.3
Compiling rustc-serialize v0.3.22
Compiling log v0.3.6
Compiling matches v0.1.4
Compiling unicode-bidi v0.2.4
Compiling traitobject v0.0.1
Compiling httparse v1.2.1
Compiling semver v0.1.20
Compiling libc v0.2.18
Compiling mime v0.2.2
Compiling num_cpus v1.2.0
Compiling rustc_version v0.1.7
Compiling idna v0.1.0
Compiling language-tags v0.2.2
Compiling unicase v1.4.0
Compiling hpack v0.2.0
Compiling url v1.2.4
Compiling winapi v0.2.8
Compiling solicit v0.4.4
Compiling winapi-build v0.1.1
Compiling toml v0.2.1
Compiling kernel32-sys v0.2.2
Compiling term v0.4.4
Compiling time v0.1.35
Compiling cookie v0.2.5
Compiling term-painter v0.2.3
Compiling hyper v0.9.14
Compiling rocket v0.1.1
Compiling rocket_codegen v0.1.1
Compiling hello-rocket v0.1.0 (file:///home/haiju/workspace/hello-rocket)
Finished debug [unoptimized + debuginfo] target(s) in 52.51 secs
Running `/home/haiju/workspace/hello-rocket/target/debug/hello-rocket`

Finished debug [unoptimized + debuginfo] target(s) in 52.51 secs
Running `/home/haiju/workspace/hello-rocket/target/debug/hello-rocket`
 🔧 Configured for development.
 => listening: localhost:8000
 => logging: Normal
 🛰 Mounting '/':
 => GET /
 🚀 Rocket has launched from http://localhost:8000...
 GET /:
 => Matched: GET /
 => Outcome: Succcess
 => Response succeeded.

7. ブラウザで http://localhost:8000/ にアクセスし、Hello, World! が表示されて

 いればOK。

f:id:haiju:20161225024748j:plain

一番後発ってこともあるのか?分かりやすいなーって印象。

ただ、Nightlyの最新が必要ってことを除けばだけど。

追っかけてみたいなーって思った。

次はChatアプリとか書いてみたいなー。

[参考サイト]

rocket.rs

Nim の GUIライブラリ nimxをインストールしてサンプルコードを動かしてみる(2) 補足追加

この記事はNim Advent Calendar 2016 23日目の記事です。

NimにはGUIライブラリとしてnimxがあり、このブログでも

某勉強会用の資料作成のために3月に書いた記事でも触れて

います。

では本題に入り、環境が変わっているため、Nim 0.15.2の

最新でインストール&動作確認をする手順から。

[インストール]

1. 最新の0.15.2からNim本体にパッケージングされたパッケージマネージャ

 のnimbleを使い下記コマンドでnimxをインストール。

% nimble install nimx

2. とりあえずインストールログを確認。

 Prompt: No local packages.json found, download it from internet? [y/N]
 Answer: y
Downloading Official package list
Success Package list downloaded.
Downloading https://github.com/yglukhov/nimx using git
Verifying dependencies for nimx v0.1
Installing sdl2 (any version)
Downloading https://github.com/nim-lang/sdl2 using git
Verifying dependencies for sdl2 v1.1
Installing sdl2 v1.1
Success: sdl2 installed successfully.
Installing opengl (>= 1.1)
Downloading https://github.com/nim-lang/opengl using git
Verifying dependencies for opengl v1.1.0
Installing x11 (any version)
Downloading https://github.com/nim-lang/x11 using git
Verifying dependencies for x11 v1.0
Installing x11 v1.0
Success: x11 installed successfully.
Installing opengl v1.1.0
Success: opengl installed successfully.
Installing nimsl (>= 0.2 & < 0.3)
Downloading https://github.com/yglukhov/nimsl using git
Verifying dependencies for nimsl v0.2
Installing nimsl v0.2
Success: nimsl installed successfully.
Installing jnim (any version)
Downloading https://github.com/vegansk/jnim using git
Verifying dependencies for jnim v0.2.5
Installing nimfp (>= 0.1.0)
Downloading https://github.com/vegansk/nimfp using git
Verifying dependencies for nimfp v0.3.5
Installing nimboost (>= 0.3.2)
Downloading https://github.com/vegansk/nimboost using git
Verifying dependencies for nimboost v0.3.4
Tip: 80 messages have been suppressed, use --verbose to show them.
Error: Traceback (most recent call last)
 ... nimble.nim(1034) nimble
 ... nimble.nim(967) doAction
 ... nimble.nim(600) install
 ... nimble.nim(407) installFromDir
 ... nimble.nim(283) processDeps
 ... nimble.nim(600) install
 ... nimble.nim(407) installFromDir
 ... nimble.nim(283) processDeps
 ... nimble.nim(600) install
 ... nimble.nim(407) installFromDir
 ... nimble.nim(283) processDeps
 ... nimble.nim(600) install
 ... nimble.nim(407) installFromDir
 ... nimble.nim(276) processDeps
 ... Unsatisfied dependency: nim (>= 0.15.3)

3. --verboseをつけて、問題になった依存パッケージから再インストール。

% nimble install jnim --verbose
Reading official package list
Downloading https://github.com/vegansk/jnim using git
Cloning latest tagged version: v0.2.5
Verifying dependencies for jnim v0.2.5
Loading list of installed packages
Checking for nimfp (>= 0.1.0)
Installing nimfp (>= 0.1.0)
Reading official package list
Downloading https://github.com/vegansk/nimfp using git
Cloning latest tagged version: v0.3.5
Verifying dependencies for nimfp v0.3.5
Loading list of installed packages
Checking for nimboost (>= 0.3.2)
Installing nimboost (>= 0.3.2)
Reading official package list
Downloading https://github.com/vegansk/nimboost using git
Cloning latest tagged version: v0.3.4
Verifying dependencies for nimboost v0.3.4
Loading list of installed packages
Error: Traceback (most recent call last)
... nimble.nim(1034) nimble
... nimble.nim(967) doAction
... nimble.nim(600) install
... nimble.nim(407) installFromDir
... nimble.nim(283) processDeps
... nimble.nim(600) install
... nimble.nim(407) installFromDir
... nimble.nim(283) processDeps
... nimble.nim(600) install
... nimble.nim(407) installFromDir
... nimble.nim(276) processDeps
... Unsatisfied dependency: nim (>= 0.15.3) --- 0.15.3?

4. やっぱり同じ作者の3つのパッケージでエラーが発生

 している模様・・・(ΦωΦ;

インストールについては以上になりますwww

詳細についてはgithubのnimbleのソースコードとエラーが

発生した場所を丹念に見ていくしかないなー。

それとも、Nim本体に内包されたnimbleでは問題がある

のかしら?

いずれにしても、あとで詳しくかー。

前回は、インストールに成功しgithubのREADME.rst

一部の機能が検証できなかったものの、だいたい試せた

ので、これからに期待していたんだけど、今回はバージョンアップした

nimxの依存パッケージのインストールエラーで早々に終了したので

Nimでクロスプラットフォーム開発の夢が少し頓挫してしまったようなw

詳しい使い方のドキュメントより、パッケージが依存している

ライブラリの提示がREADME.rst(md)にあればいいんだけどな。

[補足]

この後、少ししてNim開発版で 0.15.3がリリースされたので、これは

インストールできるかもな希望が湧いて来たため、確認でき次第、

内容を更新予定です。

※新しいバージョンで再検証した結果は以下の記事にまとめました。

haiju.hatenablog.com

 

[参考サイト]

github.com

github.com

github.com

github.com

github.com

github.com

出遅れたけどElmプログラミングことはじめ

自分が使ってるManjaro Fluxbox 15.12(kernel 4.4.x)

では長らくnode.jsとnpmとElmやPureScriptの相性が

悪くて途中でインストールエラーでコケて入らない

状態だったのが、lts-boronになってエラーも解消されて

インストールできるようになったので記念カキコ。

Elm自体も0.18.0で大きく機構が変わったようなので

公式チュートリアルのサンプルコードが動くかどうか

不安だったけど(ΦωΦ)

スペルの入力ミスがなければあっけなく終わったので

これから試したいことをいろいろ実験できる。

ではインストールから備忘録としてまとめる。

[手順]

※前提条件

nodejs-lts-boronとnpmが入っていること。

1. npm でelmをインストール。

% sudo npm install -g elm

-g にするとシステム全体にインストール。

2. 勉強用のディレクトリを作成して移動。

% mkdir elm-project && cd elm-project 

3. 早速、Main.elmを作成し公式チュートリアルのA Quick Sample

 を写経(内容は数値を増減するカウンターを実装)。

import Html exposing (Html, button, div, text)

import Html.Events exposing (onClick)

main =
     Html.beginnerProgram { model = 0, view = view, update = update }
     type Msg = Increment | Decrement
     update msg model =
         case msg of
             Increment ->
                model + 1
            Decrement ->
                model - 1
     view model =
        div
           [ button [ onClick Decrement ] [ text "-" ]
           , div
[ text (toString model) ]
           , button [ onClick Increment ] [ text "+" ]
           ]

4. 保存してelm-makeでmain.htmlに出力するようにコンパイル実行。

%  elm-make Main.elm --output=main.html

5. ここで4のコマンド実行時にファイル名を入力ミスw

% elm-make Main.el --output=main.html <-- 拡張子が.elだとEmacsだしw 

しかし、直後にエラーを出さずに必要な依存ライブラリやパッケージの

ダウンロードが始まる。エラーにならないけど大丈夫?(ΦωΦ;)

ちと、不安になる。

Some new packages are needed. Here is the upgrade plan.
Install:
   elm-lang/core 5.0.0
   elm-lang/html 2.0.0
   elm-lang/virtual-dom 2.0.2 
Do you approve of this plan? [Y/n] y
Starting downloads...
 
 ● elm-lang/html 2.0.0
 ● elm-lang/virtual-dom 2.0.2
 ● elm-lang/core 5.0.0

Packages configured successfully!

 でも、必要なライブラリやパッケージのダウンロードが終わると、elm-makeさんに

「そんなファイルないよー」って言われる!(ΦωΦ)<ホウコクハサイゴナノネ

 elm-make: Main.el: openFile: does not exist (No such file or directory)

 Main.elmって入力したよねってのを確認してelm-makeコマンドから再スタート。

 % elm-make Main.elm --output=main.html

ようやく本題に入れると思ったのも束の間、1行目のimportでHtmlがHymlにミスってる

エラーがwww(ΦωΦ;)

コマンドの入力ミスと違い、ファイルの内容はすぐに訂正が入る。

-- NAMING ERROR ------------------------------------------------------- Main.elm 

Module `Html` does not expose `Hyml` 

1| import Html exposing (Hyml, button, div, text)
183 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

ご親切に、以下のつづりと間違えたんだよね?って指摘が入る。

(elm-makeたん、親切!(ΦωΦ))

Maybe you want one of the following?

       Html

Detected errors in 1 module.

 6. HymlをHtmlに修正して再度、elm-makeから再スタートw

     今度はMain.elmのコンパイルが上手く行って、

     main.htmlが作成されて出力された!

Success! Compiled 1 module.
Successfully generated main.html

7. elm-reactorを実行して内部サーバを起動し、下記URLにアクセス

 して、マイナスとプラスボタンが作成されてて動作に問題かないか

 を確認。

% elm-reactor

ブラウザで下記URLにアクセス。

http://localhost:8000/main.html

f:id:haiju:20161218162514p:plain

 画像が小さ過ぎるな・・・(ΦωΦ;;

問題があるのは大きさだけのようなので・・・

※elm-reactorはCtrl + Cで停止できる。

[参考サイト]

Install · An Introduction to Elm

www.parsonsmatt.org

github.com

qiita.com

qiita.com

Win7(x64)のVMのCentOS7(x64)に最新のGitを導入

ついついブログの備忘録に書いた気になって、しかも

dropboxに環境ごとのドキュメントとしてもバックアップ

してたとか思ってたけど、そんなことなかったので書くw

今日は天候的に低気圧しんどいし、月末が近づいてる

疲労で全身がだるおもー。

あんまり進捗ないかもしれない。

[手順]

■前提

makeやbuildのためにgccをインストール。

% sudo yum -y install gcc 

1. 依存ライブラリのインストール。

% sudo yum -y install curl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-ExtUtils-MakeMaker

2. wgetを導入し、ソースコードを取得して解凍。

% sudo yum -y install wget

% cd /usr/local/src/

% sudo wget https://www.kernel.org/pub/software/scm/git/git-2.10.2.tar.gz

% sudo tar xzvf git-2.10.2.tar.gz

3. makeコマンドでインストール。

% cd git-2.10.2

% sudo make prefix=/usr/local all

% sudo make prefix=/usr/local install 

 ※ /usr/local は自分で導入したアプリケーションをインストールする場所

4. 導入されたか確認。

% git --version

git version 2.10.2 と表示されればOK 

[参考サイト]

vdeep.net

Manjaro Fluxbox 15.12_x86-64のsystemd-nspawnで構築したFedora25 Serverのコンテナに次に必要そうな情報

多分、日本語化とかGUIデスクトップを導入するかも

しれない時に必要になるだろう情報を集めてみた。

下の2つの記事はsystemd-nspawn関係じゃないけど

部分的に参考になるかもしれないので。

ちなみにWin7_x86-64Virtualbox上のManjaro-gnome-16.08

でsystemd-nspawnでFedora25 Serverのコンテナを構築しよう

としたら、前の記事の手順2の最後のFedoraリポジトリ

認識させるコマンド「sudo dnf repolist」を実行したら下記エラー

が何度も発生するのでネットワーク周りを根本的に見直す

必要があるのだろうと思って中断。

Failed to synchronize cache for repo 'fedora', disabling.

[参考サイト]

www.server-world.info

www.server-world.info

fueloftheprogrammer.blogspot.jp

qiita.com

qiita.com

postd.cc

qiita.com