帐前卒专栏

code, software architect, articles and novels.
代码,软件架构,博客和小说

Today, I met the following problem. I wrote an article, and use rake generate to generate the site. Then the console reports:

/home/chico/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych.rb:148:in `parse’: couldn’t parse YAML at line 3 column 17 (Psych::SyntaxError)

why?
Then I found the reason:

“\” should not be written in title of your article. If you really want to write it, use “\\”

今天解决了linux 环境中编译c++或者c文件时产生的错误。

1
2
程序中有游离的"\xxx"
忽略空字符

以上两个错误,产生的原因和字符编码有关系。一般是文件从windows转移到linux下,然后使用c或者cc或者g++编译。产生了一系列的报警和错误信息。
解决方法如下:

1
2
3
4
1. 使用vi打开报错的文件
2. 查看其文件编码. 也就是用vi 查看encoding变量。":set fileencoding?"
3. 如果编码不是utf-8则转换为utf-8. 使用":set fileencoding=utf-8"
4. 保存文件

当然产生这种错误的原因还有可能是由于在代码里输入了全角字符引起的。如果上面的方法不对,还需要再进一步排查cat -A filename

简单来说

python range会生成一个list对象,然后返回list中的内容,而xrange不会生成list对象。所以xrange相对与range来说更省空间,并且速度较快。

在英文中的官方解释是:

1
2
3
4
5
6
7
class xrange(object)
| xrange([start,] stop[, step]) -> xrange object
|
| Like range(), but instead of returning a list, returns an object that
| generates the numbers in the range on demand. For looping, this is
| slightly faster than range() and more memory efficient.

ok. Do you understand?

This article will tell you how to build a website in ubuntu system. First you should install apache and php. These two tools can help you to build a small website, like “hello world” websit:D

// run the following commands
sudo apt-get install apache2 php5 libapache2-mod-php5
/etc/init.d/apache2 restart

important path

Then you should remember the following paths:

  • /etc/init.d/apache2
  • /var/www
  • /etc/apache2/apache2.conf
  • /etc/apache2/conf.d
  • /etc/apache2/sites-enabled

Apache’s default document root is /var/www on Ubuntu, and the configuration file is /etc/apache2/apache2.conf. Additional configurations are stored in subdirectories of the /etc/apache2 directory such as /etc/apache2/mods-enabled (for Apache modules), /etc/apache2/sites-enabled (for virtual hosts), and /etc/apache2/conf.d

Test your php

1
vi /var/www/hello.php
1
2
3
<?php
phpinfo();
?>

Then call this file in browser (http://localhost/hello.php)
DONE:D

概率,贝叶斯,熵,条件熵。互信息I(X,Y)=H(Y)-H(Y|X),两个变量之间的依赖度。
今天接触了一个新的概念:学习的本质是压缩。化为经典就是大道至简

Today, I use jstack, jmap, and resin to look up why my server is deading in stress test. And I also find printing information into log is useful. You can print log in entrance of function and exit of function.
jstack is a tool which is looked up stack of system, specailly in threads. It is mainly for looking up dead lock and some functions which are executed too slowly.
jmap is a tool which is looked up current memory of system or some memery jvm can not delete immediately.
You can use jstack like this:

1
jstack -l [pid]

If you know pid of the process, you can see what’s the situation of stacks in process. If you want to see the detail, looking at those stacks.
jmap is used like this:

1
jmap -heap [pid]

Today, Big niu Qiao tells me about JVM GC policy.
There are New Generation, Old Generate and Perm Generation in JVM. You can find them in jmap command. And New Generation are new objects. And Old Generation are old objects which are still be refered. Eden Space stores new generate objects. And From Space stores still alive objects after gc once. To space stores objects which are not refered and in From space before gc once. If an objects is in From Space many times, it will be moved to Old Generation by JVM. Perm Generation are static objects and Classes.
By the way, if your application runs in resin, you should look up those logs of resin, for example, jvm-default.log. The log file contains GC log information. If GC throws overMemory exception, you should modify your configuration of resin (resin.xml in resin4.0+). Modify or add:

1
<jvm-arg>-Xmx1024</jvm-arg>

This means set JVM heap space to 1G.

Read more »

今天唐大牛教了些git的命令。顺便把他的git别名也发给我了。啥叫别名,就是

1
git br  ==>  git branch

只需要在home目录下的.gitconfig文件中添加:

1
2
3
4
5
6
7
8
9
[alias]
st = status -s
ci = commit
l = log --oneline --decorate -13
ll = log --oneline --decorate
co = checkout
br = branch
rb = rebase
dci = dcommit

以后就可以使用别名了。

Read more »

今天跟姐和姐夫逛了下曲阜。三孔很小的时候去过,现在基本什么记忆都没有了。当年好像破破烂烂。现在好像好一点了。很多翻修的痕迹,如果过去不砸,也就不用修了。跟着导游看了看,貌似只有题字有看的必要。翻修的有些差,就如同翻修的长城。
在孔林里听说只要姓孔就可以埋到孔林里。孔老师看来很有希望…

octopress这东西还是很难弄的。这几天发生了各种git的异常。也不知道是怎么发生的。亦难解决。这stack overflow中查到都是中看不中用的东西。最后只好从github上再次clone下来。然后git init.这里要注意的是,octopress的home目录中其实是ignore _deploy 文件夹的。home 对应的是自己的source分支。而_deploy中才是master分支。
rake deploy 其实是调用的rake push。其实是将_public中的内容copy到_deploy中。然后

1
2
3
4
5
6
cd _deploy
git init
git add .
git add -u
git commit -m "some time"
git push -u origin master

所以还是多看看octopress的内部实现比较好。

Today, I have met a bug of octopress. When you write your blog with number in categories, like “cattegories: [some keyword, 2012]”.

When you type rake generate. The command will report:

/plugins/category_generator.rb:109:in block in write_category_indexes;: undefined method gsub; for 2012:Fixnum (NoMethodError)

It is caused by your number 2012.

1
vi plugins/category_generator.rb

Go to line 109. and add a line code:

1
category = category.to_s

Now, type rake generate again. It will be fine.

0%