ページ

2015年1月25日日曜日

ARPについて改めて勉強

ARP (Address Resolution Protocol)

以前から名前と雰囲気くらいは知っていたのですが、ちゃんと勉強。
※Resolution 「解決する」という意味らしい。

ARP
  Ethernetではデータフレームの送信にMACアドレスが利用されており、IPで次の宛先となる送信すべき対象が決まったら、そのMACアドレスを決定しないといけない。これを解決するのがARPというプロトコル。

という事はEthernet限定の話?

ARPの流れ

1. IPアドレスをキーにしてMACアドレスを問い合わせるARP要求パケットを送信
2. 対象のIPアドレスを持っているノードはARP応答パケットでMACアドレスを伝える
3. ARPのキャッシュに書き込む
ARPは基本、同一データリンク(サブネット)で行う。別データリンクにノードがある場合は別データリンクのルータが間接的に応答する。


ARPキャッシュの情報を見てみる
コマンドは「arp -a」で見れる。
このコマンドはWindows、Maxでは同じ。Linuxだけ「arp -n」

キャッシュ情報は一定時間経つと消える。
※DHCPなどIPアドレスが変動する為。WindowsXP/2000の場合は2分間らしい。
ちなみにキャッシュテーブルはパソコンにも、ルータにもある。




クラシックギター購入!!

前々から購入したいと思っていたクラシックギターを購入

といっても高いものは買えないので、とりあえず入門者用のやつを購入。
島村楽器がオリジナルブランドで出している安価なLumberというブランドのもの。

























・スペック
 ボディトップ:シダー
 ボディサイド:サペリ
 ボディバック:サペリ
 ネック:ナトー
 フィンガー:ローズウッド
 スケール:650mm
 ブリッジ:ローズウッド
 カラー:ナチュラル
※参考
ギター用材


あと、弦の交換の時とまどいそう・・・


















なんじゃこりゃ〜 ><;

るろうに剣心Blue-ray購入

原作を全て見てないけど、映画を全て購入。

映画の監督が大友啓史さん(「龍馬伝」なんかの監督もしていた)だったので、
映画1作目から購入していました。

今回2部作で映画化だったので、Blue-rayを購入。



















とにかくもアクションシーンが凄かった><。
そして面白かったな〜。もう続きは出ないんっぽいし残念><。

2015年1月24日土曜日

GASまとめ 1 - 概要 -

GAS(Google Apps Script)まとめ

社内でGAS使って色々やった時のまとめ。
今回は概要部分。



GAS概要

GAS(Google Apps Script)はJavaScriptと違って、サーバー側で実行される。
なので、JavaScriptのalertの様にブラウザ側で実行され、ダイアログ表示する
メソッド等はGASでは使えない。
かわりにGASではBrowserオブジェクトを使って実行する。


1. Google Apps Services
スプレットシートや、ドキュメント等のGoogle Apps毎にXXXXAppオブジェクトが
用意されており、そのオブジェクトを使用してGoogle Appsを操作する。
例) Drive  -> DriveApp、 Gmail -> GmailApp

2015年の1月時点では以下のGoogle Apps Servicesがある

No
名前
説明
1
Calendar
カレンダーの参照・更新を行う
2
Contacts
連絡先の参照・更新を行う
Groupsの連絡先とは分けられる
3
Document
ドキュメントの作成・参照・更新を行う
4
Drive
ドライブ上のフォルダやファイルの作成・更新を行う
5
Forms
フォームの作成・参照・更新を行う
6
Gmail
メールの送信やメールへのアクセスを行う
7
Groups
Google Groupsのメンバー一覧やメールの参照を行う
8
Language
翻訳を行う
9
Maps
Mapの静止画や方向検索、座標変換等を行う
※Google Mapを操作はできない
10
Sites
Google Siteの作成・参照・更新を行う
11
Spreadsheet
スプレットシートの作成・参照・更新を行う


Drive上のファイルはそれぞれIDとURLを持っており、Document、Forms、SpreadsheetはopenByIdやopenByUrlメソッドでそれぞれのファイルにアクセスする。
例)
    var ss = SpreadsheetApp.openById("abcdefg1234");
    Logger.log(ss.getName());

