Skip to content

Instantly share code, notes, and snippets.

View chrisyue's full-sized avatar
:octocat:
=。=

chris yue chrisyue

:octocat:
=。=
View GitHub Profile
@chrisyue
chrisyue / sonata-admin-default-filter.php
Created December 12, 2013 02:43
symfony sonata admin add default filter
public function getFilterParameters()
{
$default = [
'isAudited' => ['value' => 2],
];
$this->datagridValues = array_merge($default, $this->datagridValues);
return parent::getFilterParameters();
}
@chrisyue
chrisyue / ctags-config-for-symfony2.md
Last active March 29, 2018 08:24
ctags-config-for-symfony
-R
--languages=php
--php-kinds=cif
--regex-php=/^[ \t]*trait[ \t]+([a-z0_9_]+)/\1/t,traits/i
--exclude=app/*
--exclude=bin/*
--exclude=web/*
--exclude=tests/*
--exclude=var/*
@chrisyue
chrisyue / pre-commit
Last active November 17, 2017 09:15
pre-commit for php,使用 php -l / phpmd / php-cs-fixer做检查,需要在项目根目录添加phpmd.xml,.php_cs文件
#!/usr/bin/env php
<?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
chrisyue / phpcs.xml
Created September 26, 2017 10:33
php code sniffer snippet
<?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"/>
</rule>
</ruleset>
@chrisyue
chrisyue / recursive-iterator-file.php
Last active September 19, 2016 07:52
通过正则递归搜索指定目录里的文件
<?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
chrisyue / file_get_content_post.php
Created January 15, 2014 10:38
使用file_get_content发送POST请求
function tweet($message, $username, $password)
{
$context = stream_context_create(array(
'http' => array(
'method' => 'POST',
'header' => sprintf("Authorization: Basic %s\r\n", base64_encode($username.':'.$password)).
"Content-type: application/x-www-form-urlencoded\r\n",
'content' => http_build_query(array('status' => $message)),
'timeout' => 5,
),
@chrisyue
chrisyue / vim-verbose-set.md
Created January 14, 2014 15:41
vim察看某个选项被设置的详情

:verbose set isk?

@chrisyue
chrisyue / vim-imap.md
Created January 10, 2014 14:12
vim 察看imap

:verbose imap

@chrisyue
chrisyue / vim-verbose-check-option.md
Created December 29, 2013 18:38
vim查看选项详细设置过程

:verbose se ?

@chrisyue
chrisyue / 庐山烟雨.md
Created December 29, 2013 14:28
苏轼(苏东坡) - 庐山烟雨

庐山烟雨浙江潮

未到千般恨不消

到得原来无别事

庐山烟雨浙江潮