Skip to content

Instantly share code, notes, and snippets.

<?php
function autoload($className)
{
$className = ltrim($className, '\\');
$fileName = '';
$namespace = '';
if ($lastNsPos = strrpos($className, '\\')) {
$namespace = substr($className, 0, $lastNsPos);
$className = substr($className, $lastNsPos + 1);
@jamesBan
jamesBan / password hash
Last active August 29, 2015 14:02
password hash
<?php
class PassHash {
// blowfish
private static $algo = '$2a';
// cost parameter
private static $cost = '$10';
// mainly for internal use
public static function unique_salt() {
@jamesBan
jamesBan / check signature
Last active August 29, 2015 14:02
reset api check Signature
<?php
class Demo
{
/**
* @var string
*/
public static $ACCESS_KEY = 'KUN6xYZlOAtid2MjHm90-6VFY2M7HC90ijDH4uOR';
/**
* @var string
<?php
$perror = function($msg){
$errorCode = socket_last_error();
$errorMsg = socket_strerror($errorCode);
exit("$msg: [$errorCode] $errorMsg\r\n");
};
if(!$socket = socket_create(AF_INET, SOCK_STREAM, 0)){
$perror('could not create scoket');
<?php
$data = array('name' => 'zhangsan');
$post_data = http_build_query($data);
$http = "POST /site/test HTTP/1.1\r\n";
$http .= "Host: example.com\r\n";
$http .= "User-Agent: " . $_SERVER['HTTP_USER_AGENT'] . "\r\n";
$http .= "Content-Type: application/x-www-form-urlencoded\r\n";
$http .= "Content-length: " . strlen($post_data) . "\r\n";
$http .= "Connection: close\r\n\r\n";
<?php
$options = array(
'http' => array(
'method' => "POST",
'header' =>
"Accept-language: en\r\n" .
"Content-type: application/x-www-form-urlencoded\r\n",
'content' => http_build_query(array('name' => 'zhangsan'))
));
function getImg($url)
{
$data = parse_url($url);
$referer = $data['scheme'] . '://' . $data['host'];
$options = array(
'http' => array(
'method' => 'GET',
'header' => "Referer:{$referer}\r\nCache-Control: max-age=3600\r\n",
'timeout'=> 1,
)
<?php
/**
* Aspect
* @source http://www.jaceju.net/blog/archives/327/
*
*/
class Aspect
{
/**
* Name of target class
<?php
do{
$retry = false;
$try_num = 1;
try{
$db->exec('UPDATE table num = num + 1 where id = 1;');
} catch (Exception $e) {
if($e->getMessage() == 'error message' && $try_num < 10) {
@jamesBan
jamesBan / get china street data
Created July 24, 2014 07:35
获取具体省份下的街道数据
<?php
set_time_limit(0);
//省份id
$id = isset($_GET['id']) ? intval($_GET['id']) : 33;
//市
$url = "http://www.stats.gov.cn/tjsj/tjbz/tjyqhdmhcxhfdm/2013/{$id}.html";
$province = pathinfo($url, PATHINFO_FILENAME);