DriveAppに関しては上記メソッドとは異なり、
getFileByIdやgetFolderByIdメソッドの様にFileやFolderをIDで管理する

2015年1月18日日曜日

AndroidでのSystem Properties

AndroidでSystemPropertiesがどこまで利用可能か調べてみた

一覧は公式ページに乗っている
Name Meaning Example
file.separator separator /
java.class.path System class path .
java.class.version (Not useful on Android) 50.0
java.compiler (Not useful on Android) Empty
java.ext.dirs (Not useful on Android) Empty
java.home Location of the VM on the file system /system
java.io.tmpdir See createTempFile(String, String) /sdcard
java.library.path Search path for JNI libraries /vendor/lib:/system/lib
java.vendor Human-readable VM vendor The Android Project
java.vendor.url URL for VM vendor's web site http://www.android.com/
java.version (Not useful on Android) 0
java.specification.version VM libraries version 0.9
java.specification.vendor VM libraries vendor The Android Project
java.specification.name VM libraries name Dalvik Core Library
java.vm.version VM implementation version 1.2.0
java.vm.vendor VM implementation vendor The Android Project
java.vm.name VM implementation name Dalvik
java.vm.specification.version VM specification version 0.9
java.vm.specification.vendor VM specification vendor The Android Project
java.vm.specification.name VM specification name Dalvik Virtual Machine Specification
line.separator The system line separator \n
os.arch OS architecture armv7l
os.name OS (kernel) name Linux
os.version OS (kernel) version 2.6.32.9-g103d848
path.separator See pathSeparator :
user.dir Base of non-absolute paths /
user.home (Not useful on Android) Empty
user.name (Not useful on Android) Empty

が、実際どうなのかやってみた。
以下サンプルアプリを作成。

















まずは、エミュレータで確認。
↓使用するエミュレータ

























↓LogCatの内容
01-17 23:21:59.126: D/MainActivity(2642): key = http.agent, value = Dalvik/2.0.0 (Linux; U; Android L Build/LPV81B)
01-17 23:21:59.154: D/MainActivity(2642): key = java.io.tmpdir, value = /data/data/com.examples.androidmics/cache
01-17 23:21:59.156: D/MainActivity(2642): Line :

・・・少なっ!!
エミュレータだとこんなもんなんでしょうか。。

次に実機で確認。
Android4.0.4


