開発環境にwordpressのインストール

mysqlでまずwodpress用のデータベースを作成します。

[vagrant@localhost wordpress]$ mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.34 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create database wordpress;
Query OK, 1 row affected (0.11 sec)

mysql> grant all on wordpress.* to dbuser@localhost identified by 'xxxx';

その後、wp-config-sample.phpをコピーして、wp-config.phpに変更し、ファイルの中身を編集します。

define('DB_NAME', 'wordpress');

/** MySQL データベースのユーザー名 */
define('DB_USER', 'dbuser');

/** MySQL データベースのパスワード */
define('DB_PASSWORD', 'xxxx');

/** MySQL のホスト名 */
define('DB_HOST', 'localhost');

/** データベースのテーブルを作成する際のデータベースの文字セット */
define('DB_CHARSET', 'utf8');

/** データベースの照合順序 (ほとんどの場合変更する必要はありません) */
define('DB_COLLATE', '');

さらに、認証用ユニークキーを追加し、PHPサーバーを立ち上げると、wordpress初期画面が表示されるはずです。

Android studioのインストール

androidのサイトより、android studioをインストールします。ダウンロード・起動に相当の時間がかかります。また、メモリを沢山使用するので確認しておきましょう。

ADVでエミュレーターを立ち上げて、動作確認します。
%e7%84%a1%e9%a1%8c

shiftキーを2回押して、line numberをonに切り替えます。
%e7%84%a1%e9%a1%8c

androidはjavaで書いていきます。画面のクラスの読み込みは、R.idです。

public void changeLabel(View view){
        TextView tv = (TextView)findViewById(R.id.mytextview);
        tv.setText("Changed!");
    }

php ビンゴシート

乱数を生成し、n個切り取る際は、range, shuffle, array_sliceで作ります。
$col = range($i * 15 + 1, $i * 15 + 15);
shuffle($col);
$nums[$i] = array_slice($col, 0, 5);
index.php

<?php
require_once(__DIR__ . '/config.php');
require_once(__DIR__ . '/Bingo.php');

$bingo = new \MyApp\Bingo();
$nums = $bingo->create();

