Skip to content

Commit

Permalink
更新
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexchent committed Jan 7, 2020
1 parent eecd96d commit 9f09110
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 2 deletions.
1 change: 1 addition & 0 deletions Framework/Autoload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?phpnamespace interview\Loader;class Autoload{ static public function autoload($class){ spl_autoload_register(); }}
Expand Down
45 changes: 45 additions & 0 deletions Framework/Loader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace Framework;


class Loader
{

/**
* 注册自动加载类文件方法
*/
public static function registerAutoLoad()
{
spl_autoload_register("\Framework\Loader::autoLoad");
}

/**
* 自动加载的目录
* @var array
*/
private static $dirs = array();

public static function addAutoloadDIR($dir)
{
self::$dirs[] = $dir;
}

/**
* 自动加载类文件
* @param string $class
*/
public static function autoLoad($class)
{
$file = str_replace('\\', '/', $class) . ".php";
foreach (self::$dirs as $dir) {
$tmp = $dir . "/" . $file;
if (file_exists($tmp)) {
return require_once $tmp;
}
}

echo $class . ' not exist!';

}
}
8 changes: 8 additions & 0 deletions Helper/Tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -343,5 +343,13 @@ public static function getRelativePath($a, $b)
}


public static function getmicrotime(){
list($u,$s) = explode('', microtime());
$num = (float)$u + (float)$s;
return sprintf("%.4f", $num);

}



}
1 change: 1 addition & 0 deletions Helper/fordir.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php/** * 遍历指定目录下的所有目录和文件 * Created by PhpStorm. * User: chentao * Date: 2019/12/22 * Time: 3:50 PM */function get_dir_info($path){ $handle = opendir($path);//打开目录返回句柄 while(($content = readdir($handle))!== false){ $new_dir = $path . '/' . $content; if($content == '..' || $content == '.'){ continue; } if(is_dir($new_dir)){ echo "目录:".$new_dir . "\n"; get_dir_info($new_dir); }else{ echo "文件:".$path.'/'.$content ."\n"; } }}get_dir_info(__DIR__);
Expand Down
1 change: 1 addition & 0 deletions cli/c.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php/************************************* * PHP amqp(RabbitMQ) Demo - consumer * Author: Linvo * Date: 2012/7/30 *************************************///配置信息$conn_args = array( 'host' => '127.0.0.1', 'port' => '5672', 'login' => 'admin', 'password' => 'admin', 'vhost'=>'/');$e_name = 'e_linvo'; //交换机名$q_name = 'q_linvo'; //队列名$k_route = 'key_1'; //路由key//创建连接和channel$conn = new AMQPConnection($conn_args);if (!$conn->connect()) { die("Cannot connect to the broker!\n");}$channel = new AMQPChannel($conn);//创建交换机$ex = new AMQPExchange($channel);$ex->setName($e_name);$ex->setType(AMQP_EX_TYPE_DIRECT); //direct类型$ex->setFlags(AMQP_DURABLE); //持久化echo "Exchange Status:".$ex->declare()."\n";//创建队列$q = new AMQPQueue($channel);$q->setName($q_name);$q->setFlags(AMQP_DURABLE); //持久化echo "Message Total:".$q->declare()."\n";//绑定交换机与队列,并指定路由键echo 'Queue Bind: '.$q->bind($e_name, $k_route)."\n";//阻塞模式接收消息echo "Message:\n";while(True){ $q->consume('processMessage');}$conn->disconnect();/** * 消费回调函数 * 处理消息 */function processMessage($envelope, $queue) { $msg = $envelope->getBody(); echo $msg."\n"; //处理消息 $queue->ack($envelope->getDeliveryTag()); //手动发送ACK应答}
Expand Down
4 changes: 4 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{ "require":{
"ezyang/htmlpurifier": "^4.12",
"swoole/ide-helper": "@dev"
}}
Expand Down
2 changes: 2 additions & 0 deletions getVideoTxt.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
include 'cli/pachong.php';


echo 111;die;

$redis = new Redis();
$redis->pconnect('127.0.0.1','6379');

Expand Down
1 change: 1 addition & 0 deletions suanfa/shunzi.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php/** * Created by PhpStorm. * User: chentao * Date: 2019/12/15 * Time: 11:41 AM *///判断5个数字组合为顺子。0可以准换为任何数function isShunzi($arr){ $brr = array_count_values($arr); foreach ($brr as $key => $value) { }}
Expand Down
1 change: 1 addition & 0 deletions suanfa/topk.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php/** * Created by PhpStorm. * User: chentao * Date: 2019/12/24 * Time: 11:56 AM *///生成小顶堆函数function Heap(&$arr,$idx){ $left = ($idx << 1) + 1; $right = ($idx << 1) + 2; if (!isset($arr[$left])){ return; } if(isset($arr[$right]) && $arr[$right] < $arr[$left]){ $l = $right; }else{ $l = $left; } if ($arr[$idx] > $arr[$l]){ $tmp = $arr[$idx]; $arr[$idx] = $arr[$l]; $arr[$l] = $tmp; Heap($arr,$l); }}//这里为了保证跟上面一致,也构造500w不重复数/* 当然这个数据集并不一定全放在内存,也可以在 文件里面,因为我们并不是全部加载到内存去进 行排序*/ini_set('memory_limit', '1024M');$numArr = range(0,5000000,1);//打乱它们shuffle($numArr);//先取出10个到数组$topArr = array_slice($numArr,0,10);//获取最后一个有子节点的索引位置//因为在构造小顶堆的时候是从最后一个有左或右节点的位置//开始从下往上不断的进行移动构造(具体可看上面的图去理解)$idx = floor(count($topArr) / 2) - 1;//生成小顶堆for($i=$idx;$i>=0;$i--){ Heap($topArr,$i);}var_dump(microtime());list($t1, $t2) = explode(' ', microtime());$st = (float)sprintf('%.0f', floatval($t1) + floatval($t2)*1000);//这里可以看到,就是开始遍历剩下的所有元素for($i = count($topArr); $i < count($numArr); $i++){ //每遍历一个则跟堆顶元素进行比较大小 if ($numArr[$i] > $topArr[0]){ //如果大于堆顶元素则替换 $topArr[0] = $numArr[$i]; /* 重新调用生成小顶堆函数进行维护,只不过这次是从堆顶 的索引位置开始自上往下进行维护,因为我们只是把堆顶 的元素给替换掉了而其余的还是按照根节点小于左右节点 的顺序摆放这也就是我们上面说的,只是相对调整下,并 不是全部调整一遍 */ Heap($topArr,0); }}var_dump($topArr);list($t1, $t2) = explode(' ', microtime());$et = (float)sprintf('%.0f', floatval($t1) + floatval($t2)*1000);echo $et - $st;
Expand Down
2 changes: 1 addition & 1 deletion test.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php/** * Created by PhpStorm. * User: chentao * Date: 2019/12/5 * Time: 11:02 AM */declare(strict_types=0);include "Helper/Tools.php";static $c =1;$d = 3;$res1 = test(1.5,2);var_dump($res1);$res2 = test(1.5,2);var_dump($res2);function test(int $a, int $b) :int { static $d = 4; $res = $a + $b; if(isset($c)) { $res += $c; } if(isset($d)) { $res += $d; $d += 1.5; } return $res;}die;class A { private $x = 1;}// PHP 7 之前版本定义闭包函数代码$getXCB = function() { return $this->x;};// 闭包函数绑定到类 A 上//$getX = $getXCB->bindTo(new A, 'A');//echo $getX();//print(PHP_EOL);echo $getXCB->call(new A, 'A');
<?php/** * Created by PhpStorm. * User: chentao * Date: 2019/12/5 * Time: 11:02 AM *///declare(strict_types=0);$a = array (1, 2, array ("a", "b", "c"));var_export($a);die;$redis = new Redis();$redis->connect('127.0.0.1',3306);die;class A { private $x = 1;}// PHP 7 之前版本定义闭包函数代码$getXCB = function() { return $this->x;};// 闭包函数绑定到类 A 上//$getX = $getXCB->bindTo(new A, 'A');//echo $getX();//print(PHP_EOL);echo $getXCB->call(new A, 'A');
Expand Down
1 change: 0 additions & 1 deletion xss.html

This file was deleted.

0 comments on commit 9f09110

Please sign in to comment.