Skip to content

Instantly share code, notes, and snippets.

@fasthold
fasthold / phpunit.xml
Created February 16, 2011 10:01
zend framework phpunit configuration
<phpunit bootstrap="./TestHelper.php" colors="true">
<!-- Version: $Id$ -->
<testsuite name="Zend Framework Unit Test Demo">
<directory>./</directory>
</testsuite>
<filter>
<whitelist>
<directory suffix=".php">../library/</directory>
<directory suffix=".php">../application/</directory>
@fasthold
fasthold / MapReduce_test.php
Created March 7, 2011 06:39
利用 mongodb mapreduce 计算数量总和
<?php
$mongo = new Mongo();
$db = $mongo->selectDb('firv_exam');
// 要查询的collection
$collection = 'question';
// 构造 map 和 reduce 函数
$map = <<<MAP
function() { emit(this.username,1); } // this.username 相当于 sql 里的 group by username
@fasthold
fasthold / 查询包含 sim 的记录
Created March 8, 2011 08:51
简易模糊查询 按相关性排序 SQL语句
SELECT * , IF( `Word` = 'sim', 1, IF( `Word` LIKE 'sim%', 2, IF( `Word` LIKE '%sim', 4, 3 ) ) ) AS `sort` FROM `dblist` WHERE `Word` LIKE '%sim%' ORDER BY `sort` , `Word`
# 得到结果:
1. sim
2. sim*
3. *sim*
4. sim*
@fasthold
fasthold / Pdo_Mysql.php
Created July 17, 2011 09:49
简易封装PDO_MySQL
<?php
/**
* Pdo MySql driver wrap
*
* @category Class
* @package Fasthold Own PHP Snippet
* @copyright Copyright (c) 2007
* @license New BSD License
* @author Fasthold Lau ([email protected])
*/
@fasthold
fasthold / gist:1357342
Created November 11, 2011 06:22
利用Imagick将pdf转为图片
<?php
/**
* PDF2PNG
* @param $pdf 待处理的PDF文件
* @param $path 待保存的图片路径
* @param $page 待导出的页面 -1为全部 0为第一页 1为第二页
* @return 保存好的图片路径和文件名
*/
function pdf2png($pdf,$path,$page=-1)
{
@fasthold
fasthold / gist:1446080
Created December 8, 2011 04:09
有效的中文型用户名检测
function check_username($username) {
$guestexp = ‘\xA1\xA1|\xAC\xA3|^Guest|^\xD3\xCE\xBF\xCD|\xB9\x43\xAB\xC8′;
$len = $this->dstrlen($username);
if($len > 15 || $len < 3 || preg_match(“/\s+|^c:\\con\\con|[%,\*\"\s\<\>\&]|$guestexp/is”, $username)) {
return FALSE;
} else {
return TRUE;
}
}
@fasthold
fasthold / gist:4490336
Last active December 10, 2015 20:48
装好ubuntu desktop后的那些事
sudo apt-get update
sudo apt-get install build-essential vim gvim git gitk
mkdir ~/temp
mkdir ~/app
# 安装 chrome
sudo apt-get install chromium-browser
# 安装 sublime text
cd ~/temp
<?php
/**
* 加密 hash,生成发送给用户的 hash 字符串
*
* @param array $hash_data
* @param string $hash_key
* @return string
*/
function encode_hash($hash_data, $hash_key = false)
@fasthold
fasthold / preload.js
Created May 12, 2013 10:01
Preload images so simple.
// From http://stackoverflow.com/questions/476679/preloading-images-with-jquery
function preload(arrayOfImages) {
$(arrayOfImages).each(function(){
$('<img/>')[0].src = this;
// Alternatively you could use:
// (new Image()).src = this;
});
}
@fasthold
fasthold / composer.json
Last active December 19, 2015 13:59
The useful "wheel"
{
"require": {
"silex/silex": "1.1.*@dev",
"respect/validation": "dev-develop",
"symfony/browser-kit": "2.4",
"monolog/monolog": "1.6.*@dev",
"cartalyst/sentry": "2.0.*",
"illuminate/database": "4.1.*",
"ircmaxell/password-compat": "*",
"gabordemooij/redbean": "dev-master"