02-06 08:02:32.090: D/MainActivity(1375): key = java.vm.version, value = 1.6.0
02-06 08:02:32.090: D/MainActivity(1375): key = android.icu.library.version, value = 4.6
02-06 08:02:32.090: D/MainActivity(1375): key = java.vendor.url, value = http://www.android.com/
02-06 08:02:32.090: D/MainActivity(1375): key = java.vm.vendor.url, value = http://www.android.com/
02-06 08:02:32.090: D/MainActivity(1375): key = user.dir, value = /
02-06 08:02:32.090: D/MainActivity(1375): key = java.vm.name, value = Dalvik
02-06 08:02:32.090: D/MainActivity(1375): key = java.home, value = /system
02-06 08:02:32.090: D/MainActivity(1375): key = user.region, value = JP
02-06 08:02:32.090: D/MainActivity(1375): key = android.zlib.version, value = 1.2.5
02-06 08:02:32.090: D/MainActivity(1375): key = user.home, value =
02-06 08:02:32.090: D/MainActivity(1375): key = java.runtime.name, value = Android Runtime
02-06 08:02:32.090: D/MainActivity(1375): key = java.io.tmpdir, value = /sdcard
02-06 08:02:32.090: D/MainActivity(1375): key = http.agent, value = Dalvik/1.6.0 (Linux; U; Android 4.0.4; AT1S0 Build/IMM76D)
02-06 08:02:32.090: D/MainActivity(1375): key = java.version, value = 0
02-06 08:02:32.090: D/MainActivity(1375): key = java.boot.class.path, value = /system/framework/core.jar:/system/framework/core-junit.jar:/system/framework/bouncycastle.jar:/system/framework/ext.jar:/system/framework/framework.jar:/system/framework/android.policy.jar:/system/framework/services.jar:/system/framework/apache-xml.jar:/system/framework/filterfw.jar
02-06 08:02:32.090: D/MainActivity(1375): key = java.library.path, value = /vendor/lib:/system/lib
02-06 08:02:32.090: D/MainActivity(1375): key = file.separator, value = /
02-06 08:02:32.090: D/MainActivity(1375): key = java.specification.vendor, value = The Android Project
02-06 08:02:32.090: D/MainActivity(1375): key = file.encoding, value = UTF-8
02-06 08:02:32.090: D/MainActivity(1375): key = line.separator, value =
02-06 08:02:32.090: D/MainActivity(1375): key = java.vm.specification.version, value = 0.9
02-06 08:02:32.090: D/MainActivity(1375): key = java.vm.specification.vendor, value = The Android Project
02-06 08:02:32.090: D/MainActivity(1375): key = android.openssl.version, value = OpenSSL 1.0.0e 6 Sep 2011
02-06 08:02:32.090: D/MainActivity(1375): key = os.name, value = Linux
02-06 08:02:32.090: D/MainActivity(1375): key = java.vm.vendor, value = The Android Project
02-06 08:02:32.090: D/MainActivity(1375): key = path.separator, value = :
02-06 08:02:32.090: D/MainActivity(1375): key = java.ext.dirs, value =
02-06 08:02:32.090: D/MainActivity(1375): key = java.class.path, value = .
02-06 08:02:32.090: D/MainActivity(1375): key = os.version, value = 2.6.39.4-g8e40b1f
02-06 08:02:32.090: D/MainActivity(1375): key = java.specification.name, value = Dalvik Core Library
02-06 08:02:32.090: D/MainActivity(1375): key = java.compiler, value =
02-06 08:02:32.090: D/MainActivity(1375): key = os.arch, value = armv7l
02-06 08:02:32.090: D/MainActivity(1375): key = user.name, value =
02-06 08:02:32.090: D/MainActivity(1375): key = user.language, value = ja
02-06 08:02:32.090: D/MainActivity(1375): key = android.icu.unicode.version, value = 6.0
02-06 08:02:32.090: D/MainActivity(1375): key = java.runtime.version, value = 0.9
02-06 08:02:32.090: D/MainActivity(1375): key = java.class.version, value = 50.0
02-06 08:02:32.090: D/MainActivity(1375): key = java.vendor, value = The Android Project
02-06 08:02:32.090: D/MainActivity(1375): key = java.vm.specification.name, value = Dalvik Virtual Machine Specification
02-06 08:02:32.090: D/MainActivity(1375): key = java.specification.version, value = 0.9
02-06 08:02:32.090: D/MainActivity(1375): Line :

公式ページと同じくらいのプロパティが設定してあるよう。
ちなみに、System#getPropertyで存在しないキーを指定するとnullを返却するので、
nullチェックは必要!!





2015年1月15日木曜日

GAEと戯れる 15 - セッション -

Google Appsとの連携の前に・・・ちょっとセッションを使ってみる。

まず、使えるようにするには、「appengine-web.xml」を修正する。
























<session-enabled>をtrueにする。
<?xml version="1.0" encoding="utf-8"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
<application>acount-war</application>
<version>1</version>
<precompilation-enabled>true</precompilation-enabled>
<system-properties>
    <property name="slim3.hotReloading" value="true"/>
    <!--
        <property name="slim3.datastoreDeadline" value="8"/>
        <property name="slim3.uploadSizeMax" value="1000000"/>
        <property name="slim3.uploadFileSizeMax" value="100000"/>
        -->
    <property name="java.util.logging.config.file" value="WEB-INF/classes/logging.properties"/>
</system-properties>
<sessions-enabled>true</sessions-enabled>
<threadsafe>true</threadsafe>
</appengine-web-app>

