帐前卒专栏

Without software, we are nothing.

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.

Web Config Permission of Files and Dirs



permission of files: 0644 permission of dirs: 0755 if not, you will not see the web page. Or your site may have an exploit. 配置文件的权限为0644, 配置dir的权限为0755,这样即可以让用户访问到,又不会有太大的安全漏洞。

Octopress Markdown



今天又弄了一下octopress,发现octopress和markdown中间还是有些兼容问题。例如codeblock、四个空格、tab、` ` `以及*的使用。都有些bug。应该是octopress解析时候有问题。*后面紧跟的一段,如果后面紧跟代码一定是8个空格或者两个tab。偶然情况下,使用4个空格也是可以作为code的。而code一定是以没有空格开头到行结束的。即使你使用了{\% codeblock \%} 以及 {\% endcodeblock \%} 也是不会被识别的。 所以blog还是简单点好。

Simple is beauty!
by someone

Simple is beauty!

下面再使用一下pull quote 其实我真的不想再说什么了… 好吧,让这篇blog结束吧。

First Use Octopress



这是第二篇blog。第一篇貌似什么都没有写。现在在linux下过得相当到舒坦。比windows的感觉好多了。就是拼音输入法支持到不怎么样。谢谢搭建octopress的感受吧。第一感受是这东西真不好装。需要现学到知识也有很多,例如rvm, ruby, gem, bundle, rake, git, MarkDown. 再加上在windows下养成到习惯,到linux下还是要熟悉一下。首先要先安装openssl和libtool相关的包。

1
sudo apt-get install openssh-client openssl libruby1.9.1 libssl-dev libssl libtool

下面挨个介绍吧。
* rvm 是管理ruby的工具,因为octopress需要使用ruby1.9.2所以必须使用rvm,否则就自己去ruby的官网上自己下载,然后编译安装。这里使用rvm是可以管理多个ruby版本。并且可以自动编译安装ruby。安装rvm需要一行命令

bash -s stable < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer)   

敲命令时注意< <之间的空格。安装完这个,需要将rvm添加到path中。在~/.bashrc中添加PATH=$PATH:~/.rvm/bin。注意有些系统可能~/.bashprofile或者其他,详情在哪里添加请google。添加完后,关闭bash shell.再启动shell或者终端。然后下面的命令可以很好执行:

which rvm
# 看到底rvm路径对了没有
rvm install 1.9.2 && rvm use 1.9.2
# 安装ruby 1.9.2并且使用这个版本
ruby --version
# 是否是1.9.2版本

这里需要注意rvm use 1.9.2,如果你的机器重启,这里下次还要再设置一边。否则很有可能不能找到正确的ruby. * 这一步要使用到git, git是管理代码到工具。不会用的话详情见git。octopress也主要使用了git和github,否则该实现到功能都不能用了。

git clone git://github.com/imathis/octopress.git octopress
# 把octopress的主要内容down下来。   
  • 这里要使用gem, bundle, rake了。gem,bundler都是管理ruby各个小类库的工具。而rake是ruby make.
    gem install bundler
    bundle install
    rake install
    # 如果这里rake运行不成功,有可能是有多个版本到rake,要使用bundle exec rake install
    
  • 剩下的详情请查阅octopress。 如果在rake generate处因为openssl卡住,则需要安装完openssl,再安装ruby.yaml编译不成功,是因为没有安装libtool.

CSDN Hacked



CSDN lost its user-password-email information. And all has published in Internet. If you want to find whether your password is exposed. Go to this website[the link].

repeat times passwod percent
501 qwerasdf (0.0124073903469017)
504 computer (0.012481686097482)
519 zxczxczxc (0.0128531648503832)
521 dddddddd (0.0129026953507701)
525 299792458 (0.0130017563515437)
532 135792468 (0.0131751131028976)
535 20082008 (0.0132494088534779)
536 369369369 (0.0132741741036713)
553 5845211314 (0.0136951833569594)
556 yangyang (0.0137694791075396)
559 csdncsdn (0.0138437748581199)
559 google250 (0.0138437748581199)
561 woaini520 (0.0138933053585067)
562 zhang123 (0.0139180706087001)
562 1234567b (0.0139180706087001)
565 wocaonima (0.0139923663592804)
567 1233211234567 (0.0140418968596672)
567 9876543210 (0.0140418968596672)
570 qaz123456 (0.0141161926102475)
571 q123456789 (0.0141409578604409)
572 321654987 (0.0141657231106343)
578 369258147 (0.0143143146117948)
585 aaa123456 (0.0144876713631487)
589 1357924680 (0.0145867323639224)
592 123321aa (0.0146610281145026)
601 25257758 (0.0148839153662434)
608 wojiushiwo (0.0150572721175973)
616 ssssssss (0.0152553941191446)
618 qazwsx123 (0.0153049246195315)
621 123456aaa (0.0153792203701117)
623 1234567a (0.0154287508704985)
642 z123456789 (0.0158992906241735)
649 woainima (0.0160726473755274)
650 44444444 (0.0160974126257208)
651 buzhidao (0.0161221778759142)
657 ffffffff (0.0162707693770747)
669 100200300 (0.0165679523793957)
680 12345679 (0.0168403701315233)
685 12369874 (0.0169641963824904)
693 1122334455 (0.0171623183840377)
702 111111 (0.0173852056357785)
708 woaini123 (0.017533797136939)
713 qwe123456 (0.017657623387906)
726 xiaoxiao (0.0179795716404205)
727 123456654321 (0.0180043368906139)
729 woshishui (0.0180538673910007)
732 12301230 (0.018128163141581)
740 1234554321 (0.0183262851431283)
741 5201314520 (0.0183510503933217)
744 12345612 (0.018425346143902)
765 lilylily (0.0189454163979637)
770 123456asd (0.0190692426489308)
772 10101010 (0.0191187731493176)
777 1q2w3e4r5t (0.0192425994002847)
783 11235813 (0.0193911909014452)
805 12345600 (0.0199360264057004)
835 11111111111111111111 (0.0206789839115029)
847 wwwwwwww (0.0209761669138239)
852 0987654321 (0.0210999931647909)
882 5845201314 (0.0218429506705934)
882 zxcvbnm123 (0.0218429506705934)
892 kingcom5 (0.0220906031725276)
894 123456987 (0.0221401336729144)
910 05962514787 (0.0225363776760091)
920 321321321 (0.0227840301779433)
967 woaiwojia (0.0239479969370339)
975 1qazxsw2 (0.0241461189385812)
988 123qweasd (0.0244680671910956)
991 1234abcd (0.0245423629416759)
1003 woaini1314 (0.0248395459439969)
1037 12345678a (0.025681564450573)
1054 q1w2e3r4 (0.0261025737038611)
1058 asdfghjk (0.0262016347046348)
1109 1123581321 (0.027464662464499)
1111 123698745 (0.0275141929648858)
1119 asdf1234 (0.0277123149664332)
1136 521521521 (0.0281333242197213)
1148 147852369 (0.0284305072220423)
1183 123456qq (0.0292972909788118)
1200 3.1415926 (0.0297183002320999)
1206 qweqweqwe (0.0298668917332604)
1214 111222333 (0.0300650137348078)
1245 zzzzzzzz (0.0308327364908037)
1268 ms0083jxj (0.0314023372452523)
1273 11112222 (0.0315261634962193)
1285 code8925 (0.0318233464985403)
1316 qweasdzxc (0.0325910692545363)
1339 77777777 (0.0331606700089848)
1384 asd123456 (0.0342751062676886)
1480 qwer1234 (0.0366525702862566)
1589 33333333 (0.039351982557339)
1652 55555555 (0.0409121933195242)
1652 741852963 (0.0409121933195242)
1656 963852741 (0.0410112543202979)
1699 520520520 (0.0420761600786148)
1854 123456123456 (0.0459147738585944)
1859 999999999 (0.0460386001095615)
1859 123456aa (0.0460386001095615)
1891 99999999 (0.0468310881157508)
1918 asdfasdf (0.047499749870973)
1971 aa123456 (0.0488123081312241)
1986 123456789a (0.0491837868841254)
1989 qwertyui (0.0492580826347056)
2100 1234qwer (0.0520070254061749)
2106 a1234567 (0.0521556169073354)
2113 123456123 (0.0523289736586893)
2131 123456 (0.0527747481621708)
2138 a12345678 (0.0529481049135247)
2160 abc123456 (0.0534929404177799)
2166 123321123 (0.0536415319189404)
2243 22222222 (0.0555484561838334)
2296 asdasdasd (0.0568610144440845)
2348 110110110 (0.0581488074541422)
2380 12341234 (0.0589412954603315)
2396 abcd1234 (0.0593375394634262)
2515 qazwsxedc (0.0622846042364428)
2540 12121212 (0.0629037354912782)
2573 123654789 (0.0637209887476609)
2578 0123456789 (0.063844814998628)
2580 123456abc (0.0638943454990148)
2796 1q2w3e4r (0.0692436395407928)
2826 asdfghjkl (0.0699865970465953)
2885 0000000000 (0.0714477468080069)
2985 12344321 (0.0739242718273486)
3061 31415926 (0.0758064308420482)
3080 iloveyou (0.0762769705957231)
3094 qq123456 (0.076623684098431)
3143 qwertyuiop (0.0778371813579084)
3175 000000000 (0.0786296693640977)
3277 qqqqqqqq (0.0811557248838262)
3281 87654321 (0.0812547858845999)
3501 password (0.0867031409271515)
3610 789456123 (0.0894025531982339)
3649 xiazhili (0.0903683979557772)
3667 1qaz2wsx (0.0908141724592587)
4096 11223344 (0.101438464792234)
4435 a123456789 (0.109833884607803)
5025 66666666 (0.124445382221918)
5145 1111111111 (0.127417212245128)
5459 aaaaaaaa (0.135193500805861)
5553 987654321 (0.137521434324042)
5965 147258369 (0.14772471740373)
6995 111111111 (0.173232925102949)
15033 88888888 (0.372296006157632)
17790 1234567890 (0.440573800940881)
19986 123123123 (0.494958290365624)
34952 00000000 (0.865595024760297)
46053 dearbook (1.14051406715741)
76346 11111111 (1.89072779126658)
212749 12345678 (5.26878221339919)
235012 123456789 (5.82013097845522)

Velocity Encoding Charset Error



First, set some properties for velocity engine. Set vm file reading path. use file read-mode not resource read-mode.

// set velocity path, if you don’t do these, you will get Resource not found exception.
Properties p = new Properties();
p.setProperty(“resource.loader”, “file”);
p.setProperty(“class.resource.loader.class”,”org.apache.velocity.runtime.resource.loader.FileResourceLoader”);
// where is your vms path, set it
p.setProperty(“file.resource.loader.path”, realPath + “/vm”);
// set output encoding
// nearly almost articals said the following will work, but it won’t
p.setProperty(Velocity.INPUT_ENCODING, Constant.DEFAULT_ENCODING);
p.setProperty(Velocity.OUTPUT_ENCODING, Constant.DEFAULT_ENCODING);
p.setProperty(“contentType”, “text/html;charset=”+Constant.DEFAULT_ENCODING);
Velocity.init(p);

The above code should be write in beginning of use any of velocity objects. In Spring or Java web application, you should write them into Servlet context listener.
If you use ascii word. There will no error encoding. But if you use gb2312 or UTF-8. You will find something weird. The above code dose not work. So I use response output to solve those encoding problem. In web application, we always use response.getOutputStream() to write something back. But now, we should construct output stream to write correct encoding word to the page. So velocity can encoding them correctly. The following code will help you.

String encoding = “utf-8”;
// If you use UTF-8 encoding in your application
Writer writer = new PrintWriter(new PrintStream(resp.getOutputStream(), true, encoding));
// velocity will find abc.vm in your file path folder.
String pageName = “abc”;
Template template = Velocity.getTemplate(pageName);
VelocityContext context = new VelocityContext();
context.put(“test”, new String(“hello”.getBytes(encoding), encoding));
// here velocity will use the writer to write correct encoding words to response stream. So we can see the correct words showed by our page.
template.merge(context, writer);

If you use jetty to run your web application, it works fine.
But maybe you use windows resin to run war package. Sometimes, error encoding comes again. There is something wrong with your resin application. You should change config file in resin conf folder. In conf/resin.xml( resin 4.0+ ), add <character-encoding>UTF-8</character-encoding> in < web-app-default >. Like following:

< web-app-default >
<character-encoding>UTF-8</character-encoding>

< /web-app-default >
And you should use correct charset to start your resin. Else resin will use default charset of your operation system.

java -Dfile.encoding=UTF-8 -jar lib/resin.jar

Addition, if you use spring framework, don’t forget the encoding filter :

<filter>
<filter-name>characterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name> <param-value>UTF-8</param-value> </init-param>
</filter>
<filter-mapping>
<filter-name>characterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
In encoding or charset error. You should consider the following :

  • environment (like resin, jetty, eclipse and etc.)
  • Input (from outside, like user input, or reading from database )
  • Output (to outside, like page presented, or writing to database or file)
  • Process (maybe you encode words twice or more, or encode them to some other different charset)