ubuntu14.04(trusty)にDockerをインストール

vagrantのubuntu14.04(trusty)にDockerをインストールします。

まず、パッケージマネージャーをアップデートしておきます。

sudo apt-get update

そして、Dockerの最新を取得します。

wget -qO- https://get.docker.com/ | sh

文末にアラートが表示されるので、ユーザーをDockerグループに追加します。

If you would like to use Docker as a non-root user, you should now consider
adding your user to the "docker" group with something like:

  sudo usermod -aG docker vagrant

Remember that you will have to log out and back in for this to take effect!
vagrant@vagrant-ubuntu-trusty-64:~$ sudo usermod -aG docker vagrant

では、Dockerが入っているか確認してみましょう。大丈夫そうですね。

vagrant@vagrant-ubuntu-trusty-64:~$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
c04b14da8d14: Pull complete
Digest: sha256:0256e8a36e2070f7bf2d0b0763dbabdd67798512411de4cdcf9431a1feb60fd9
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker Hub account:
 https://hub.docker.com

For more examples and ideas, visit:
 https://docs.docker.com/engine/userguide/

vagrant@vagrant-ubuntu-trusty-64:~$ sudo docker --version
Docker version 1.12.3, build 6b644ec

Dockerを動かすためにvagrantにUbuntuをインストール

Dockerは軽量な仮想環境で、OSやアプリケーションを別の場所に簡単にもっていくことができます。Build once, run anywhere と呼ばれたりします。

Docker

Dockerはubuntu上で開発されているので、環境は、ubuntuをvagrantでインストールして、そこで作業していきましょう。ということで、vagrantのフォルダに移動し、コマンドラインからubuntuを入れます。

まず、vagrantから、boxesからtrustyをコピーします。
http://www.vagrantbox.es/
a

そして、vagrantのフォルダからコマンドラインで以下のように打ち込みます。

C:\Users\username\MyVagrant>vagrant box add trusty64 https://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-amd64-vagrant-disk1.box

インストールが終わったら、Dockerのファイルを作り、vagrant initをしましょう。

C:\Users\username\MyVagrant>mkdir Docker
C:\Users\username\MyVagrant>cd Docker
C:\Users\username\MyVagrant\Docker>vagrant init trusty64

そすると、vagrant fileが作られるので、vagrant fileの中で、以下のようにipのコメントを外して、任意のipアドレスを設定しましょう。ここでは、192.168.55.44としてます。

  # Create a private network, which allows host-only access to the machine
  # using a specific IP.
  config.vm.network "private_network", ip: "192.168.55.44"

  # Create a public network, which generally matched to bridged network.
  # Bridged networks make the machine appear as another physical device on
  # your network.
  # config.vm.network "public_network"

その後、vagrant upとし、Ubuntu sshで接続完了です。

login as: vagrant
vagrant@192.168.55.44's password:
Welcome to Ubuntu 14.04.5 LTS (GNU/Linux 3.13.0-100-generic x86_64)

* Documentation: https://help.ubuntu.com/

System information disabled due to load higher than 1.0

Get cloud support with Ubuntu Advantage Cloud Guest:
http://www.ubuntu.com/business/services/cloud

0 packages can be updated.
0 updates are security updates.

CoffeeScriptのクラスの継承

Coffeeでもクラスの継承、オーバーライドなどできます。

class User
 constructor: (@name) ->
 hello: -> alert "hello, #{@name}"

class AdminUser extends User
 hello: ->
  alert "admin says..."
  super()

tom = new User "Tom"
alert tom.name
tom.hello()

bob  new AdminUser "Bob"
# alert bob.name
bob.hello()

Ada genericによるswap

with Ada.Text_IO;
use Ada.Text_IO;
with Ada.Integer_Text_IO;
use Ada.Integer_Text_IO;

procedure MyApp is
   generic
     type element is private;
   procedure Swap(a, b: in out element);

   procedure Swap(a, b: in out element) is
     tmp: element;
   begin
     tmp := a;
     a := b;
     b := tmp;
   end Swap;

   procedure SwapInt is new Swap(Integer);
   procedure SwapChar is new Swap(Character);

   i1: Integer := 3;
   i2: Integer := 5;
   c1: Character := 'a';
   c2: Character := 'd';
