PHP anonymous function

<?php
$a = array(
    array('name' => 'tom', 'distance' => 20)
    , array('name' => 'anny', 'distance' => 18)
    , array('name' => 'jack', 'distance' => 22)
);
 
 
//$a = array(3, 2, 5, 6, 1);
 
usort($a, function($a, $b,$key="distance")
          {
              if ($a[$key] == $b[$key]) {
                  return 0;
              }
              return ($a[$key] < $b[$key]) ? -1 : 1;
          }
);
 
foreach ($a as $key => $value) {
    var_dump($value);
}

How to use prerender on your website?

https://prerender.io/documentation

It’s a simple way to test prerender, maybe you need change some code in your project.

1. Singup a account at https://prerender.io
2. Setup a prerendertest directory,like below:
/prerendertest/data.php
/prerendertest/index.html

/prerendertest/data.php

    {
    "records":[
    {"Name":"Alfreds Futterkiste","City":"Berlin","Country":"Germany"},
    {"Name":"Ana Trujillo Emparedados y helados","City":"México D.F.","Country":"Mexico"},
    {"Name":"Antonio Moreno Taquería","City":"México D.F.","Country":"Mexico"},
    {"Name":"Around the Horn","City":"London","Country":"UK"},
    {"Name":"B's Beverages","City":"London","Country":"UK"},
    {"Name":"Berglunds snabbköp","City":"Luleå","Country":"Sweden"},
    {"Name":"Blauer See Delikatessen","City":"Mannheim","Country":"Germany"},
    {"Name":"Blondel père et fils","City":"Strasbourg","Country":"France"},
    {"Name":"Bólido Comidas preparadas","City":"Madrid","Country":"Spain"},
    {"Name":"Bon app'","City":"Marseille","Country":"France"},
    {"Name":"Bottom-Dollar Marketse","City":"Tsawassen","Country":"Canada"},
    {"Name":"Cactus Comidas para llevar","City":"Buenos Aires","Country":"Argentina"},
    {"Name":"Centro comercial Moctezuma","City":"México D.F.","Country":"Mexico"},
    {"Name":"Chop-suey Chinese","City":"Bern","Country":"Switzerland"},
    {"Name":"Comércio Mineiro","City":"São Paulo","Country":"Brazil"}
    ]
    }

/prerendertest/index.html

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <meta name="fragment" content="!">
    <script src="https://cdn.bootcss.com/angular.js/1.6.3/angular.min.js"></script>
    </head>
    <body>
 
    <div ng-app="myApp" ng-controller="customersCtrl">
 
    <table>
      <tr ng-repeat="x in names">
        <td>{{ x.Name }}</td>
        <td>{{ x.Country }}</td>
      </tr>
    </table>
 
    </div>
 
    <script>
    var app = angular.module('myApp', []);
    app.controller('customersCtrl', function($scope, $http) {
        $http.get("/prerendertest/data.php")
        .then(function (result) {
            $scope.names = result.data.records;
        });
    });
    </script>
 
    </body>
    </html>

3. Config your nginx
Reference here https://gist.github.com/thoop/8165802

4. Visit http://xxx.com/prerendertest/index.html?_escaped_fragment_=, then view source of the html

MYSQL order by rand() optimize

http://www.jcodecraeer.com/a/chengxusheji/java/2017/0109/6960.html

No more “order by rand()” in code.

#0.0012s
SELECT * FROM `content` 
WHERE id >= (SELECT FLOOR(RAND() * (SELECT MAX(id) FROM `content`)))  
ORDER BY id ASC LIMIT 10;
 
#0.2s
SELECT * FROM `content`
ORDER BY RAND() LIMIT 10;

SWOT个人分析

S 擅长写一些服务端,应用层的代码。
W 不擅长学习新的代码语言,不擅长写客户端等。眼光不够长远,格局不够开阔。对用户的喜好不敏感,不擅长捕获。

O 通过和老板合作,团队成员合作完成一个产品的制作。通过和别人合作运营产品,提供技术支持。
T 局限于自己的小思维,不和人沟通,不结交认识心得朋友