Monday, August 17, 2009

Posterous API in Perl

Posterous.com is a new (micro)-blog mesh-up system.

You can use it mesh up almost all your (micro)-blog. Post once, Publish Everywhere. And there is still many funny features.

It looks pretty good, so I translated its API to Perl. You can get it from CPAN. Still work in progress, but would be productive soon.

 

Saturday, August 15, 2009

Can't locate Git.pm in @INC

Well, the installation of Github::Import worked well on Linux boxs but always reported "can't locate Git.pm in @INC" on Macintosh boxs. It is just a little trick and the answer is here.

Git.pm comes with git instead of being a part of CPAN. Building a copy of git-core or copying from other box solve it quickly.

 

Tuesday, July 7, 2009

the roadmap of upgrowth

和長輩們聊天總是很有趣的。即使那是一句老生常談,從長輩提攜的口吻中說出,依然受用。

6/26 的謝師宴,和賴暎杰老師坐在一起,我是這麼問的:「研究遇到瓶頸時,是怎麼面對的。」

「每天都多學會一件事,就不用擔心。」

yep...

 

Monday, July 6, 2009

Data::Model

Data::Model is a new ORM created by yappo, Its usage style is similar to DataMapper and Jifty::DBI.

Different from most famous equivalent, Data::Model handles multi-database. In order to do that, every model was appointed its database and table name in addition to its schema specification.

Let's see a simple example:



This is a simplest model in Data::Model, Only two DDL in it.

The first, base_driver( $driver ) specify which database the model would connect to. $driver is a Data::Model::Driver::DBI object. Write those diffusion code in every model is really not perlish, so we extract all possible drivers to MyApp::DB::driver().



The second, pass the table name and schema to install_model(), this step is the same as above two ORM system. and then, all thing done. By the way, columns() is the best syntax sugar provided by Data::Model::Schema.

Wait... Because Data::Model is too young to do auto_migration, we simply write MyApp::DB::make_schema() to do that. Finally, we could do simple CRUD in our application. as below.



Though Data::Model is too young to have some important feature such as validator and hook, even has no ability to handle relation between two table. The prototype is really exciting.

[Chinese Version]

 

.

Thursday, June 25, 2009

disable beep in emacs

使用 Emacs 也有一段時間,在 Mac 的 GUI 環境下使用 touch panel 撥弄 emacs 的 scroll bar,總會有令人中斷思緒的嗶嗶聲。Emacs Wiki: AlarmBell 這頁把處理警告的設定方式寫的頗為清楚。

要把警示聲換成視覺警示,可以寫成

(custom-set-variables '(visible-bell t))

在 GNU Emacs,這樣預設是閃爍第一行或最後一行,端看 touch panel 是轉哪一邊,XEmacs 則是閃爍整個螢幕,要讓 XEmacs 僅閃爍一行,則要寫成

(custom-set-variables '(visible-bell 'top-bottom))

完全關閉警告,可以設成

(custom-set-variables '(ring-bell-function 'ignore))

ring-bell-function 還可以設定成一個 lambda,指定警示聲去播放某個音效檔案。
(setq ring-bell-function (lambda ()
(call-process "audioplay" nil 0 nil
"/this/is/my/errorsound.au")))

或是送出訊息
(setq ring-bell-function (lambda ()
(message "use the message to replace beep")))


Emacs is awesome :D

 

Connect to SQLServer(MSSQL) in php5 with FreeTDS

In Debian It needs to

$ aptitude install freetds-common php5-sybase

Then add configuration about SQLServer to /etc/freetds/freetds.conf
[ConfigName]
host = host_of_sql_server
port = port_of_sql_server
tds version = correct_version
client charset = use_utf8_as_better

All thing done.

 

Monday, June 8, 2009

Pseudo-OO syntax in C

總是會忘記的 syntax



 

Tuesday, April 28, 2009

some notes

1. do find => rescue

2. model operation more than 3 lines => define class method in model

3. def current_user

4. render_as_form

5. more than one relation in one table

6. composite primary key => hook

 

Tuesday, April 7, 2009

Class::Implant - No &import() !

Class::implant is a experimental little helper implemented when I developed Railsish with gugod. Manipulating mixin and inheritance outside package is its primary function, also with abilities to select methods which would import.

Original idea is inspire by the purpose: we want to import whole Helper methods into Controller which the Helper is named after. And it is should not be left to framework users to do it by themself. In Ruby, we just need to write
XxxController.send(:include, XxxHelper)
In Perl, it can also be written as
eval qq{ package XxxController; use XxxHelper; }
But a tedious &import() should be write in XxxHelper as follow.
sub import {
for (qw(hello world foo bar method...)) {
*{blah::$_} = \&$_
}
}
and edit the export methods list by hand.

Even use Exporter and edit @EXPORT and export by symbol :all, users still need to do follow by hand
use base Exporter;
our @EXPORT = qw(..);
Class::Implant provide simplified equivalent.

package main;
use Class::Implant;
implant "XxxHelper", { into => "XxxController" };

Everything done! All methods in XxxHelper is imported into XxxController!

If call use Class::Implant in other package, default import target would become it. That means, above code is the same as follow:

package XxxController;
use Class::Implant;
implant "XxxHelper";

In the release 0.02_01, two other options work. { inherit => 1 } make imported packages appear in @ISA of import target. { match => pattern } filter, and import methods conform to pattern.

For example,

package main;
use Class::Implant;
implant qw(Foo Bar), { into => "Cat", match => qr{h\w+} };

means import methods whose name start with h in Foo and Bar into Cat.

I also write UNIVERSAL::Implant. As its name, require once, and write as follow everywhere.

Cat->implant qw(Foo Bar), { match => qr{h\w+} }

Do the same thing as previous example. That means, caller package Cat assign { into => "Cat" }.



Chinese Version is @ Chupei.pm.org

 

debian manpage-zh

上次寫 C 的時候對 Debian 還沒有很熟,今天偶然查 manpages 時才注意到有中文的 standard C library manpages。真相如下:



希望我沒有太後知後覺...XD