Skip to content

Instantly share code, notes, and snippets.


chris yue chrisyue

View GitHub Profile
chrisyue / phpcs.xml
Created Sep 26, 2017
php code sniffer snippet
View phpcs.xml
<?xml version="1.0"?>
<ruleset name="Symfony2 Project">
<description>Coding sniffer rules for Symfony2</description>
<rule ref="Symfony2">
<exclude name="Symfony2.Commenting.ClassComment"/>
<exclude name="Symfony2.Commenting.FunctionComment"/>
<exclude name="PEAR.Functions.FunctionCallSignature.Indent"/>
chrisyue / recursive-iterator-file.php
Last active Sep 19, 2016
View recursive-iterator-file.php
foreach (new RegexIterator(new RecursiveIteratorIterator(new RecursiveDirectoryIterator('.', FilesystemIterator::SKIP_DOTS)), '/\.m3u8$/') as $file) {
$name = $file->getBasename(sprintf('.%s', $file->getExtension()));
$content = file_get_contents($file->getRealPath());
$newContent = str_replace($name, urlencode($name), $content);
file_put_contents($file->getRealPath(), $newContent);
chrisyue / .php_cs.php
Last active Aug 29, 2015
php-cs-fixer config for Symfony2 project
View .php_cs.php
$finder = Symfony\CS\Finder\DefaultFinder::create()
return Symfony\CS\Config\Config::create()
View Grant
grant CREATE,INSERT,DELETE,UPDATE,SELECT on pauldb.* to paul@localhost identified by 'password' with grant option
View 全角转半角
$str = "0123ABCDFWS\",.?<>{}[]*&^%#@!~()+-|:;";
echo "$str";
echo "<br />";
$str = preg_replace('/\xa3([\xa1-\xfe])/e', 'chr(ord(\1)-0x80)', $str);
echo $str;
View git-cheat-sheet
// rename local branch
git branch -m <old> <new>
git branch -m <new>
chrisyue / phpmd.xml
Created Mar 8, 2014
phpmd ruleset overview
View phpmd.xml
<?xml version="1.0"?>
<ruleset name="xxx"
<!-- @see -->
<rule ref="rulesets/codesize.xml/CyclomaticComplexity"/>
chrisyue / pre-commit
Last active Nov 17, 2017
pre-commit for php,使用 php -l / phpmd / php-cs-fixer做检查,需要在项目根目录添加phpmd.xml,.php_cs文件
View pre-commit
#!/usr/bin/env php
// 使用 php -l / phpmd / php-cs-fixer做检查,需要在项目根目录添加phpmd.xml(如果使用phpmd),.php_cs(如果使用phpcs并且有自定义的配置)文件
// 使用前执行 chmod +x path/to/pre-commit
exec('git diff HEAD --name-only --diff-filter=AMRC', $filenames);
$filenames = array_filter($filenames, function($filename) {
return pathinfo($filename, PATHINFO_EXTENSION) === 'php';
chrisyue / composer.json
Last active Aug 29, 2015
global composer.json php常用工具
View composer.json
"require": {
"composer/composer": "dev-master",
"phpmd/phpmd": "dev-master",
"fabpot/php-cs-fixer": "dev-master",
"phpunit/phpunit": "3.7.*",
"sebastian/phpcpd": "*",
"phpdocumentor/phpdocumentor": "2.*",
"sami/sami": "1.*",
"squizlabs/php_codesniffer": "dev-master"
chrisyue /
Created Feb 12, 2014
curl | python -mjson.tool