Skip to content

Instantly share code, notes, and snippets.

View forecho's full-sized avatar
🎯
Focusing

蔡正海 forecho

🎯
Focusing
View GitHub Profile
@forecho
forecho / Snoopy.class.php
Created September 14, 2014 16:06
爬虫类
<?php
/*************************************************
*
* Snoopy - the PHP net client
* Author: Monte Ohrt <monte@ohrt.com>
* Copyright (c): 1999-2014, all rights reserved
* Version: 2.0.0
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@forecho
forecho / amh.sh
Created October 13, 2014 12:47
LNMP 一键安装包括控制面板
#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
clear;
echo '================================================================';
echo ' [LNMP/Nginx] Amysql Host - AMH 4.2 ';
echo ' http://Amysql.com';
echo '================================================================';
@forecho
forecho / 0_reuse_code.js
Last active August 29, 2015 14:21
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@forecho
forecho / Security.php
Last active August 29, 2015 14:22
创建一个随机字符串
<?php
/**
* author : forecho <caizhenghai@gmail.com>
* createTime : 2015/6/10 10:27
* description:
*/
class Security
{
/**
@forecho
forecho / unlink.php
Last active August 29, 2015 14:26
删除匹配的所有文件
@forecho
forecho / log.php
Last active September 14, 2015 02:05
Yii2 在线查看日志功能 使用方法:放在web目录下。
<?php
/**
* author : forecho <caizhenghai@gmail.com>
* createTime : 2015/7/9 16:32
* description:
*/
if (!isset($_GET['auth']) || $_GET['auth'] != "forecho") {
die();
}
@forecho
forecho / uploadcontroller.php
Last active September 15, 2015 06:00 — forked from appcodr/uploadcontroller.php
REST API controller code in Yii2 to upload photo/file
<?php
class UploadController extends ActiveController
{
public $documentPath = 'documents/';
public function verbs()
{
$verbs = parent::verbs();
$verbs[ "upload" ] = ['POST' ];
@forecho
forecho / random.php
Created November 8, 2015 05:28
百万数据库某个表「伪」随机显示 N 条数据思路
/**
* 随机
* @param int $rows 数据池
* @return mixed
*/
protected function random($rows = 100)
{
$count = User::find()->select(['itemid'])->where([])->count();
$random = mt_rand($rows, $count - $rows);
$model = User::find()->where(['>=', 'id', $random])->joinWith(['type'])->limit($rows)->all();
@forecho
forecho / array_last.php
Created November 8, 2015 08:24
php获取数组最后一个数组值的三个方法
<?php
$array=array(1,2,3,4,5);
echo $array[count($array)-1];//计算数组长度,然后获取数组最后一个元素,如果数组中最后一个元素含有非数字键名,结果可能跟预期不符合
//适用于键名为数字的数组
echo '<br>';
echo end($array);//将数组的内部指针指向最后一个单元,适用于所有数组
echo '<br>';
rsort($array);//对数组逆向排序,如果数组中含有字母或汉字,结果可能不符合预期,最适用于数字数组
echo $array[0];
@forecho
forecho / httpClient.php
Last active November 18, 2015 10:11
封装 curl 类
<?php
function httpClient($url, $data = FALSE, $header = FALSE, $timeout = 30)
{
if (!strstr($url, 'http://') && !strstr($url, 'https://')) {
$url = 'http://' . $url;
}
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);