07-05
0
laravel
1.创建一个名为laravel的laravel项目
composer create-project laravel/laravel --prefer-dist ./QZ_20_0712
命令解释:
composer:表示执行该程序;
create-project :创建项目
laravel/laravel:需要创建的项目名称;
–prefer-dist:优先下载压缩包方式,而不是直接从GitHub上下载源码
2.php artisan
(1)数据表
//创建迁移 建表
php artisan make:migration create_demo_table
//重建数据库,在原本的迁移文件中增加字段后执行
php artisan migrate:refresh
//数据表迁移
php artisan migrate
//数据表回滚
php artisan migrate:rollback
(2)功能列表
php artisan list
(3)make 列表
make:cast Create a new custom Eloquent cast class
make:channel Create a new channel class
make:command Create a new Artisan command
make:component Create a new view component class
make:controller Create a new controller class
make:event Create a new event class
make:exception Create a new custom exception class
make:export Create a new export class
make:factory Create a new model factory
make:import Create a new import class
make:job Create a new job class
make:listener Create a new event listener class
make:mail Create a new email class
make:middleware Create a new middleware class
make:migration Create a new migration file
make:model Create a new Eloquent model class
make:notification Create a new notification class
make:observer Create a new observer class
make:policy Create a new policy class
make:provider Create a new service provider class
make:request Create a new form request class
make:resource Create a new resource
make:rule Create a new validation rule
make:seeder Create a new seeder class
make:test Create a new test class
06-13
0
Docker
1.安装Docker
//Centos
yum install docker
2.docker 基础命令
//启动docker
systemctl start docker
//关闭docker
systemctl stop docker
//重启docker
systemctl restart docker
//docker设置随服务启动而自启动
systemctl enable docker
//查看docker 运行状态
systemctl status docker
3.docker 镜像命令
//查看自己服务器中docker 镜像列表
docker images
//搜索镜像
docker search 镜像名
docker search --filter=STARS=9000 mysql 搜索 STARS >9000的 mysql 镜像
//拉取镜像
docker pull 镜像名
docker pull 镜像名:tag
//删除镜像
#删除一个
docker rmi -f 镜像名/镜像ID
#删除多个 其镜像ID或镜像用用空格隔开即可
docker rmi -f 镜像名/镜像ID 镜像名/镜像ID 镜像名/镜像ID
#删除全部镜像 -a 意思为显示全部, -q 意思为只显示ID
docker rmi -f $(docker images -aq)
//强制删除镜像
docker image rm 镜像名称/镜像ID
4.docker 容器命令
//查看正在运行容器列表
docker ps
//查看所有容器 -----包含正在运行 和已停止的
docker ps -a
//运行一个容器
# -it 表示 与容器进行交互式启动 -d 表示可后台运行容器 (守护式运行) --name 给要运行的容器 起的名字 /bin/bash 交互路径
docker run -it -d --name 要取的别名 镜像名:Tag /bin/bash
05-16
0
PHP常用代码
PHP读写文件的方法
文件操作
// 判断是否是一个文件
var_dump(is_file('./demo.txt')); // bool(true)
// 读取文件字节数
var_dump(filesize('./demo.txt')); // int(11)
// 文件重命名
rename('./demo.txt', './demo.txt.bak');
// 删除文件
unlink('./demo.txt');
写入文件
// 打开文件
$file = fopen('./demo.txt', 'w');
// 只读:r
// 读写,文件覆盖:r+
// 清空写入:w
// 可创建清空写入:w+
// 追加写入:a
// 创建追加写入:a+
// 写入内容到文件
fwrite($file, 'Hello World');
// 关闭文件
fclose($file);
读取文件内容
// 写入内容到文件
fwrite($file, 'Hello World');
// 关闭文件
fclose($file);
$file = fopen('./demo.txt', 'r');
$filesize = filesize('./demo.txt');
$content = fread($file, $filesize);
var_dump($content); // string(11) "Hello World"
fclose($file);
通过快捷方式读取文件内容
// 读取文件到数组
$lines = file('./demo.txt');
var_dump($lines);
// array(4) {
// [0]=>string(7) "赠人"
// [1]=>string(22) "李群玉〔唐代〕"
// [2]=>string(49) "曾留宋玉旧衣裳,惹得巫山梦里香。"
// [3]=>string(48) "云雨无情难管领,任他别嫁楚襄王。"
// }
// 读取文件内容
$lines = file_get_contents('./demo.txt');
var_dump($lines);
// string(126) "赠人
// 李群玉〔唐代〕
// 曾留宋玉旧衣裳,惹得巫山梦里香。
// 云雨无情难管领,任他别嫁楚襄王。"
05-10
0
iOS 多线程
一、iOS中常见的多线程方案
1、pthread
- 一套通用的多线程API
- 适用于Unix\Linux\Windows等系统
- 跨平台、可移植
- 使用难度大
- 使用C语言
- 程序员管理线程生命周期
- 实际项目中几乎不用
2、NSThread
- 使用更加面向对象
- 简单易用、可直接操作线程对象
- 使用OC语言
- 程序员管理线程生命周期
- 实际项目中几乎不用
3、GCD
- 旨在替代NSThread技术
- 充分利用设备的多核
- 使用C语言
- 自动管理线程生命周期
- 实际项目中经常使用
4、NSOperation
- 基于GCD(底层是GCD)
- 比GCD多了一些简单实用的功能
- 使用更加面向对象
- 使用OC语言
- 自动管理线程生命周期
- 实际项目中经常使用
二、GCD
1、GCD有两个用来执行任务的函数
- 同步(sync):只能在当前线程中执行任务,不具备开启新线程的能力,任务立刻马上执行,会阻塞当前线程并等待 Block中的任务执行完毕dispatch函数才会返回,然后当前线程才会继续往下运行。
- 异步(async):可以在新的线程中执行任务,具备开启线程的能力,但不一定会开启新的线程,dispatch函数会立即返回, 然后Block在后台异步执行,即当前线程会直接往下执行,不会阻塞当前线程。
#pragma mark - 同步执行
- (void)syncQueue {
NSLog(@"同步主线程开始");
//创建串行队列
dispatch_queue_t queue = dispatch_queue_create("com.weixin.globalQueue", DISPATCH_QUEUE_SERIAL);
dispatch_sync(queue, ^{
NSLog(@"同步线程");
});
NSLog(@"同步主线程结束");
}
#pragma mark - 异步执行
- (void)asyncQueue {
NSLog(@"异步主线程开始");
dispatch_queue_t queue = dispatch_queue_create("com.qq.globalQueue", DISPATCH_QUEUE_SERIAL);
dispatch_async(queue, ^{
NSLog(@"异步线程");
});
NSLog(@"异步主线程结束");
}
2、队列
用于存放任务,分为串行队列和并行队列。
- 串行队列:所有任务会在一条线程中执行(有可能是当前线程也有可能是新开辟的线程),并且一个任务执行完毕后,才开始执行下一个任务。
- 并行队列:可以开启多条线程并行执行任务(但不一定会开启新的线程),并且当一个任务放到指定线程开始执行时,下一个任务就可以开始执行了
- 创建队列:
1.串行队列
//创建串行队列
dispatch_queue_t firstQueue = dispatch_queue_create("com.weibo", DISPATCH_QUEUE_SERIAL);
2.并行队列
//创建并行队列
dispatch_queue_t secondQueue = dispatch_queue_create("com.facebook", DISPATCH_QUEUE_CONCURRENT);
3.创建全局默认并发队列
//创建全局默认并发队列
/**
第一个参数:优先级 也可直接填后面的数字
#define DISPATCH_QUEUE_PRIORITY_HIGH 2 // 高
#define DISPATCH_QUEUE_PRIORITY_DEFAULT 0 // 默
#define DISPATCH_QUEUE_PRIORITY_LOW (-2) // 低
#define DISPATCH_QUEUE_PRIORITY_BACKGROUND INT16_MIN // 后台
第二个参数: 预留参数 0
*/
dispatch_queue_t queue3 = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
4.获取主队列
//获取主队列
dispatch_queue_t mainQueue = dispatch_get_main_queue();
5.队列组
dispatch_group_async & dispatch_group_notify
#pragma mark - 队列组
- (void)GCDGroup {
//创建队列组
dispatch_group_t group = dispatch_group_create();
//1.开子线程下载图片
//创建队列(并发)
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
//下载图片1
dispatch_group_async(group, queue, ^{
NSURL *url = [NSURL URLWithString:@"http://www.huabian.com/uploadfile/2015/0914/20150914014032274.jpg"];
NSData *data = [NSData dataWithContentsOfURL:url];
self.image1 = [UIImage imageWithData:data];
NSLog(@"image1 ==== %@",self.image1);
});
//下载图片2
dispatch_group_async(group, queue, ^{
NSURL *url = [NSURL URLWithString:@"http://img1.3lian.com/img2011/w12/1202/19/d/88.jpg"];
NSData *data = [NSData dataWithContentsOfURL:url];
self.image2 = [UIImage imageWithData:data];
NSLog(@"image2 ==== %@",self.image2);
});
//group中所有任务执行完毕,通知该方法执行
dispatch_group_notify(group, queue, ^{
//开启图形上下文
UIGraphicsBeginImageContext(CGSizeMake(200, 200));
//画1
[self.image1 drawInRect:CGRectMake(0, 0, 200, 100)];
//画2
[self.image2 drawInRect:CGRectMake(0, 100, 200, 100)];
//根据图形上下文拿到图片
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
//关闭上下文
UIGraphicsEndImageContext();
//回到主线程刷新UI
dispatch_async(dispatch_get_main_queue(), ^{
self.imageView.image = image;
NSLog(@"%@--刷新UI",[NSThread currentThread]);
});
});
}