begin
  put(i1);
  new_line;
  put(i2);
  new_line;
  put(c1);
  new_line;
  put(c2);
  new_line;
  SwapInt(i1, i2);
  SwapChar(c1, c2);
  put(i1);
  new_line;
  put(i2);
  new_line;
  put(c1);
  new_line;
  put(c2);
  new_line;
end MyApp;
[vagrant@localhost ada_lessons]$ gnatmake myapp.adb
gcc -c myapp.adb
gnatbind -x myapp.ali
gnatlink myapp.ali
[vagrant@localhost ada_lessons]$ ./myapp
          3
          5
a
d
          5
          3
d
a

Ada procedure

with Ada.Text_IO;
use Ada.Text_IO;
with Ada.Integer_Text_IO;
use Ada.Integer_Text_IO;

procedure MyApp is
  procedure SayHi(name: in String) is
  begin
   put_line("hi!" & name);
  end SayHi;
begin
   SayHi("tom");
   SayHi("bob");
end MyApp;
[vagrant@localhost ada_lessons]$ gnatmake myapp.adb
gcc -c myapp.adb
gnatbind -x myapp.ali
gnatlink myapp.ali
[vagrant@localhost ada_lessons]$ ./myapp
hi!tom
hi!bob

Adaのloopとexit

Adaのloopは永久ループなので、exitで処理を抜けます。

-- Float
--変数
with Ada.Text_IO;
use Ada.Text_IO;
with Ada.Integer_Text_IO;
use Ada.Integer_Text_IO;

procedure MyApp is
   count: integer;
   i: integer := 1;
begin
 get(count);
 loop
   put(i);
   new_line;
   i := i + 1;
   exit when i > count;
 end loop;
end MyApp;
[vagrant@localhost ada_lessons]$ gnatmake myapp.adb
gcc -c myapp.adb
gnatbind -x myapp.ali
gnatlink myapp.ali
[vagrant@localhost ada_lessons]$ ./myapp
4
          1
          2
          3
          4

Adaの条件分岐

-- Float
--変数
with Ada.Text_IO;
use Ada.Text_IO;
with Ada.Integer_Text_IO;
use Ada.Integer_Text_IO;

procedure MyApp is
 score: integer;
begin
 get(score);
 if score > 80 then
    put_line("great!");
 elsif score > 60 then
 put_line("good!");
 else
 put_line("...");
    end if;
end MyApp;
[vagrant@localhost ada_lessons]$ gnatmake myapp.adb
gcc -c myapp.adb
gnatbind -x myapp.ali
gnatlink myapp.ali
[vagrant@localhost ada_lessons]$ ./myapp
25
...

戦闘機開発 Adaの定数と変数、四則演算

--定数
--変数
with Ada.Text_IO;
use Ada.Text_IO;
with Ada.Integer_Text_IO;
use Ada.Integer_Text_IO;

procedure MyApp is
 x: Integer;
 y: constant Integer := 3;
begin
  x := 5;
  put(x);
  new_line;
  x := 10;
  put(x, 5);
  new_line;
  put(y);
  new_line;
end MyApp;

四則演算

--定数
--変数
with Ada.Text_IO;
use Ada.Text_IO;
with Ada.Integer_Text_IO;
use Ada.Integer_Text_IO;

procedure MyApp is
 x: Integer;
begin
 put("your number? ");
 get(x);

 put(x + 3);
 new_line;
 put(x - 3);
 new_line;
 put(x / 3);
 new_line;
 put(x rem 3);
 new_line;
 put(x * 3);
 new_line;
 put(x ** 3);
 new_line;
end MyApp;

25を入力してみます。

[vagrant@localhost ada_lessons]$ gnatmake myapp.adb
gcc -c myapp.adb
gnatbind -x myapp.ali
gnatlink myapp.ali
[vagrant@localhost ada_lessons]$ ./myapp
your number? 25
         28
         22
          8
          1
         75
      15625

戦闘機開発 Adaで”helloworld”

Adaの拡張子は、adbです。myapp.adbファイルをつくり、早速コードを書いてみましょう。

with Ada.Text_IO;
use Ada.Text_IO;

procedure MyApp is
begin
  put_line("hello world!");
end MyApp;
[vagrant@localhost ada_lessons]$ gnatmake myapp.adb
gcc -c myapp.adb
gnatbind -x myapp.ali
gnatlink myapp.ali
[vagrant@localhost ada_lessons]$ ls
myapp  myapp.adb  myapp.ali  myapp.o
[vagrant@localhost ada_lessons]$ ./myapp
hello world!