2015年3月18日水曜日

Projecte building. In 2015, Try the latest Technology. Part 1

In this industry, Technology have been advancing rapidly.
This time, I will create new project. and this is a private project.

So, I decide to build the latest Technology.

I think I public this attempt. I hope that this article is useful.

Enviroment

  • mac Yosemite

Using Technology

  • docker
  • nginx
  • php-fpm
  • php5.5
  • laravel
  • anguler.js
  • MongoDB
  • foundation
  • jenkins
  • Hubot
  • slack
  • arduino

Docker

This project use docker.
docker is an open platform for distributed applications for developers and sysadmins.
Currently, I don't want to use this Technology by big project. But this time, small project like startup. I will try docker.

install docker


brew update

brew install docker boot2docker

// docker version
docker -v
Docker version 1.5.0, build a8a31ef

// iso image download
boot2docker init

// boot2docker launch
boot2docker up

// export
To connect the Docker client to the Docker daemon, please set:
    export DOCKER_HOST=tcp://192.168.59.103:2376
    export DOCKER_CERT_PATH=/Users/msuzuki/.boot2docker/certs/boot2docker-vm
    export DOCKER_TLS_VERIFY=1

boot2docker status
running

use docker


  // move project folder
  cd {projectfolder}

  // crate docker file
  touch Dockerfile

  // write docker file
  vi Dockerfile

Dockerfile


FROM centos:6.6
MAINTAINER Edy

# yum update
RUN yum -y update

# install nginx
RUN rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
RUN yum -y install nginx

# install php
RUN rpm -ivh http://ftp.riken.jp/Linux/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm
RUN rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
RUN yum install -y http://repo.mysql.com/mysql-community-release-el6-5.noarch.rpm
RUN yum install -y --enablerepo=remi-php55 php php-mbstring php-mcrypt php-devel php-fpm

# Expose ports.
EXPOSE 80
# EXPOSE 443

# launch nginx
ENTRYPOINT ["/usr/sbin/nginx", "-g", "daemon off;"]

docker image cent os 7 is instability. use centos:6.6.

Run docker


  // build Dockerfile
  docker build -t development001 .

  // confirm docker images
  REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
  develop001          latest              9da6bf054ea6        45 minutes ago      611.7 MB

  // docker run
  docker run -i -t --name dev001 9da6bf054ea6 /bin/bash

  // nginx version
  nginx -v
  nginx version: nginx/1.6.2

  // php version
  php -v
  PHP 5.5.22 (cli) (built: Feb 18 2015 17:54:45) 

  // php-fpm version
  php-fpm -v
  PHP 5.5.22 (fpm-fcgi) (built: Feb 18 2015 17:55:52)

  // nginx start
  nginx

  // confirm
  curl http://localhost:80/

  // exit
  exit

Access docker from Mac


  // launch nginx container
  docker run -d -i -p 80:80 -t development001:latest

  // setting port forwarding
  VBoxManage controlvm "boot2docker-vm" natpf1 "nginx,tcp,127.0.0.1,3000,,80"

  // browser access
  http://localhost:3000

docker was ready. Next operation is setting nginx and php-fpm coordination.

以上。

参考サイト

この記事がお役にたちましたらシェアをお願いします

このエントリーをはてなブックマークに追加

2015年3月7日土曜日

Change LocationClient to GoogleApiClient

Enviroment

  • android:minSdkVersion="14"
  • android:targetSdkVersion="19"
  • com.google.android.gms:play-services:6.5.+
  • android studio

In my project, I changed play-services version6.1. to play-services 6.5.+.
But, Building Errors occurred.

Unfortunately, LocationClient came to deprecated class. Instead, GoogleApiClient class was released.

As I modified out-of-date code, I open to public latest code.
Please make good use of this code.

Attention: Under Sample Code is not Activity, but Service.

Sample Code


import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.location.Location;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.IBinder;
import android.util.Log;

import com.eastcore.cargo.BuildConfig;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.location.LocationListener;
import com.google.android.gms.location.LocationRequest;
import com.google.android.gms.location.LocationServices;

/**
 * LocationService
 * 位置情報を取得し続けるだけのサービスクラス
 */
public class LocationService extends Service implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener, LocationListener {

    public static final String TAG = "LocationService";

    //protected LocationClient mLocationClient;
    protected GoogleApiClient mGoogleApiClient;

    protected LocationRequest mLocationRequest;

    // 緯度
    protected double mLatitude;
    // 経度
    protected double mLongitude;
    // 標高
    protected double mAltitude;

    @Override
    public void onCreate() {
        super.onCreate();
        if (isLocationEnabled()) {
            if (BuildConfig.DEBUG) {
                Log.d(TAG, "-----onConnected----");
            }
            connectGooglePlayServices();
        }
    }

    @Override
    public void onDestroy() {
        Log.d(TAG, "onDestroy");
        super.onDestroy();
        disConnectGooglePlayServices();
    }

    /**
     * 現在地情報が取得可能な場合はtrue, 取得できない場合はfalse
     * @return
     */
    protected boolean isLocationEnabled() {
        LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        return locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
    }

    /**
     * GooglePlayServicesに接続する
     */
    protected void connectGooglePlayServices() {

        mLocationRequest = LocationRequest.create();
        // 10秒おきに位置情報を取得する
        mLocationRequest.setInterval(10000);
        // 精度優先
        mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
        // 最短で5秒おきに位置情報を取得する
        // mLocationRequest.setFastestInterval(5000);

//        mLocationClient = new LocationClient(getActivity().getApplicationContext(), connectionCallbacks, onConnectionFailedListener);
//        mLocationClient.connect();
        mGoogleApiClient = new GoogleApiClient.Builder(this)
                .addApi(LocationServices.API)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .build();

        if (mGoogleApiClient != null) {
            // GoogleApiClient start
            mGoogleApiClient.connect();
        }

    }

    /**
     * GooglePlayServicesを切断する
     */
    protected void disConnectGooglePlayServices() {

        if (mGoogleApiClient.isConnected()) {
            // 位置情報の取得を停止
            LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, this);
            //mGoogleApiClient.removeLocationUpdates(locationListener);
            mGoogleApiClient.disconnect();
        }

    }

    @Override
    public IBinder onBind(Intent intent) {
        // TODO: Return the communication channel to the service.
        throw new UnsupportedOperationException("Not yet implemented");
    }

    @Override
    public void onConnected(Bundle bundle) {
        LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);

    }

    @Override
    public void onConnectionSuspended(int i) {
    }

    @Override
    public void onLocationChanged(Location location) {
        double latitude = location.getLatitude();
        double longitude = location.getLongitude();
        double altitude = location.getAltitude();

        // latitude changed
        if (mLatitude != latitude) {
            mLatitude = latitude;
        }

        // longitude changed
        if (mLongitude != longitude) {
            mLongitude = longitude;
        }

        // altitude changed
        if (mAltitude != altitude) {
            mAltitude = altitude;
        }

        if (BuildConfig.DEBUG) {
            Log.d(TAG, "mLatitude:" + mLatitude + ", mLongitude: " + mLongitude + ", mAltitude: " + mAltitude);
        }
    }

    @Override
    public void onConnectionFailed(ConnectionResult connectionResult) {}
}

It is easy to change out-of-date code.

if your code still have deprecated class, it should be replaced the latest code.

thanks.

Reference Sites

この記事がお役にたちましたらシェアをお願いします

このエントリーをはてなブックマークに追加
Related Posts Plugin for WordPress, Blogger...