mac上spacemacs体验小记

安装

第一步,安装emacs-ma

emacs-mac是对GNU的emacs为mac环境进行了一定的定制,可能体验会更好一点。那就卸载掉以前的emacs,装下吧
$ brew remove emacs$ brew tap railwaycat/emacsmacport$ brew install emacs-mac --with-spacemacs-icon
其中最后一步会花费比较长的时间,我当时在make阶段足足花费了近10分钟...

第二步,克隆下spacemacs的配置...

阅读全文

一个将多说的头像变成https的简单方法

最近启用全站https之后,却发现地址栏里面却还没有小绿锁 -- 检查了下网络请求,发现原来是多说搞的鬼
多说的头像有一些不是https的,如http://wx.qlogo.cn/mmopen/5YxiaxTAIu0nOId2JW67SDEgJqPNjx33IeUNG5QJLuddhd45icL0R905icmdXbSib4H9FLib1IUsjA67ePswvZ9PxVA/0
其实呢,就上面这个这个头像而言,将http协议改成https协议后其实也是能够访问的。所以呢,就有了一个很简单的解决方案:首先,把多说的嵌入脚本下载保存到本地。
wget https://static.duoshuo.com/embed.js
其次,打开这个文件,格式化一下,找到avatarUrl这个函数,将其修改为这样:
avatarUrl: function (e) {return ((e.avatar_url || rt.data.default_avatar_url) + '').replace(/^http:/, location.protocol);}
最后,压缩下这个js,并替换原本的js:
<script type="text/javascript">var duoshuoQuery = {short_name:"<%= config.duoshuo_shortname %>"};setTimeout(function() {var ds = document.createElement('script');ds.type = 'text/javascript';ds.async = true;ds.src = '/lib/duoshuo-embed.min.js';ds.charset = 'UTF-8';(document.getElementsByTagName('head')[0]|| document.getElementsByTagName('body')[0]).appendChild(ds);}, 10);</script>
构建并发布网站,OK了。有个小bug:如果头像的服务器不支持https的话,就无法显示头像了。这其实也是有办法解决的,比如搞个反向代理,将http转换成https。不过有点麻烦,懒得弄了。阅读全文

一个关于systemd私有目录的奇怪问题

今天遇到一个奇怪的问题 -- PHP里面访问不了/tmp/xhprof-data目录,可是这个目录明明是存在的!今天要使用xhprof进行性能分析,但是打开性能分析开关然后访问页面后却发现没有任何性能数据,很奇怪。检查了下httpd的日志,发现有个fatal error:PHP Fatal error: Uncaught exception 'ErrorException' with message 'fopen(/tmp/xhprof-data/57ad36118dcf0.default.xhprof): failed to open stream: No such file or directory'而对应的PHP代码是类似这样:$file = fopen($filePath, 'w');一般来说这个错误应该是目录不存在或权限不足导致的。那么就检查下对应的目录:
➜  /tmp$ ll -d xhprof-datadrwxrwxrwx. 2 apache apache 41 Aug 12 10:34 xhprof-data
目录是存在的呀,而且为了让PHP能访问,特意设置了全部可以读写,并且所属的用户和组都是apache。然后在代码里面测试下这个目录是否可以访问:
// 简单粗暴点,直接加一行打印看看var_dump(is_dir(dirname($filePath)));die;
结果令人吃惊 -- 居然打印出来是false。难道路径错了吗?把路径也重新打印出来核对下:
// 简单粗暴点,直接加一行打印看看var_dump(dirname($filePath));die;
路径打印出来就是/tmp/xhprof-data,没有错!奇葩问题呀!最后尝试删除掉这个目录,然后在PHP里面加一行自动创建目录:
is_dir(dirname($filePath)) or mkdir(dirname($filePath), 0777, true);
结果,居然通了!到tmp目录下看看跟之前创建的有啥区别:
➜  /tmp$ ll xhprof-datals: cannot access xhprof-data: No such file or directory
奇怪了,目录呢? 使用find找下试试:
➜  /tmp$ find . -type d -name xhprof-datafind: ‘./systemd-private-bd5ddddffb9240cdad836fe13ccb096d-httpd.service-kCEghE’: Permission denied➜  /tmp$ sudo !!➜  /tmp$ sudo find . -type d -name xhprof-data./systemd-private-bd5ddddffb9240cdad836fe13ccb096d-httpd.service-kCEghE/tmp/xhprof-data
原来是放到了systemd-private-bd5ddddffb9240cdad836fe13ccb096d-httpd.service-kCEghE下面。这个是个什么鬼? 据google一下的结果,原来是systemd可以配置/tmp目录为私有目录,以防冲突而创建的。检查下配置:
➜  /tmp$ cat /usr/lib/systemd/system/httpd.service | grep PrivateTmpPrivateTmp=true
果然是有对应的这个配置。涨姿势了。特此记录。阅读全文

如何在静态博客HEXO中只显示摘要信息

