$.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: ,

node_modules无法删除integration错误

Posted in webapp on August 6th, 2014 by Adam

windows下删除web app的node_modules目录,可能出现无法删除integration错误的提示,根据这里的解释,源自windows路径长度的限制,造成这个bug。

This is the maximum length of a path according to the Windows API, defined as 260 characters.

解决办法:

http://support.microsoft.com/?kbid=320081

you can delete a file named “lpt1″ if you specify the full path of the file by using the following special syntax:
del \\?\c:\path_to_file\lpt1

或者直接把太深的目录拖到浅一点的目录。

Tags:

CentOs6.5测试Hadoop

Posted in 云时代 on July 30th, 2014 by Adam

References:

http://www.michael-noll.com/tutorials/running-hadoop-on-ubuntu-linux-single-node-cluster/

http://wiki.apache.org/hadoop/GettingStartedWithHadoop

http://blog.csdn.net/fuwencaho/article/details/37727873

/////////////////////////////////////////////////////////////

=======
Test Single-node-cluster Hadoop on CentOS6.5
=======

wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.i686.rpm
yum remove java-1.5.0-*
yum install java-1.6.0-openjdk.i686
export JAVA_HOME=/usr/lib/jvm/jre-1.6.0-openjdk
java -version

sudo groupadd hadoop
sudo useradd -g hadoop hduser

ssh-keygen -t rsa
cat $HOME/.ssh/id_rsa.pub >> $HOME/.ssh/authorized_keys

/etc/sysctl.conf
# disable ipv6
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1

cd /usr/local

http://mirrors.hust.edu.cn/apache/hadoop/core/hadoop-2.4.1/hadoop-2.4.1.tar.gz

cd /usr/local
$ sudo tar xzf hadoop-1.0.3.tar.gz
$ sudo mv hadoop-1.0.3 hadoop
$ sudo chown -R hduser:hadoop hadoop

//////////////////////////////

vi $HOME/.bashrc
=====================================
# Set Hadoop-related environment variables
export HADOOP_HOME=/usr/local/hadoop

# Set JAVA_HOME (we will also configure JAVA_HOME directly for Hadoop later on)
export JAVA_HOME=/usr/lib/jvm/jre-1.6.0-openjdk

# Some convenient aliases and functions for running Hadoop-related commands
unalias fs &> /dev/null
alias fs=”hadoop fs”
unalias hls &> /dev/null
alias hls=”fs -ls”

# If you have LZO compression enabled in your Hadoop cluster and
# compress job outputs with LZOP (not covered in this tutorial):
# Conveniently inspect an LZOP compressed file from the command
# line; run via:
#
# $ lzohead /hdfs/path/to/lzop/compressed/file.lzo
#
# Requires installed ‘lzop’ command.
#
lzohead () {
hadoop fs -cat $1 | lzop -dc | head -1000 | less
}

# Add Hadoop bin/ directory to PATH
export PATH=$PATH:$HADOOP_HOME/bin
===================================

/////////////////

$ sudo mkdir -p /app/hadoop/tmp
$ sudo chown hduser:hadoop /app/hadoop/tmp
# …and if you want to tighten up security, chmod from 755 to 750…
$ sudo chmod 750 /app/hadoop/tmp

/usr/local/hadoop/bin/hadoop namenode -format

echo “foo foo quux labs foo bar quux” | python ./mapper.py
echo “foo foo quux labs foo bar quux” | python ./mapper.py | sort -k1,1 | /home/hduser/reducer.py

if Error:
hadoop ssh: Could not resolve hostname
try:
sbin/start-dfs.sh

if Error:
cat: /usr/local/hadoop/conf/slaves: No such file or directory
try:
cp /hadoop/etc/hadoop/slaves /hadoop/conf/

if Error:
-copyFromLocal: /home/hduser No such file or directory
try:
/usr/local/hadoop$ hdfs dfs -mkdir -p /user/hduser

Test with 332KB text:
/usr/local/hadoop/bin/hadoop dfs -copyFromLocal /home/hduser/tmp/*.txt /user/hduser/adam/
/usr/local/hadoop/bin/hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-2.4.1.jar wordcount /user/hduser/adam/*.txt /user/hduser/adam-out
/usr/local/hadoop/bin/hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-2.4.1.jar wordcount -D mapred.reduce.tasks=16 /user/hduser/adam/*.txt /user/hduser/adam-out2

Result:
# /usr/local/hadoop/bin/hadoop dfs -cat /user/hduser/adam-out/part-r-00000 > words-count.txt
sort -n -k 2 -t \t words-count.txt

重复次数最多的单词如下:
development 11
element 11
effect 12
left 12
That 12
amount 13
heat 13
planet 13
vast 13
went 13
bright 14
get 14
last 14
Mount 14
put 14
against 15
right 15
ancient 16
just 16
present 16
yet 16
might 19
fact 21
almost 25
part 28
point 29
What 29
cannot 33
different 39
what 62
first 65
most 66
But 67
must 67
out 80
about 83
light 98
great 114
but 131
It 161
not 200
at 226
it 385

Tags: , ,
RSS Feed