ラベル Web開発 の投稿を表示しています。 すべての投稿を表示
ラベル Web開発 の投稿を表示しています。 すべての投稿を表示

2015年6月27日土曜日

UnityWebGLを試してみた。

以前作成した色彩感覚テストアプリをWebGLにビルドしてみました。
グラデーション
Unityプレイヤー

Chromeで実行したところ
It seems your browser does not support running Unity WebGL content from file:// urls. Please upload it to an http server, or try a different browser.
Macのセキュリティに引っかかってしまいました。
全部ピンク
Safariで実行
ブラウザで実行するとなぜか色が全部同じに。。 
色を作成するコードに対応できていないのかもしれません

140mも
そしてファイルサイズが136メガ!
多分基本となるAPIが重いのでしょう。
どんなにソースが軽くても130メガ以上のファイルになってしまいます。
UnityのWebGLはhttpサーバで公開するには向いていないかも?
プラットフォームを選ばずに動作させられる点が使いどころかもしれません。

2014年1月19日日曜日

Web開発転向者向けのメモ PHP⇔JavaScript間でのデータの受け渡しなど

キーワードは

  • ブラウザオブジェクト
  • スーパーグローバル変数
  • PHPとJavaScriptのデータ受け渡し
  • PHPやJavaScriptの外部ファイル(共通クラスの呼び出し方)

・ブラウザオブジェクト
ブラウザ操作用のクラス郡。ブラウザが保持している情報へのアクセスや書き換えができる。

--JS各オブジェクトと階層
http://www.htmq.com/js/index.shtml#js_window



--URLにパラメータを付けて渡す
index.html 渡す側
<a href="page.html?sample1=yes&hensu=100">引数つきリンク</a>

URLの後に"?"でパラメータを繋ぎます。
複数の場合は"&"で連結していけます


page.html 受け取る側
<script type="text/javascript">

var urlPrm = new Object;
var urlSearch = location.search.substring(1).split('&');
for(i=0;urlSearch[i];i++) {
 var kv = urlSearch[i].split('=');
 urlPrm[kv[0]]=kv[1];
}

alert(urlPrm.sample1);
alert(urlPrm.sample2);
</script>


で表示される文字はそれぞれ"yes","100"となります。

--スーパーグローバル変数
・スーパーグローバル変数(定義済みの変数)
$GLOBALS〔グローバル変数〕
$_SERVER〔サーバー変数〕

$_GET〔HTTP GET変数〕
引数付きURL or  getのデータを取り出せる
http://xxxx.yy.zz/user.php?id=5&name=yoshi
URLの引数 or フォーム入力の取得
$id = $_GET['id'];

$_POST〔HTTP POST変数〕
$_COOKIE〔COOKIE変数〕
$_ENV〔環境変数〕
$_FILES〔HTTP ファイルアップロード変数〕
$_REQUEST〔リクエスト変数〕

$_SESSION〔セッション変数〕
セッションごとにデータを保持できる
PHP⇒PHPへのデータ受け渡し
 セッション生成
session_start();
$_SESSION["data"]="保存データ";

// セッション復元
session_start();
echo "セッションデータ:" , $_SESSION["data"] ;



JSURL⇒PHPへ引数を渡す
http://www.php-ref.com/web/01_get.html
 GETメソッドの送信データを取得する。
フォームで、項目「get_data1」にデータ入力してGETメソッドで送信する。
 「test1.php」
<html>
<body>

<form action = "test2.php" method = "get" >--or post
<input type="text" name="get_data1">

<input type="submit" name="GET送信" value="GET送信">
</form>

</body>
</html>

GETデータ「get_data1」を取得してHTMLに出力する。
 「test2.php」
<html>
<body>

<?php
echo $_GET["get_data1"];--or POST
?>

</body>
</html>

url⇒PHPへ引数を渡す
 http://xxxx.yy.zz/user.php?id=100&name=データ

取り出す
<?php
  // [ user.php ]
  if(isset($_GET['id'])) {
      $id = $_GET['id'];
      print("$id<br>\n");
  }
  if(isset($_GET['name'])) {
      $name = $_GET['name'];
      print("$name<br>\n");
  }
?>

PHP⇒JSへ
http://www.crystal-creation.com/web-appli/technical-information/programming/php/sample/javascript-cooperation.htm

<script type="text/javascript">
  var a = <?php echo $a; ?>;