默认情况下hexo博客(如本站)的首页显示的是完整的文章 -- 而文章比较长的时候这无疑会带来诸多不遍。 那怎么样才能只显示个摘要呢?方法说白了,其实很简单 -- 只要加入一个<!-- more -->这样的占位符在文章正文里面即可:
这就是一个简介<!-- more -->这里更多的内容
注意:这个占位符貌似只能另起一行,不能放在行内。阅读全文

如何解决Selenium中”Cannot find function addEventListener in object [object HTMLDocument]”的错误

今天遇到一个很坑爹的问题,某Selenium自动化用例老是失败,报错如下
1) App\Tests\***********Facebook\WebDriver\Exception\UnknownServerException: TypeError: Cannot find function addEventListener in object [object HTMLDocument]. (http://**********/*)Failed to take screen-shot: org.openqa.selenium.htmlunit.HtmlUnitDriver cannot be cast to org.openqa.selenium.TakesScreenshot
Google了下这个错误,发现暂时没有适合我的解决方案:
  1. 有的方案建议换firefox来测试 -- 可是我们的这个自动化用例是要跑在一台linu...
阅读全文

PHP下使用强大的imagick轻松生成组合缩略图

最近有个需求是要把多张图片组合起来生成缩略图,刚好可以用强大的imagick扩展。这里说的imagickImageMagick在PHP下的扩展。使用pecl安装起来那叫一个轻松简单 —— 一条命令就搞定:
sudo pecl install imagick
(扩展装好后还是要在php.ini中加上extension=imagick.so,然后记得重启apachePHP-fpm服务。)这个需求是要这样生成缩略图:
  1. 如果有1张图片,就直接生成这张图片的缩略图;
  2. 如果有2张图片,则一张在左边一张在右边,各一半;
  3. 如果有3张图片,则两张左边平均分配,一张独占右边;...
阅读全文

PHP中的null合并运算符

null合并运算符是一个好东西,有了它我们就能很方便的获取一个参数,并能在其为空的情况下提供一个默认值。比如在js中可以用||来搞:
function setSomething(a){a = a || 'some-default-value';// ...}
而在PHP中,可惜PHP的||总是返回truefalse,无法这样来搞。PHP7才正式加入了??这个运算符:
// 获取user参数的值(如果为空,则用'nobody')$username = $_GET['user'] ?? 'nobody';// 等价于:$username = isset($_GET['user']) ? $_GET['user'] : 'nobody';
PHP7 估计还有很长时间才能用到生产环境中,那在目前的PHP5中有没有替代方案呢?据研究,完全有个非常便捷的替代方案:
// 获取user参数的值(如果为空,则用'nobody')$username = @$_GET['user'] ?: 'nobody';// 等价于:$username = isset($_GET['user']) ? $_GET['user'] : 'nobody';
-- 运行此代码:https://3v4l.org/aDUW8瞪大了眼睛看,跟前面的PHP7的例子差不多,主要是把??替换为了?:。 这个是个什么鬼呢?其实这就是(expr1) ? (expr2) : (expr3)表达式的省略模式:
表达式 (expr1) ? (expr...
阅读全文

PlantUML的实例参考

Alice -> Bob: Authentication RequestBob --> Alice: Authentication ResponseAlice -> Bob: Another authentication RequestAlice <-- Bob: another authentication Response

actor Foo1boundary Foo2control Foo3entity Foo4database Foo5Foo1 -> Foo2 : To boundaryFoo1 -> Foo3 : To controlFoo1 -> Foo4 : To entityFoo1 -> Foo5 : To database

actor Bob #red' The only difference between actor'and participant is the drawingparticipant Aliceparticipant "I have a really\nlong name" as L #99FF99/' You can also declare:participant L as "I have a really\nlong name"  #99FF99'/Alice->Bob: Authentication RequestBob->Alice: Authentication ResponseBob->L: Log transaction

Alice -> "Bob()" : Hello"Bob()" -> "This is very\nlong" as Long' You can also declare:' "Bob()" -> Long as "This is very\nlong"Long --> "Bob()" : ok

Alice->Alice: This is a signal to self.\nIt also demonstrates\nmultiline \ntext

Bob ->x AliceBob -> AliceBob ->> AliceBob -\ AliceBob \\- AliceBob //-- AliceBob ->o AliceBob o\\-- AliceBob <-> AliceBob <->o Alice

Bob -[#red]> Alice : helloAlice -[#0000FF]->Bob : okautonumberBob -> Alice : Authentication RequestBob <- Alice : Authentication Responseautonumber 15Bob -> Alice : Another authentication RequestBob <- Alice : Another authentication Responseautonumber 40 10Bob -> Alice : Yet another authentication RequestBob <- Alice : Yet another authentication Responseautonumber "<b>[000]"Bob -> Alice : Authentication RequestBob <- Alice : Authentication Responseautonumber 15 "<b>(<u>##</u>)"Bob -> Alice : Another authentication RequestBob <- Alice : Another authentication Responseautonumber 40 10 "<font color=red><b>Message 0  "Bob -> Alice : Yet another authentication RequestBob <- Alice : Yet another authentication Response

title Simple communication exampleAlice -> Bob: Authentication RequestBob --> Alice: Authentication ResponseAlice -> Bob : Hellolegend rightShortlegendendlegend

Alice -> Bob : message 1Alice -> Bob : message 2newpageAlice -> Bob : message 3Alice -> Bob : message 4newpage A title for the\nlast pageAlice -> Bob : message 5Alice -> Bob : message 6

Alice -> Bob: Authentication Requestalt successful caseBob -> Alice: Authentication Acceptedelse some kind of failureBob -> Alice: Authentication Failuregroup My own labelAlice -> Log : Log attack startloop 1000 timesAlice -> Bob: DNS AttackendAlice -> Log : Log attack endendelse Another type of failureBob -> Alice: Please repeatend

Alice->Bob : hellonote left: this is a first noteBob->Alice : oknote right: this is another noteBob->Bob : I am thinkingnote lefta notecan also be definedon several linesend note

participant Aliceparticipant Bobnote left of Alice #aquaThis is displayedleft of Alice.end notenote right of Alice: This is displayed right of Alice.note over Alice: This is displayed over Alice.note over Alice, Bob #FFAAAA: This is displayed\n over Bob and Alice.note over Bob, AliceThis is yet anotherexample ofa long note.end note

caller -> server : conReqhnote over caller : idlecaller <- server : conConfrnote over server"r" as rectangle"h" as hexagonendrnote

participant Aliceparticipant "The **Famous** Bob" as BobAlice -> Bob : hello --there--... Some ~~long delay~~ ...Bob -> Alice : oknote leftThis is **bold**This is //italics//This is ""monospaced""This is --stroked--This is __underlined__This is ~~waved~~end noteAlice -> Bob : A //well formatted// messagenote right of AliceThis is <back:cadetblue><size:18>displayed</size></back>__left of__ Alice.end notenote left of Bob<u:red>This</u> is <color #118888>displayed</color>**<color purple>left of</color> <s:red>Alice</strike> Bob**.end notenote over Alice, Bob<w:#FF33FF>This is hosted</w> by <img sourceforge.jpg>end note

== Initialization ==Alice -> Bob: Authentication RequestBob --> Alice: Authentication Response== Repetition ==Alice -> Bob: Another authentication RequestAlice <-- Bob: another authentication Response

participant Aliceactor Bobref over Alice, Bob : initAlice -> Bob : helloref over BobThis can be onseveral linesend ref

Alice -> Bob: Authentication Request...Bob --> Alice: Authentication Response...5 minutes latter...Bob --> Alice: Bye !

Alice -> Bob: message 1Bob --> Alice: ok|||Alice -> Bob: message 2Bob --> Alice: ok||45||Alice -> Bob: message 3Bob --> Alice: ok

participant UserUser -> A: DoWorkactivate AA -> B: << createRequest >>activate BB -> C: DoWorkactivate CC --> B: WorkDonedestroy CB --> A: RequestCreateddeactivate BA -> User: Donedeactivate A

participant UserUser -> A: DoWorkactivate A #FFBBBBA -> A: Internal callactivate A #DarkSalmonA -> B: << createRequest >>activate BB --> A: RequestCreateddeactivate Bdeactivate AA -> User: Donedeactivate A

Bob -> Alice : hellocreate OtherAlice -> Other : newcreate control StringAlice -> Stringnote right : You can also put notes!Alice --> Bob : ok

[-> A: DoWorkactivate AA -> A: Internal callactivate AA ->] : << createRequest >>A<--] : RequestCreateddeactivate A[<- A: Donedeactivate A

[-> Bob[o-> Bob[o->o Bob[x-> Bob[<- Bob[x<- BobBob ->]Bob ->o]Bob o->o]Bob ->x]Bob <-]Bob x<-]

@startuml/'This is an example Sequence diagramShowing a fictional web feature flowIt is easy to see roles & responsibilities for each componentand easy to change them too...'/title "Story Feature Example - Sequence Diagram"'This is a single line comment/'This is a multi-line commentOne another line'/actor User'boundary Proxyparticipant UIServer as UIparticipant APIUser -> UI: LINK: goto /account pageactivate UIUI -> User:deactivate UIactivate Usernote over UserRequirments:UI: Setting PageClick delete buttonend note' user requests account/delete pageUser -> UI: /account/deletedeactivate Useractivate UIUI -> User:deactivate UI' confirmation formactivate Usernote over UserUI: FormAre you sure?end noteUser -> UI: POST /account/deletedeactivate Useractivate UInote over UI: Verify: user has confirmedUI -> API: /account/deleteactivate APIAPI -> API: deleteAPI -> UI: donedeactivate APIUI -> User: successdeactivate UI@enduml

阅读全文