升级到macOS了,在使用libevent的时候,报这个错:kq_init: detected broken kqueue,导致代码无法使用。
网上查了一下,可以通过一个简单的设定:export EVENT_NOKQUEUE=1,不知道有没有后遗症!
目前这样已经可以使用了。
膘叔的简单人生
升级到macOS了,在使用libevent的时候,报这个错:kq_init: detected broken kqueue,导致代码无法使用。
网上查了一下,可以通过一个简单的设定:export EVENT_NOKQUEUE=1,不知道有没有后遗症!
目前这样已经可以使用了。
一般情况下,editor.md的上传图片功能已经够用了,提供了两种方式:本地上传和跨域上传,方式也很简单,跨域上传的话,则需要加callbackUrl的地址。参考:http://www.ipandao.com/editor.md/examples/image-upload.html 和 http://www.ipandao.com/editor.md/examples/image-cross-domain-upload.html。
不过我的问题和上面的不一样,因为我使用了PHP开发框架,那么在正常开发的过程中,表单提交都有csrf的验证。editor.md却没有这个功能,在官方的issue里有人提出了,可以通过设置uploadUrl来加入get参数。
嗯,理论上这样也OK。然而我使用的是YII2,在实际使用中,这个办法无效,原因是:
public function validateCsrfToken($token = null)
{
$method = $this->getMethod();
// only validate CSRF token on non-"safe" methods http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.1.1
if (!$this->enableCsrfValidation || in_array($method, ['GET', 'HEAD', 'OPTIONS'], true)) {
return true;
}
$trueToken = $this->loadCsrfToken();
if ($token !== null) {
return $this->validateCsrfTokenInternal($token, $trueToken);
} else {
return $this->validateCsrfTokenInternal($this->getBodyParam($this->csrfParam), $trueToken)
|| $this->validateCsrfTokenInternal($this->getCsrfTokenFromHeader(), $trueToken);
}
}
看最后两个判断,只判断了POST和HEADER中有Csrf的情况,没有判断GET参数里的情况,如果你的项目已经趋向于稳定,不再随便升级Yii的版本,你可以在$this->validateCsrfTokenInternal($this->getBodyParam($this->csrfParam), $trueToken)加一行:
|| $this->validateCsrfTokenInternal($this->get($this->csrfParam),$trueToken)
即,允许从GET参数中获取 csrf的值。
然而,很多时间我们都会手贱去composer update,所以这个方法有点不太敢使用。最终,还是决定修改editor.md的插件,在image-dialog.js中加入几行:
if (settings.crossDomainUpload)
{
action += "&callback=" + settings.uploadCallbackURL + "&dialog_id=editormd-image-dialog-" + guid;
}
//在上面的if代码后先加入csrfToken的值的获取
var csrfToken = $('meta[name="csrf-token"]').attr('content');
var csrfField = "";
if (csrfToken) {
var csrfParam = $('meta[name="csrf-param"]').attr('content');
csrfField = "<input type='hidden' name='" + csrfParam + "' value='" + csrfToken + "' />";
}
然后在下面的dialogContent里加入csrfField的内容,使之 变成:
var dialogContent = ( (settings.imageUpload) ? "<form action=\"" + action +"\" target=\"" + iframeName + "\" method=\"post\" enctype=\"multipart/form-data\" class=\"" + classPrefix + "form\">" : "<div class=\"" + classPrefix + "form\">" ) +
( (settings.imageUpload) ? "<iframe name=\"" + iframeName + "\" id=\"" + iframeName + "\" guid=\"" + guid + "\"></iframe>" : "" ) +
"<label>" + imageLang.url + "</label>" +
"<input type=\"text\" data-url />" + (function(){
return (settings.imageUpload) ? "<div class=\"" + classPrefix + "file-input\">" +
"<input type=\"file\" name=\"" + classPrefix + "image-file\" accept=\"image/*\" />" +
csrfField +
"<input type=\"submit\" value=\"" + imageLang.uploadButton + "\" />" +
"</div>" : "";
})() +
"<br/>" +
"<label>" + imageLang.alt + "</label>" +
"<input type=\"text\" value=\"" + selection + "\" data-alt />" +
"<br/>" +
"<label>" + imageLang.link + "</label>" +
"<input type=\"text\" value=\"http://\" data-link />" +
"<br/>" + csrfField +
( (settings.imageUpload) ? "</form>" : "</div>");
注意红字所在地方,其实就加了这个字段而已。再次提交图片上传的时候,不会再报400错误了。
有时候,有一个好的IDE其实也没有用的。就象PhpStorm ,明明有Laravel Plugin,但你会发现,你安装了这个插件,在使用Laravel进行开发的时候,还是什么用都没有,仿佛这个插件就象没有安装似的。
确实,如果不是看到官方的介绍,我就真以为这个插件是弄来玩的。
在要使用LaravelPlugin前,你得做好几个准备工作
1、安装 laravel-ide-helper,这是一个 composer 的库:composer require "barryvdh/laravel-ide-helper":"v2.2.0"
2、在config/app.php中加入:Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class,
3、重建索引,点击菜单:File | Invalidate Crashes / Restart ...,系统会认为你原来是因为出错而重启,重启后会自动重建索引
4、artisan clear-compiled 清除编译缓存
5、artisan ide-helper:generate ,会在项目目录下生成一个_ide_helper.php文件。
然后就完成了所有的配置,你在routes.php中输入Route::get('/test','H'); 你会发现:get方法认到了,输入H的时候,会将你所有的H开头的Controller都认出来。而且会自动将其中的方法形成一个列表,方便你引用。
至此,Laravel的整体插件才算完成(如果你需要自动编译less等,还要安装FileWatch插件)
更详细的教程和图文,详看官方:
1、https://blog.jetbrains.com/phpstorm/2015/01/laravel-development-using-phpstorm/
2、https://confluence.jetbrains.com/display/PhpStorm/Laravel+Development+using+PhpStorm
3、https://github.com/koomai/phpstorm-laravel-live-templates
升级wordpress的时候遇到:Briefly unavailable for scheduled maintenance. Check back in a minute.
新初装服务器的时候,有时候打开vim后中文是乱码,怎么处理呢?
编辑~/.vimrc文件,加上如下几行:
set fileencodings=utf-8,ucs-bom,gb18030,gbk,gb2312,cp936
set termencoding=utf-8
set encoding=utf-8
如果用sql语句来写group by 再count,这样的sql太容易 了。但由于现在都是在用框架,反而这类sql变得难写了。最近在折腾一个用TP 3框架写的代码,原来代码里写的是:
$count = D('Album')->table(T('albums AS a'))
->join(T('union AS u') . ' ON u.id=a.union_id')
->join(T('company AS c') . ' ON c.id=a.store_id')
->join(T('photo AS p') . ' ON a.id=p.parent_id')
->field('a.*,u.name AS union_name,c.name as store_name')
// ->field('count(a.id)')
->where($where)
->group('a.id')
->count();
看起来好象没有问题,但事实上。出来的结果却并不是你想要的,这个count并不是你要的count,而是每个组的条数。当然你也可以用select()来查出数据,再count($count)一下,但如果数据量过大。这样会崩溃 的。
最终用这样的方法解决了:
$numsQuery = D('Album')->table(T('albums AS a'))
->join(T('union AS u') . ' ON u.id=a.union_id')
->join(T('company AS c') . ' ON c.id=a.store_id')
->join(T('photo AS p') . ' ON a.id=p.parent_id')
->field('a.*,u.name AS union_name,c.name as store_name')
// ->field('count(a.id)')
->where($where)
->group('a.id')
->buildSql();
$nums = D()->table("{$numsQuery} as t")->count();
算是曲线求国吧。
其实很多人在问这种问题了,但更多的人建议是直接写sql。我这种是不写sql的啦 ~
设置了远程数据库允许IP连接,也设置了bind ip为0.0.0.0 ,但有时候能连,有时候不能连接,而且还设置了是IP连接,报标题所在的错误,即 [ERROR 1042 (HY000): Can't get hostname for your address]。
开始就在想,是不是skip-name-resolve的问题,但因为我不是用host连接的,也不是内部的域名解析的问题。所以开始没注意,但google了之后,还是决定加了skipnameresolve
ave MySQL 5.5 Server setup on a windows machine. I am able to connect to the server from console / app running on the same machine but not from a remote machine. While connecting using the command
mysql -h xx.xx.xx.xx --port=3306 -u root -p
I get error as:
ERROR 1042 (HY000): Can't get hostname for your address
Have tried putting entry of client ip in server's etc\hosts file as
<client-ip> <client-hostname>
所有的回答都指向了skip-name-resolve
I believe this is to do with the fact that MySQL tries to establish the DNS name associated with your IP address on connect. See here for more information at the MySQL site.
You have two options:
1) Fix the connecting machine's reverse DNS. Since you've already added the machine to the hosts file, this might be unnecessary. You should also issue a FLUSH HOSTS statement on the MySQL server. See the same link above for more information about this.
2) Run MySQL with the '--skip-name-resolve' option. However, if you do this, you won't be able to use DNS names in GRANT statements. Instead you'll be restricted to using IP addresses.
2.1) or put in my.ini :
[mysqld]
skip-name-resolve
I'd recommend (1) if you can.
Hope this helps.
delete from sablog_comments where visible =0 and content REGEXP '^[0-9a-zA-Z]{6} '
2.2升到2.4的小坑应该就出在权限上了
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
allow from all
在2.4下面,上面的代码不报错,但不起作用。如果你的目录下面有.htaccess文件,那么,网站是打不开的,上面的代码改成
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
OK,再次打开就正常了