Mysql错误:mysql Illegal mix of collations for operation like

Posted in 杂项 on November 5th, 2014 by Adam

原因是datetime和autoincrement id不能用like。就是这样。

论程序员的幸福感

Posted in Coding on October 8th, 2014 by Adam

程序员的幸福感是什么?你想一辈子写程序,却没有幸福感,那么你是很难一直写下去的。

所谓程序员的幸福感就是:

  • 写程序有自由感
  • 写程序很享受、有惬意感
  • 写程序有灵感、才思泉涌感
  • 写程序有成就感、荣誉感
  • 写程序足够养家,可以体面地活下去

如果满足上述条件,我就觉得可以一辈子写程序,写一辈子程序。

$.parseJSON Unexpected token t错误

Posted in javascript on September 12th, 2014 by Adam

常见的原因是:双引号内的引号需要双重释义。例如:”description”:”Created for \\”zhaiduo.com\\””

验证json格式是否有问题,可以看这里:http://jsonlint.com/

Tags:

ImageMagic把pdf转成jpg出现黑色块的问题

Posted in Linux/Unix on August 28th, 2014 by Adam

今天发现有些pdf转成img后出现黑色块,根据这里的解释,很有可能是pdf用的是透明背景,而不是白色背景。所以,解决办法就是:

命令行增加: -background white -alpha remove

问题解决。

现代浏览器工作原理

Posted in webapp, 浏览器 on August 28th, 2014 by Adam

翻译自:adobe博客

Modern browsers typically have two important threads of execution. These threads work together to render a web page:
现代浏览器渲染网页的两个重要线程:主线程和合成线程

The main thread
The compositor thread
Typically, the main thread is responsible for:
主线程主要负责:

Running your JavaScript.
执行js脚本
Calculating your HTML elements’ CSS styles.
计算页内元素样式
Laying out your page.
装载网页
Painting your elements into one or more bitmaps.
把元素画进一个或多个位图
Handing these bitmaps over to the compositor thread.
把这些位图移交给合成线程
Typically, the compositor thread is responsible for:
合成线程主要负责:

Drawing bitmaps to the screen via the GPU.
用GPU把位图渲染到屏幕
Asking the main thread to update bitmaps for visible or soon-to-be-visible parts of the page.
通知主线程更新可见位图,或者准备位图
Figuring out which parts of the page are visible.
画出位图的可见部分
Figuring out which parts are soon-to-be-visible when you’re scrolling.
准备即将可见的位图部分
Moving parts of the page when you scroll.
屏幕滚动式,渲染对应部分到屏幕
The main thread can be busy for long periods of time running your JavaScript or painting a large element.
这个时候主线程可能忙得不亦乐乎,由于你调用js脚本,或者渲染大型页内元素
While it’s busy, it’s not responsive to user input.
所以,对用户的事件毫无响应

On the other hand, the compositor thread tries to stay extremely responsive to user input.
另一方面,合成线程却对用户的事件有求必应
The compositor tries to redraw the page 60 times per second when the page is changing, even if the page is incomplete.
当网页发生变化时,合成线程尽力做到每秒渲染页面60次,甚至在页面还没有被准备好时。

For example, when the user scrolls a page, the compositor thread asks the main thread to update the bitmaps for newly visible parts of the page.
例如:用户滑动网页,合成线程就会要求主线程为新的页面生成新的位图
However, if the main thread doesn’t respond quickly enough, the compositor doesn’t wait.
然而,主线程并不能立即响应,合成线程也不会等下去
The compositor draws the parts of the page it has so far and draws white elsewhere.
合成线程依然把页面画出来,没有完成的页面部分就被填充成白色(常见这种情况google chrome)

The GPU
I mentioned the compositor thread draws bitmaps to the screen using the GPU. Let’s quickly go over the GPU.
下面讲讲GPU的处理部分

The GPU is a chip found in most phones, tablets, and computers today. It’s extremely specialized,
现代手机、平板已经完全支持GPU芯片
meaning it’s really good at certain things, and it’s not that great at others.
它非常擅长做一些事

GPUs are really fast at:
它的强项有:

Drawing to the screen.
画图到屏幕
Drawing the same bitmap over and over again.
不断的重复画图
Drawing the same bitmap in a different position, rotation, or scale.
根据不同位置、旋转度、缩放画同一幅图

GPUs are relatively slow at:
当然,它也有不擅长

Loading bitmaps into their memory.
把位图装载进内存。

Tags:

前端打包压缩合并工具Fis

Posted in webapp on August 18th, 2014 by Adam

由百度开发的前端打包压缩合并工具Fis,为你解决前端资源的打包压缩问题,赞~!。

首先,把npm切换成国内镜像,加快模块下载速度。感谢淘宝npm
$ npm install -g cnpm –registry=https://registry.npm.taobao.org
以后通过cnpm来下载模块。

然后,安装fis: cnpm install -g fis

然后启动:fis server start

下载fis demo,cd到demo目录,开始测试。

通过修改fis-conf.js配置,运行fis release -omp进行各种压缩合并和优化操作。

fis server open可以打开输出目录,查看生成的合并文件。

seajs开发环境搭建

Posted in webapp on August 15th, 2014 by Adam

seajs是基于CMD规范的前端开发工具,和基于AMD的requireJs不同,seajs有着更适合国人使用习惯的使用方法。搭建好Python, nodeJs, npm, grunt开发环境后, 安装好spm2:
$ npm install spm@2.x -g
$ npm install spm-build -g

spm基于gruntjs构建,使用更简单,复杂应用可自行配置gruntfile.js,进行编译。

windows下需要安装GNU win32的make工具, 包括make和coreutils包。(记得设置环境变量)
测试用例采用qunit环境,测试文件放入tests\suites目录下,需要在seajs.use中测试。

更多参考:
seajs配置:https://github.com/seajs/seajs/issues/262

Yii PHPUnit

Posted in 单元测试 on August 11th, 2014 by Adam

在yii protected/tests/目录下运行:phpunit unit进行单元测试,出现各种错误:
比如pear install phpunit/DbUnit或者PHP_Invoker找不到,这个需要PHP支持pcntl模块,windows下不支持。

如果出现如下错误:
PHPUnit_Extensions_Story_TestCase.php failed to open yii\framework\YiiBase.php
可以尝试安装:
pear install phpunit/PHPUnit_Story
注意:phpunit的pear库已经移到phpunit.de,并且在2014年底,安装方式会有变化。

You have installed PHPUnit via PEAR. This installation method is no longer
supported and http://pear.phpunit.de/ will be shut down no later than
December, 31 2014.

一般常见找不到问题,可以通过下面来安装,找不到可以pear search试试。

pear install phpunit/PHPUnit
pear install phpunit/PHPUnit_Selenium
pear install phpunit/PHP_Invoker
pear install phpunit/PHPUnit_Story
pear install phpunit/DbUnit

具体测试过程中,Yii include的错误,可以直接注释,或者disable掉

//////////////// yii\framework\test\CTestCase.php
//require_once(‘PHPUnit/Runner/Version.php’);
//require_once(‘PHPUnit/Util/Filesystem.php’); // workaround for PHPUnit <= 3.6.11

spl_autoload_unregister(array(‘YiiBase’,’autoload’));
//require_once(‘PHPUnit/Autoload.php’);
spl_autoload_register(array(‘YiiBase’,’autoload’)); // put yii’s autoloader at the end
////////////////

Failed opening PHPUnit_Extensions_Story_TestCase.php yii\framework\YiiBase.php
disable include path:
YiiBase::$enableIncludePath=false;

Tags: ,
RSS Feed