帐前卒专栏

Without software, we are nothing.

Build Website in Ubuntu



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

Machine Learning



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

Jstack Jmap Resin



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.

Git Alias



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

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

以后就可以使用别名了。

孔府,孔庙,孔林



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

Octopress Deploy



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的内部实现比较好。

Octopress Bugs



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.

Back Home



今天终于到家了。卧了一夜到火车。在六点多睡势良好的情况下被列车猿唤醒换票。另外卧铺车厢开灯太早了,并且关灯太晚了。
回到家中吃吃喝喝,洗澡理发,不知不觉就到中午了。下午实在困,睡了一下午。晚上的时候家人一起玩玩UNO.感觉很好。教会了爸妈。UNO还是适合各种人群的。
公司发的扑克牌,貌似只对懂外语的年轻人有效。对爸妈一点杀伤力都没有。下午还看了一下holmes.剧情还不错,根据现代场景改变的历史剧还是很有看头。
晚上再研究一下wordpress导入。自己改的脚本还是多多少少有些问题。导致解析不成功。

新浪Oauth



新浪Oauth好像是上Oauth2.0了。不过也支持OAuth 1.0a.但是新浪的OAuth 1.0a是冒牌的。也就是说,应该是1.0~1.0a或者是真正到1.0 alpha. 因为这个Oauth不支持oauth_callback_confirm参数,也就是在request_token之后就仅仅返回oauth_token和oauth_secret.因为没有这个oauth_call_confirm, 也就无法区分Oauth到底是1.0的还是1.0a的。另外如果你真的照着OAuth1.0a的流程与新浪的接口整合。就会发现在获取authorized_token,还是要传给新浪 oauth_callback,否则新浪真的不知道callback到哪里去,于是新浪就展示给你获取oauth_verifier到页面,也就是授权码页面。

另外如果你真的加了oauth_callback,加入你的callback中没有参数,那谢天谢地,你的程序可以跑得很好。如果你的callback中有一个参数,那也谢天谢地, 你的程序可以跑得良好。如果你的callback中有更多到参数,那就别想跑得好了。因为新浪在某些情况下会丢参数。即使你将oauth_callback中的值整个用urlEncode编码一下(再使用替换个别字符转为Oauth特殊编码),也是有可能给你丢参数的。
所以请记住:国内就真的没有什么Oauth1.0a. 另外传说腾讯Oauth的oauth_callback的特殊值不是oob, 而是null.
所以最简单有效到方法是将oauth_callback值中的’&’替换为’||’,将’=’替换为’|’.然后在callback之后的页面进行反编码。就可以得到自己想要到参数了。 新浪是从Oauth1.0进行改版到Oauth1.0a的。其实就仅仅做了oauth_verifier的生成。然后就真的啥事请都没有做。

Temp File, Just Test



This blog is just for octopress test. Not use rake new_post, just vi source/_post/2012-01-16-test.markdown. I want to see whether it works.
En, it works.