使い方
  1. 設定方法
   sessionScope("key"“value");  

  2. 取り出し方
   String value = this.sessionScope("key");

  3. 削除
  removeSessionScope("key);

  まあ、分かりやすい^^

また、セッションはDatastoreに蓄積するらしいので定期的に削除してやらないといけないらしい。

参考URL


2015年1月4日日曜日

GAEと戯れる 14 - gdata -

今回からはGAEとGoogle Appsとの連携をやってみる

以下サイトを参考
http://thinkit.co.jp/story/2013/10/01/4472

とりあえず、GAE側にGoogle Appsと連携する為のライブラリを導入してみる。
gdataというものがいるらしい。
↓からダウンロード可能
https://code.google.com/p/gdata-java-client/downloads/list

GAE側プロジェクトのWEB-INF/lib配下にjarファイルをコピー
















コピー元はダウンロードしたgdata/java/lib配下のjarと、jsr305.jar
次に、以下6項目をビルドパスに追加

















↓とりあえず、参考サイトを元にサービスクラスを作成してみた
/**
 * GoogleDriveのスプレッドシートサービスクラス
 * @author jf-orange
 */
public class SpreadSheetService {

    private SpreadsheetService spreadsheetService;
    
    /**
     * コンストラクタ
     * 
     * @param appName       アプリケーション名
     */
    public SpreadSheetService(String appName) {
        spreadsheetService = new SpreadsheetService(appName);
    }
    
    /**
     * スプレッドシートの検索
     * 
     * @param sheetName     シート名
     * @return              {@link SpreadsheetEntry}
     * @throws Exception
     */
    public SpreadsheetEntry findSheet(String sheetName) throws Exception {
        if (StringUtil.isEmpty(sheetName)) {
            return null;
        }
        FeedURLFactory factory = FeedURLFactory.getDefault();
        SpreadsheetQuery sheetQuery 
            = new SpreadsheetQuery(factory.getSpreadsheetsFeedUrl());
        sheetQuery.setTitleQuery(sheetName);
        SpreadsheetFeed sheetFeed = spreadsheetService.query(sheetQuery, SpreadsheetFeed.class);
        return sheetFeed.getEntries().get(0);
    }
    
    public WorksheetEntry getWorksheet(SpreadsheetEntry entry) throws Exception {
        if (entry == null) {
            return null;
        }
        return entry.getDefaultWorksheet();
    }
    
    /**
     * ワークシート内の全データを取得
     * 
     * @param workSheetEntry        {@link WorksheetEntry}
     * @return                      {@link ListEntry}のリスト
     * @throws Exception
     */
    public List<ListEntry> getSheetAllData(WorksheetEntry workSheetEntry) throws Exception {
        if (workSheetEntry == null) {
            return null;
        }
        ListQuery listQuery = new ListQuery(workSheetEntry.getListFeedUrl());
        ListFeed listFeed = spreadsheetService.query(listQuery, ListFeed.class);
        return listFeed.getEntries();
    }

}

GAEと戯れる 13 - Slim3 モデル作成 -

Modelの作成

2015年一発目はGAEのModelを作成してみます。
ControllerとViewを作成した時のようにbuild.xmlを使用してAntで作成していくみたいす。

build.xml右クリック > 「Ant Build...」






















いつものように、ダイアログが表示されるのでModel名を入力








今回は「MyData」と入力
























すると「パッケージ/model」と「パッケージ/meta」の配下にそれぞれ
MyData.javaとMyDataMeta.javaが作成される。
※metaに関してはAndroidのgenっぽい?

↓作成されたMyData.java
@Model(schemaVersion = 1)
public class MyData implements Serializable {

    private static final long serialVersionUID = 1L;

    @Attribute(primaryKey = true)
    private Key key;

    @Attribute(version = true)
    private Long version;
    
    /**
     * Returns the key.
     *
     * @return the key
     */
    public Key getKey() {
        return key;
    }

    /**
     * Sets the key.
     *
     * @param key
     *            the key
     */
    public void setKey(Key key) {
        this.key = key;
    }

    /**
     * Returns the version.
     *
     * @return the version
     */
    public Long getVersion() {
        return version;
    }

    /**
     * Sets the version.
     *
     * @param version
     *            the version
     */
    public void setVersion(Long version) {
        this.version = version;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((key == null) ? 0 : key.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        MyData other = (MyData) obj;
        if (key == null) {
            if (other.key != null) {
                return false;
            }
        } else if (!key.equals(other.key)) {
            return false;
        }
        return true;
    }

}

クラスに@Modelのアノテーションが付いている。Seasarっぽい?
slim3が用意したアノテーションでこのクラスがModelであることを宣言している。
Keyはプライマリーキー、これもアノテーションで宣言している。
VersionはこのModelのバージョンをGAE側が管理する為に必要らしい。

このMyData.javaに必要なフィールドを追加してみる。
@Model(schemaVersion = 1)
public class MyData implements Serializable {

    private static final long serialVersionUID = 1L;

    @Attribute(primaryKey = true)
    private Key key;

    @Attribute(version = true)
    private Long version;

    /* 名前           */
    private String name;
    /* メールアドレス   */
    private String mail;
    /* 年齢           */
    private int age;
    
    /**
     * Returns the key.
     *
     * @return the key
     */
    public Key getKey() {
        return key;
    }

    /**
     * Sets the key.
     *
     * @param key
     *            the key
     */
    public void setKey(Key key) {
        this.key = key;
    }

    /**
     * Returns the version.
     *
     * @return the version
     */
    public Long getVersion() {
        return version;
    }

    /**
     * Sets the version.
     *
     * @param version
     *            the version
     */
    public void setVersion(Long version) {
        this.version = version;
    }

    /**
     * 名前の取得
     * 
     * @return  名前
     */
    public String getName() {
        return name;
    }
    
    /**
     * 名前の設定
     * 
     * @param name  名前
     */
    public void setName(String name) {
        this.name = name;
    }
    
    /**
     * メールアドレスの取得
     * 
     * @return      メールアドレス
     */
    public String getMail() {
        return mail;
    }
    
    /**
     * メールアドレスの設定
     * 
     * @param mail  メールアドレス
     */
    public void setMail(String mail) {
        this.mail = mail;
    }
    
    /**
     * 年齢の取得
     * 
     * @return      年齢
     */
    public int getAge() {
        return age;
    }
    
    /**
     * 年齢の設定
     * 
     * @param age   年齢
     */
    public void setAge(int age) {
        this.age = age;
    }
    
    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((key == null) ? 0 : key.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        MyData other = (MyData) obj;
        if (key == null) {
            if (other.key != null) {
                return false;
            }
        } else if (!key.equals(other.key)) {
            return false;
        }
        return true;
    }

}

この状態でビルドするとMyDataMeta.javaも自動で更新されているっぽい。
んで、このModelを使う場合。

↓Controller側で使用してみる。
public class IndexController extends Controller {

    @Override
    public Navigation run() throws Exception {
        String msg = "データの入力";
        
        if (isPost()) {
            String name = asString("name");
            String mail = asString("mail");
            int age = asInteger("age");
            
            MyData myData = new MyData();
            myData.setName(name);
            myData.setMail(mail);
            myData.setAge(age);
            // slim3 エンティティをデータストアに保存
            Datastore.put(myData);
        }
        // slim3 エンティティ一覧の取得
        List<MyData> myDatas = Datastore.query(MyDataMeta.get()).asList();
        request.setAttribute("msg", msg);
        request.setAttribute("mydatas", myDatas);
        return forward("index.jsp");
    }

}

GAE側で用意されているDataStoreをslim3がラップしたDatastoreクラスを使用する。
Datastore#put : insert
Datastore#query() : slim3側で用意されているModelQueryオブジェクトを生成する
                                 ModelQuery#asListメソッドでListへ変換している。


↓index.jsp
<body>
<div id="header">
<h1>テスト</h1>
</div>
<p>${msg}</p>
<form method="post" action="/">
<table>
<tr><td>名前</td><td><input type="text" ${f:text("name")}></td></tr>
<tr><td>メール</td><td><input type="text" ${f:text("mail")}></td></tr>
<tr><td>年齢</td><td><input type="text" ${f:text("age")}></td></tr>
<tr><td></td><td><input type="submit"></td></tr>
</table>
</form>
<hr>
<table border="1">
<c:forEach var="mydata" items="${mydatas}">
<tr>
<td>${mydata.name}</td>
<td>${mydata.mail}</td>
<td>${mydata.age}</td>
</tr>
</c:forEach>
</table>
</body>

</html>

c:forEachでリストをループし、表示している。

↓実行結果








データストアに登録してみる










ちなみに、ローカルのDBの内容参照や編集は
 http://localhost:8888/_ah/admin
から参照/編集ができる。