Category Archives: 开发

使用cron监测mysql状态并自动重启

腾讯云上部署了一个 wordpress,mysql 常常因为服务器负载过大导致进程被 kill 掉
没太多时间处理这些东西,比如优化性能,静态化,资源放 cdn 等,写个脚本定时检测 mysql 状态,跪掉的话自动重启就好了,有时间再慢慢搞。
对了,我的系统是 debian8

#!/bin/sh
pidof mysqld >/dev/null
if [ $? -eq 0 ]
then
    echo "It is running."
else
    echo "At date MySQL Server was stopped">> /home/mysql_log
    /etc/init.d mysql restart
fi

新建脚本后执行 crontab –e,在文件末尾添加定时任务 /2 * sh /path/to/restart_mysql.sh 每两分钟检查一次状态。
问题完美

php dyld: Library not loaded: /usr/local/lib/libjpeg.8.dylib 错误

通过 brew 升级了一下 mac 上安装的包,php 开始报 dyld: Library not loaded: /usr/local/lib/libjpeg.8.dylib 的错误。
比较明显的看出是依赖出了问题,上 stackoverflow 查一下,已经有解决的方法了。
排行第一的答案的方法是手动下载 jpeg 包的源码,本地编译安装。我这样有点洁癖的不太喜欢本地编译安装的方式,管理起来太麻烦了。既然是brew 升级造成的问题,我更倾向于直接降级。
其他答案里也提供了降级的方案:

brew switch jpeg 8d

如果这个命令提示jpeg does not have a version "8d" in the Cellar.brew 仓库里不存在8d 的版本
需要手动回滚 brew 仓库版本进行安装

cd $(brew --prefix)/Homebrew/Library/Taps/homebrew/homebrew-core
git checkout b231469
HOMEBREW_NO_AUTO_UPDATE=1 brew install jpeg
git checkout master

最后重新执行上面第一步的命令,就修复好了。
参考:
https://stackoverflow.com/questions/32703296/dyld-library-not-loaded-usr-local-lib-libjpeg-8-dylib-homebrew-php

小米电视 4A 65 寸 开箱记录

家里装修好住进来3个多月,电器都还没配全。一是这些电器用到的频率比较小,早点装迟点装影响不是很大,二是装完修,手上并没有太多的闲钱。不过再怎么没钱,结婚前还是要把所有东西配齐的。
这周配了一个小米电视。买电视前稍微看了下相关资料,电视还是索尼的比较好,另外在推荐的观看距离里,电视越大越好。我们家里客厅比较小,座位到电视墙的距离就2.3M 左右,这个距离正好是65寸电视推荐的最小观看距离,但是电视墙又比较大,如果放了比较小的电视,看起来会比较 Low,权衡之下,还是决定买65寸的电视。
淘宝上看了下65寸索尼电视65寸要1.5w,着实有点贵。花这么多钱买个平时不太用的电器感觉有点不值。问了下身边刚装修完的几个同事买的什么电视,发现清一色的都是买小米电视。又问了下小米电视广告多的问题,发现广告多的问题其实有几种处理的方式。就安心的决定买小米电视了。毕竟价格在这里,是索尼同等大小价格的三分之一,差太大了。
65寸的小米电视有4,4A,4A 语言版,3S,3S 曲面版等5个型号。官网对比发现4A 和3S 版本配置基本相同,后者在某些地方还比前者要好一些,比如智能背光,更高的NTSC参数,USB 3.0,更薄的机子等,最关键的,3S 配备了小米家庭影院音响系统,这个在小米官网独立售价就是1999元。而3S标准版只比4A 标准版贵了1000元。这让人十分心动。我旁边工位的同事也是看中这点买了3S。我最初也是决定买 3S 的。
买电视的时候正好遇上各大电商的818大促活动,点开小米官网,各个商品也和其他电商一样在做活动,不同的小米电视都有优惠三四百,五六百块钱。看到 3S 有便宜300块钱非常高兴。但是点开详情页的时候,我就有点不好了,显示已经售罄。马上点开小米天猫旗舰店,3S 也是售罄状态。我就不淡定了,花这么多时间决定好的型号没了,我又回到了原点。重新找个型号还是怎样呢。闲想间又逛了下小米官网,意外看到4A 型号促销便宜1300元,这样的优惠估计是不常有。这里面也有一点猫腻,3S 的优惠是有包邮的,而4A 的优惠没有包邮,邮费报价300元,所以实际上只是优惠了1000元,这下算上独立的音响系统,价格是和3S 一样了。既然3S 售罄,也没有其他好的选择了 ,于是立马下了个单。
下单的时候还有点意外,选错了付款方式,本来是可以花呗6期免息分期的,选成了用信用卡全款付款。想后台退款了重新拍一单,但是后台竟然没有取消订单的功能。联系了下客服,表示也不知道,但是可以工作人员手工取消订单,需要等待24个小时。这服务简直眼瞎。不想折腾,就算了。
周日下的单,工作日家里都没人,联系物流下周六送货。下单的时候小米系统给自动预约了上门安装服务,安装工人和物流之间没有系统调配。自己做了协调。
周六送货过来,配送员会帮你开箱通电,检查显示器完整及漏光情况。也就插上电源开机看了下。中午12点送的电视,预约的是3点钟过来安装。但是安装工人并不是很准时,过来安装的时候已经6点了。两个工人,安装其实比较简单,其中一个工人只是帮忙抬下电视,并不需要做其他事情。在电视墙上打孔,安装支架。打孔比较粗暴,打孔周围前面都有一些裂缝,粉刷的墙面都有点掉下来。反正都在电视后面,没有太计较。
有个不太方便的地方是,4A 的背面接口面板比较靠里面,挂上去之后想再接其他线,比如挂个移动硬盘,比较麻烦。线路面板不在电视中央,背景墙上开的隐形线路管道距离有点远,线路要穿进去的话需要很长的线。我的机顶盒的线就不够长,只能放外面过。显得有点丑。