</script>

--共通jsファイルの利用
http://www.tohoho-web.com/js/write.htm#jsfile

--共通PHPファイルの利用
http://www.ipentec.com/document/document.aspx?page=php-function-definition-call-external-file

2013年12月31日火曜日

VMwere上のCentOSでLAMP環境構築

・インストール環境 
Windows XP
Care2 E8400 3GHz
メモリ 2G

VMwere5.0
CentOS6.4
Apache2.4
MySQL
PHP5.5

VMwereのインストールからCentOSインストールまでは特記することはありません。
簡易インストールを使用するとVMwereが全て自動設定認識してくれます。ネットワーク周りもすぐ使えます。

--日本語化
OSのGUIからSYSTEM⇒Keyboade⇒Japanesを選択
yum groupinstall "Japanese Support"
vi /etc/sysconfig/i18n
ja_JPに書き換える
再起動

--Tera Term SSHクライアント
ダウンロード
http://sourceforge.jp/projects/ttssh2/releases/
文字化けする場合はTera Termの設定からフォントを変更

--LAMP環境構築手順
http://itmemo.net-luck.com/linux-centos-apache-install-2/
上記サイトが参考になります。

・エラー発生の場合は

configure: error: pcre-config for libpcre not found. PCRE is required and available
PCREをダウンロードしてインストール

configure: error: You need a C++ compiler for C++ support.
yum install gcc-c++

最後にPHPの動作を確認して終了です。
http://192.168.xxx.xxx/index.php




・iptablesとhttpd.confの書き換えについて※書き換え追加箇所赤文字

--ファイヤウォール設定
vi /etc/sysconfig/iptables
# SSH, HTTP, FTP1, FTP2, MySQL
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 80    -j ACCEPT

--アパッチ設定
vi /usr/local/apache2/conf/httpd.conf

<IfModule unixd_module>
#
# If you wish httpd to run as a different user or group, you must run
# httpd as root initially and it will switch.
#
# User/Group: The name (or #number) of the user/group to run httpd as.
# It is usually good practice to create a dedicated user and group for
# running httpd, as with most system services.
#
User apache
Group apache

</IfModule>

#
# ServerName gives the name and port that the server uses to identify itself.
# This can often be determined automatically, but we recommend you specify
# it explicitly to prevent problems during startup.
#
# If your host doesn't have a registered DNS name, enter its IP address here.
#
ServerName hide-CentOS:80


<IfModule dir_module>
    DirectoryIndex index.html index.php
</IfModule>

#
# PHP Configuration
#
<FilesMatch "\.ph(p[2-6]?|tml)$">
    SetHandler application/x-httpd-php
</FilesMatch>

<FilesMatch "\.phps$">
    SetHandler application/x-httpd-php-source
</FilesMatch>





2013年10月1日火曜日

Web開発メモ01 Centos6PHP環境構築

レッドハットのクローンOSでサーバー構築めも

インストール環境
Windows XP
Care2 E8400 3GHz
メモリ 2G


--・VMwereダウンロード
https://my.vmware.com/jp/web/vmware/free#desktop_end_user_computing/vmware_player/5_0|PLAYER-503|product_downloads
VirtualBoxとWMwereどちらがいいのか比較したところ。
VirtualBoxはVRAMなどの細かい設定ができる。
VMwereはドラックアンドドロップでファイルを移動できる。
私はWMwere選択しました。使用経験もあるので。
インストール時の注意は特にありません。※最新のVMwere Plusは営利使用有料

・Redhatダウンロード
無料版の開発は終了し現在は有料版のみ提供しています。
Redhatは企業向けの有料版しかありません。評価版も企業向けにしか提供されていません。
フリーメールアドレスなど、個人向けのメールアドレスでは企業向けカウントに登録できませんでした。