?>
<!DOCTYPE html>
<html lang="ja">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>jQueryスライドショー</title>
    <link rel="stylesheet" href="styles.css">
  </head>
  <body>
    <div id="container">
      <table>
        <tr>
          <th>B</th><th>I</th><th>N</th><th>G</th><th>O</th>
        </tr>
        <?php for ($i = 0; $i < 5; $i++) : ?>
        <tr>
          <?php for ($j = 0; $j< 5; $j++) : ?>
          <td><?= h($nums&#91;$j&#93;&#91;$i&#93;); ?></td>
          <?php endfor; ?>
        </tr>
      <?php endfor; ?>
      </table>
    </div>
  </body>
</html>

php基礎

データの型を確認

var_dump($msg);

定数

var_dump(__LiNE__);
var_dump(__FILE__);
var_dump(__DIR__);

文字列の連結

$s = "hello " . "world";

真偽値

$x = 5;
if ($x){
  echo "great";
}

三項演算子

$max = ($a > $b) ? $a : $b;

配列

$sales = array(
  "yama" => 200,
  "sato" => 400,
  "ito" => 600,
);
var_dump($sales["sato"]);

コロン構文

<ul>
<?php foreach ($colors as $value): ?>
  <li><?php echo "$value"; ?></li>
<?php endforeach; ?>
</ul>

クラス(オーバライドの禁止はメソッド名の前にfinalを付けます)

class User{
  public $name;
  public function __construct($name){
    $this->name = $name;
  }

  public function sayHi(){
    echo "hi, i am $this->name!";
  }
}

$tom =  new User("Tom");
$bob = new User("Bob");

echo $tom->name;
$bob->sayHi();

抽象クラス 

abstract class BaseUser{
  public $name;
  abstract public function sayHi();
}

class User extends BaseUser{
  public function sayHi(){
    echo "hello from user";
  }
}

インターフェイス

interface sayHi {
  public function sayHi();
}

interface sayHello {
  public function sayHello();
}

class User Implements sayHi, sayHello {
  public function sayHi{
    echo "hi";
  }
  public function sayHello{
    echo "hello";
  }
}

Cloud9

Cloud9はクラウドの統合開発環境で、ブラウザ上で手軽に開発環境を用意することができます。
Cloud9

sign inすると、クレジットカードの入力項目があり、ドキッとしますが、登録によるチャージはありません。
%e7%84%a1%e9%a1%8c

初期画面
%e7%84%a1%e9%a1%8c

インターフェイスはdreamweaverっぽいですが、嫌いではないですね。javaのコンソールもあります。
%e7%84%a1%e9%a1%8c

apacheを起動して、サーバー上で確認することも可能です。
JavaScript Consoleはブラウザで閲覧します。php, ruby, pythonはコマンドラインから作っていきましょう。

sqliteはsqliteコマンド、mysqlはmysql-ctl cliを打ち込みます。

cloud9を使えば、railsも簡単に環境をつくることができます。
%e7%84%a1%e9%a1%8c

jQuery thumbnail スライドショー

タイマー処理を使って、自動再生のスライドショーを作成します。
timer = setTimeout(function(){
autoPlay();

<!DOCTYPE html>
<html lang="ja">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>jQueryスライドショー</title>
    <style>
    body {
      margin: 10px auto;
      text-align: center;
    }
     .thumbnail{
          width: 125px;
          height:83px;
          opacity: 0.5;
          cursor:pointer;
     }
     .current {
      opacity: 1;
     }
     .thumbnail + .thumbnail {
      margin-left: 4px;
     }
    </style>
    <link rel="stylesheet" href="styles.css">
  </head>
  <body>
      <div id="thumbnails"></div>
      <div id="main"></div>
      <div id="nav">
          <button id="prev">&laquo; 前へ</button>
          <button id="next">次へ&raquo; </button>
          <button id="play">再生</button>
          <button id="stop">停止</button>
      </div>
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
      <script>
      $(function(){
          var files = [
            '01.jpg',
            '02.jpg',
            '03.jpg',
            '04.jpg'
          ];
            var img;
            var timer;
            var currentNum = 0;
            var nowPlaying = false;
            for (var i = 0; i < files.length; i++){
              img = $('<img>').attr('src', files[i]).addClass('thumbnail');
              $('#thumbnails').append(img);
            }
            $('#main').append(
                $('<img>').attr('src', files[0])
              );
            $('.thumbnail:first').addClass('current');
            $('.thumbnail').click(function(){
              $('#main img').attr('src', $(this).attr('src'));
              currentNum = $(this).index();
              $(this).addClass('current').siblings().removeClass('current');
            });
            $('#prev').click(function(){
              currentNum--;
              if (currentNum < 0){
                currentNum = files.length -1;
              }
              $('#main img').attr('src', files&#91;currentNum&#93;);
              $('.thumbnail').removeClass('current');
              $('.thumbnail').eq(currentNum).addClass('current');
            });
            $('#next').click(function(){
              currentNum++;
              if (currentNum > files.length - 1){
                currentNum = 0;
              }
              $('#main img').attr('src', files[currentNum]);
              $('.thumbnail').removeClass('current');
              $('.thumbnail').eq(currentNum).addClass('current');
            });
            function autoPlay(){
              $('#next').click();
              timer = setTimeout(function(){
                  autoPlay();
              }, 1000);
            }
            $('#play').click(function(){
                  if (nowPlaying) return;
                  nowPlaying = true;
                autoPlay();
            });
            $('#stop').click(function(){
                    clearTimeout(timer);
                    nowPlaying = false;
            });
      });
      </script>
  </body>
</html>

%e7%84%a1%e9%a1%8c

jQuery 間違い探しゲーム

ランダムで、数列に一か所に文字を挿入します。
var offset = Math.floor(Math.random() * chars.length);
chars.splice(offset, 1, seikai);

<!DOCTYPE html>
<html lang="ja">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>間違い探しゲーム</title>
    <style>
        span {
          cusor:pointer;
        }
    </style>
    <link rel="stylesheet" href="styles.css">
  </head>
  <body>
      <h1>間違い探しゲーム</h1>
      <p><input type="button" value="開始!" onclick="gameStart();"></p>
      <div id="score"></div>
      <div id="cells"></div>

      <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
      <script>
          var level = 0;
          var games = [
              ['問', '間'],
              ['大', '太'],
              ['白', '臼']
          ];
          var MAX_LEVEL = games.length - 1;
          var DIM_FIRST = 5;
          var DIM_DELTA = 3;
          var dim = DIM_FIRST;
          var t1;
          var t2;

          function gameStart(){
            var dummy = games[level][0];
            var seikai =games[level][1];

            if (level == 0){
              $('#score').empty();
              t1 = new Date().getTime();
            }
            

            var cells = '';
            for (var i = 1; i <= dim * dim; i++){
              cells += '<span id="s' + i + '"></span>';
              if (i % dim == 0){
                cells += '<br />';
              }
            }
            $('#cells').html(cells);

            var chars = [];
            for (var i = 0; i < dim * dim; i++){
              chars.push(dummy);
            }

            var offset = Math.floor(Math.random() * chars.length);
            chars.splice(offset, 1, seikai);

            // console.log(chars);
            for (var i = 1; i <= chars.length; i++){
              $('#s'+i).text(chars&#91;i-1&#93;);
              $('#s'+i).click(function(){
                if ($(this).text() == seikai){
                  level++;
                  dim += DIM_DELTA;
                  if (level > MAX_LEVEL){
                        t2 = new Date().getTime();
                      $('#score').text('Your score is '+(t2 - t1)/1000 +'!!');
                      level = 0;
                      dim = DIM_FIRST;
                      return false;
                  }
                  gameStart();
                }
              });
            }

          }
      </script>
  </body>
</html>

%e7%84%a1%e9%a1%8c

jQuery ↑にスクロール

アイコンはfadeIn、fadeOutを使用し、アニメーションで何秒で戻るか指定します。

<!DOCTYPE html>
<html lang="ja">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>スクロール</title>
    <style>
        body {
          text-align: center;
        }
    </style>
    <link rel="stylesheet" href="styles.css">
  </head>
  <body>
      <h1>スクロール</h1>
          <p>hello</p>
    <p>hello</p>
    <p>hello</p>
    <p>hello</p>
    <p>hello</p>
    <p>hello</p>
    <p>hello</p>
    <p>hello</p>
    <p>hello</p>
    <p>hello</p>
    <p>hello</p>
    <p>hello</p>
    <p>hello</p>
    <p>hello</p>
    <p>hello</p>
    <p>hello</p>
    <p>hello</p>
    <p>hello</p>
    <p>hello</p>
    <p>hello</p>
    <p>hello</p>
    <div id="back-to-top" style="position:fixed;right:5px; bottom:5px"><a href="#">↑</a></div>
    <div id="pos" style="position:fixed; left:5px; bottom:5px">

      <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
      <script>
      $(function(){
          $('#back-to-top').hide();

          $(window).scroll(function(){
              $('#pos').text($(this).scrollTop());
              if ($(this).scrollTop() > 60 ) {
                $('#back-to-top').fadeIn();
              } else {
                $('#back-to-top').fadeOut();
              }
          });
          $('#back-to-top a').click(function(){
              $('body').animate({
                scrollTop:0
              }, 500);
              return false;
          });
      });
      </script>
  </body>
</html>

%e7%84%a1%e9%a1%8c

JavaScript キャラ診断をツイートしよう

ランダム関数は、Math.floor(Math.random() * types.length、tweetリンクは、twitter developerのweb intentsを使います。

<!DOCTYPE html>
<html lang="ja">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>キャラ診断</title>
    <style>
        body {
          text-align: center;
        }
    </style>
    <link rel="stylesheet" href="styles.css">
  </head>
  <body>
      <h1>キャラ診断</h1>
      <p><input type="text" id="name" value=""></p>
      <p><input type="button" id="getResult" value="診断"></p>
      <h2>診断結果</h2>
      <p id="result">こちらに結果が表示されます。</p>
      <div id="tweet"></div>

      <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
      <script>
          $(function(){
              $("#getResult").click(function(){
                  var name = $("#name").val();
                  // console.log(name);

                    if (name === ""){
                      alert("名前を入力してください!");
                      return;
                    }
                  // タイプの定義
                  var types = ["勇者","魔法使い","戦士","遊び人","スーパースター"];
                  var type = types[Math.floor(Math.random() * types.length)];

                  var character = ["賢い","勇ましい","かわいい","情けない","人気の"];
                  var character = character[Math.floor(Math.random() * character.length)];

                  var result = name + "さんは「" + character + type + "」です。";
                  $("#result").text(result);

                  var tweetLink = "<a href='https://twitter.com/intent/tweet?text="+ encodeURIComponent(result) +"&hashtags=chara' target='_blank'>ツイートする</a>";
                  $("#tweet").html(tweetLink);
              });
          });
      </script>
  </body>
</html>

%e7%84%a1%e9%a1%8c

Ajaxで複数の値を返す

<!DOCTYPE html>
<html lang="ja">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>jQeury</title>
    <style>
    .myStyle{
      border:5px solid green;
      font-size:48px;
    }
    </style>
    <link rel="stylesheet" href="styles.css">
  </head>
  <body>
      <p>jQuery</p>

      <p>
        <input type="text" name="name" id="name">
        <input type="button" id="greet" value="Greet!">
      </p>
      <div id="result"></div>

      <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
      <script>
        $(function(){

          $('#greet').click(function(){

            $.get('greet.php', {
              name: $('#name').val()
            }, function(data){
                $('#result').html(data.message + '(' + data.length + ')');
            });
          });
        });
      </script>
  </body>
</html>
<?php

// echo htmlspecialchars("hi!" . $_GET&#91;"name"&#93;, ENT_QUOTES, "utf-8");

$rs = array(
  "message" => htmlspecialchars("hi!" . $_GET["name"], ENT_QUOTES, "utf-8"),
  "length" => strlen($_GET["name"])
);

header('Content-Type: application/json; charset=utf-8');
echo json_encode($rs);

%e7%84%a1%e9%a1%8c