hexo, A fast, simple & powerful blog framework, powered by Node.js.

this post was written a few mouth ago. And for some reason, my idea had changed.
if you are a geeker, and you use github, you must have know github pages, and something like Jekyll or Octopress.
I tried Octopress last year, and find it quite complex to use. As someone in V2EX said, Octopress is for someone called "SBC", i do think so (but Octopress’s default theme is more beautiful).
then i tried several other static website generator, like nico, hexo etc. i found that hexo quite easy to use, the properity of written in nodejs is friendly to frontend developers.
reference:
http://zespia.tw/hexo/

What 10 things should you do every day to improve your life?

总是高兴不太起来,闲逛时候看到的一篇文章,放着提醒自己,不要悲伤!
1) Get out in nature:
You probably seriously underestimate how important this is. (Actually, there’s research that says you do.) Being in nature reduces stress, makes you more creative, improves your memory and may even make you a better person.
2) Exercise:
We all know how important this is, but few people do it consistently. Other than health benefits too numerous to mention, exercise makes you smarter, happier, improves sleep, increases libido and makes you feel better about your body. A Harvard study that has tracked a group of men for more than 70 years identified it as one of the secrets to a good life.
3) Spend time with friends and family:
Harvard happiness expert Daniel Gilbert identified this as one of the biggest sources of happiness in our lives. Relationships are worth more than you think (approximately an extra $131,232 a year.) Not feeling socially connected can make you stupider and kill you. Loneliness can lead to heart attack, stroke and diabetes. The longest lived people on the planet all place a strong emphasis on social engagement and good relationships are more important to a long life than even exercise. Friends are key toimproving your life. Share good news and enthusiatically respond when others share good news with you to improve your relationships. Want to instantly be happier? Dosomething kind for them.
4) Express gratitude:
It will make you happier.
It will improve your relationships.
It can make you a better person.
It can make life better for everyone around you.
5) Meditate:
Meditation can increase happiness, meaning in life, social support and attention span while reducing anger, anxiety, depression and fatigue. Along similar lines, prayer can make you feel better — even if you’re not religious.
6) Get enough sleep:
You can’t cheat yourself on sleep and not have it affect you. Being tired actually makes it harder to be happy. Lack of sleep = more likely to get sick. “Sleeping on it” does improve decision making. Lack of sleep can make you more likely to behave unethically. There is such a thing as beauty sleep.
Naps are great too. Naps increase alertness and performance on the job, enhance learning ability and purge negative emotions while enhancing positive ones. 
7) Challenge yourself:
Learning another language can keep your mind sharp. Music lessons increase intelligence. Challenging your beliefs strengthens your mind. Increasing willpower just takes a little effort each day and it’s more responsible for your success than IQ. Not getting an education or taking advantage of opportunities are two of the things people look back on their lives and regret the most.
8) Laugh:
People who use humor to cope with stress have better immune systems, reduced risk of heart attack and stroke, experience less pain during dental work and live longer. Laughter should be like a daily vitamin. Just reminiscing about funny moments can improve your relationship. Humor has many benefits.
9) Touch someone:
Touching can reduce stress, improve team performance, and help you be persuasive. Hugs make you happier. Sex may help prevent heart attacks and cancer, improve your immune system and extend your life.
10) Be optimistic:
Optimism can make you healthier, happier and extend your life. The Army teaches it in order to increase mental toughness in soldiers. Being overconfident improves performance.
Read more: http://www.bakadesuyo.com/2012/05/what-10-things-should-you-do-every-day-to-imp/