えでぃしょんについて
Red Hat Desktop(デスクトップ用途向け)、WS (ワークステーション用途向け)、ES (エントリークラスのサーバ向け)、AS (比較的大規模なサーバ向け

--・アパッチ

公式のミラーダウンロードはリンクは殆ど機能していなかった・・・
Not Found
The requested URL /net/apache//httpd/httpd-2.4.6.tar.gz was not found on this server.

Tera Term SSH接続
ソフトのダウンロード
http://sourceforge.jp/projects/ttssh2/releases/
参考
http://freesoft.tvbok.com/freesoft/virtual/vmware_centos4.html
文字化け
http://www.j-oosk.com/teraterm/configuration/563/




--・PHP
http://us1.php.net/downloads.php
""内は変数の値を表示
===型の比較
配列の添え字は数字や文字をキーにできる

・フィールドにはクラス変数とインスタンス変数の2種類がある
クラス変数
private static $クラス変数 = 0;
インスタンスを生成しなくても、使用できる変数で、クラス全体で共有される。
self::$クラス変数名
で呼び出すことができる。

インスタンス変数
private $インスタンス変数;
生成したインスタンス毎に使用する変数。
$this->$インスタンス変数
で呼び出すことができる。




--vmwere エラー
エラー
ディスク"XXXX.vmdk"を開くことができない、または一部のスナップショットがこのディスクに従属しています。
理由: ファイルをロックできませんでした。

対応策
**.vmdk.lck
**.vmem.lck
**.Edition.vmx.lck

上記フォルダを削除




--アパッチインストール
APRエラー
configure: error: APR not found.  Please read the documentation
http://nakoruru.jp/?p=747

 *ServerName設定

# vi /usr/local/apache2/conf/httpd.conf
設定詳細
http://digibot.jp/tips/linux/003.html

--フォルダ検索
find / -name "apache*" -type d

--リナックスの全体像
--HTMLとJSの構造

--JS
JS:URLにパラメータを付けて渡す
2012.02.29
リンクURLにパラメータを付け、
リンク先のページで処理させるというのをやったのでメモです。

■index.html
---------------------------------------------------------------------------------------
<a href="page.html?sample1=yes&sample2=100">リンクです</a>
---------------------------------------------------------------------------------------

上記のようなリンクを設置。
URLの後に"?"でパラメータを繋ぎます。
複数ある場合はさらに"&"で繋ぎます。


■page.html
---------------------------------------------------------------------------------------
<script type="text/javascript">

var urlPrm = new Object;
var urlSearch = location.search.substring(1).split('&');
for(i=0;urlSearch[i];i++) {
 var kv = urlSearch[i].split('=');
 urlPrm[kv[0]]=kv[1];
}

alert(urlPrm.sample1);
alert(urlPrm.sample2);

</script>
---------------------------------------------------------------------------------------

飛び先のページに書くJSは上記のようになります。
最後のアラートで表示される文字はそれぞれ"yes","100"となります。

外部のJSの関数を呼ぶ
http://www.pori2.net/js/kihon/16.html



--RPM 米Red Hat社が開発したアプリケーション・パッケージの管理方式
--yum Yellowdog Updater Modified (Yum)はLinuxのRPM互換パッケージ管理システム
--SPEC RPMを作成するための作業手順やRPMの情報などを記述したファイル.このファイルを用いてRPMを作成する
--tar(ター、tape archives)は、ファイルフォーマットの一種であり、Tape ARchive formatの略である。
--GNU(/gnuミ / グヌー、/gnjuミ / グニュー)は、UNIX互換のソフトウェア環境を全てフリーソフトウェアで実装することを目標とするプロジェクト、およびそのソフトウェア全体を指す。


pwd 現在の改装
tar xzvf package.tar.gz 回答するXXX.tar.gz
./configure ⇒make makeファイルの作成とコンパイル
sudo yum remove httpd アパッチのアンインストール
/usr/local/apache2/bin/apachectl start アパッチの起動とパス
find / -name "apache*" -type d
# vi /usr/local/apache2/conf/httpd.conf

参考
--LAMP 俺の開発研究所
VMへOSインストール
http://itmemo.net-luck.com/vmware-player-centos-64bit-install/
あぱっち
 http://itmemo.net-luck.com/linux-centos-apache-install-2/
PHP
http://itmemo.net-luck.com/linux-centos-php-install/
そのたCENTOS
http://itmemo.net-luck.com/category/centos/

--設定ファイル
http://centos.server-manual.com/centos5_apache2_php5.html

--大まかな流れ
http://btt.hatenablog.com/entry/2013/02/06/120049

PHP掲示板アプリのサンプル

ページを表示する(テキストとWEBビュー)
ボタンを押すと書き込み⇒再表示



    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" >
    </uses-permission>
     <uses-permission android:name="android.permission.INTERNET" />


//activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="500px"
        android:layout_height="300px"
        android:layout_alignRight="@+id/button1"
        android:layout_marginTop="24dp"
        android:orientation="vertical" >

        <WebView
            android:id="@+id/webView1"
            android:layout_width="match_parent"
            android:layout_height="224dp" />
    </LinearLayout>

    <EditText
        android:id="@+id/editText2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/button1"
        android:layout_alignBottom="@+id/button1"
        android:layout_alignParentLeft="true"
        android:layout_toLeftOf="@+id/button1"
        android:ems="10" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_marginBottom="17dp"
        android:layout_marginRight="14dp"
        android:text="書き込み" />

    <EditText
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/button1"
        android:layout_alignLeft="@+id/linearLayout1"
        android:layout_alignRight="@+id/button1"
        android:layout_below="@+id/linearLayout1"
        android:ems="10"
        android:inputType="textMultiLine" >

        <requestFocus />
    </EditText>

</RelativeLayout>

//MainActivity

package com.example.testhttp;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.NameValuePair;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;

import com.example.testhttp.R.id;

import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.EditText;




public class MainActivity extends Activity implements OnClickListener{
private EditText ed1,ed2;
private Button  bt;
private WebView wv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

ed1 = (EditText)findViewById(id.editText1);
ed2 = (EditText)findViewById(id.editText2);
bt= (Button)findViewById(id.button1);
wv = (WebView)findViewById(id.webView1);


bt.setOnClickListener(this);

exec_post(false);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

@Override
public void onClick(View v) {

exec_post(true);
}




   String ret = "";

   // URL
   URI url = null;
   try {
     url = new URI( "http://passepied.miraiserver.com/index.php" );
     Log.d("posttest", "URLはOK");
   } catch (URISyntaxException e) {
     e.printStackTrace();
     ret = e.toString();
   }

   HttpPost request = new HttpPost( url );
   List<NameValuePair> post_params = new ArrayList<NameValuePair>();
   if(fl){
   post_params.add(new BasicNameValuePair("post_2", ed2.getText().toString()));
   }
   try {

     request.setEntity(new UrlEncodedFormEntity(post_params, "UTF-8"));
   } catch (UnsupportedEncodingException e1) {
     e1.printStackTrace();
   }


   DefaultHttpClient httpClient = new DefaultHttpClient();
   try {

     ret = httpClient.execute(request, new ResponseHandler<String>() {

       @Override
       public String handleResponse(HttpResponse response) throws IOException
       {
         Log.d(
           "posttest",  "code:" + response.getStatusLine().getStatusCode()
         );


         switch (response.getStatusLine().getStatusCode()) {
         case HttpStatus.SC_OK:

           return EntityUtils.toString(response.getEntity(), "UTF-8");

         case HttpStatus.SC_NOT_FOUND:
           return null;

         default:
           return null;
         }

       }
     
     });

   } catch (IOException e) {
     Log.d("posttest", "sippai:" + e.toString());
   } finally {
     httpClient.getConnectionManager().shutdown();
   }

   ed1.setText( ret );
 
   wv.loadDataWithBaseURL("about:blank",ret, "text/html", "UTF-8",null);
 
 }


}

//Index.php
<html>
<head><title>PHP TEST</title></head>
<body>

<p></p>



<?php

if($_SERVER["REQUEST_METHOD"] == "POST"){
    writeData();
}

readData();

function readData(){
    $keijban_file = 'keijiban.txt';

    $fp = fopen($keijban_file, 'rb');

    if ($fp){
        if (flock($fp, LOCK_SH)){
            while (!feof($fp)) {
                $buffer = fgets($fp);
                print($buffer);
            }

            flock($fp, LOCK_UN);
        }else{
            print('haita');
        }
    }

    fclose($fp);
}

function writeData(){

    $contents = $_POST['post_2'];
    $contents = nl2br($contents);

    $data = "<hr>\r\n";
    $data = $data."<p>".$contents."</p>\r\n";

    $keijban_file = 'keijiban.txt';

    $fp = fopen($keijban_file, 'ab');

    if ($fp){
        if (flock($fp, LOCK_EX)){
            if (fwrite($fp,  $data) === FALSE){
                print('kakikomi');
            }

            flock($fp, LOCK_UN);
        }else{
            print('rokku');
        }
    }

    fclose($fp);
}

?>
</body>
</html>