Wednesday, December 30, 2009

Assign initial value to a pointer

Today I suddenly got an idea. Most of time when we use pointer, we create a variable, and assign initial value to it, and then take its address become the value of a new pointer for succeeding use. But we create a redundant identifier here.

In fact, we could always create a fundamental type pointer and assign initial value to it through dereference operator like this snippet.

and no redundant variable here.

But when we define a simple struct like this.

We should assign initial value through arrow operator like third and fourth line in below snippet. Using brace to assign value as the same as first snippet is wrong syntax.

With a complex struct definition, this way increases many redundant code. Using brace to assignment initial value without creating redundant identifier could be done like this.

But I consider writing (*aPtr) = { 1, 2 }; may be the most intuitive way and it doesn't conflict with other syntax in C.


Friday, November 13, 2009

Library for Numerical Computing

Briefly summarize some numerical library here. It looks there are too many useful tools. Either for parallel computing or for matrix, numerical calculating and plotting.


MatPlotLib: it seems to be the most awesome plotting tool among this list

PGPlot: C library, also have binding in Perl, Python,Ruby

PLPlot: cross-platform plot library, also have binding in Perl

Scientific Python



MPI Ruby: MPI Ruby binding

PyMPI: MPI integrated Python interpreter

MPI for Python Python MPI binding

Simple Remote Python : SrPy

Parallel Python


Perl Data Language: difficult to be categorized. Including calculating, plotting together. include FFTW, PGPlot, PLPlot, and many data processing tool such as HDF. Awesome Environment!

MPMath: Multi-Precision math functions collection.



LibFFTW, also have binding in Perl, Ruby

Ruby DCL




GNU Scientific Library: C library, also have bindings in Ruby named Ruby/GSL and Ruby-GSL. and Python

RSRuby: bridge between Ruby and R


Ruby for Science


Sunday, August 30, 2009

Discussion about anonymous function in Perl and Ruby

Just for fun, tonight I write a methods invoking two anonymous functions to iterate a Range with specified condition in Ruby. It looks like
class Range
def each_satisfy()
And I want to invoke it as

(1..10).each_satisfy(condition_lambda, callback_lambda)

(1..10).each_satsify { |n| ...condition statment... } do |n|
...callback statement...
When I try to define its prototype as
def each_satisfy(&condition, &callback)
Ruby Interpreter broke with syntax error. So that, finally I write it as

def each_satisfy(condition, &callback)
self.each do |n|
yield n if n
and it should be used as

(1..10).each_satsify lambda { |n| ...condition statment... } do |n|
...callback statement...

It reminded me that Perl also has the same problem. Even when we declare

sub each_satisfy(&&) {


Still only first sub keyword could be omitted. That means we should invoke it as

each_satisfy { ... condition ... } sub {
my ($iter) = @_;
... callback ...

The only difference is Perl omitted the first (sub) and Ruby omitted the last (lambda).

I do want to figure out WHY they could not be designed to accept arbitrary quantity of anonymous functions.


Sunday, August 23, 2009

LWP, cURL, OpenSSL and Posterous

The fun of programming is there is always subtle mechanism in implementation. It costs time to discover but sometime is deserving. for example.

$ curl --basic -u <user>

$ echo -n "user:pass" | openssl base64 -e




Monday, August 17, 2009

Posterous API in Perl 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 in @INC

Well, the installation of Github::Import worked well on Linux boxs but always reported "can't locate in @INC" on Macintosh boxs. It is just a little trick and the answer is here. 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 的謝師宴,和賴暎杰老師坐在一起,我是這麼問的:「研究遇到瓶頸時,是怎麼面對的。」




Monday, July 6, 2009


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

(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
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 @


debian manpage-zh

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



Wednesday, March 25, 2009

Rails on FreeBSD 7.1

Today I was first time trying to install rails on freebsd 7.1. Neither the ports version nor the gem file version, rails could not work, even only simply creating a new project. It returns message as following.

undefined method `camelize' for "app":String

I had try to reinstall ruby, rubygem, and try other version rails but a nonsense. And finally I forgot how did I discover it needs ruby-iconv ports in fact. It seems occurring at the time I was using rails 2.2.2, some keyword appeared in the error message.

One post on the mailing list [Ruby on Rails : Talk] show the same problem. If you also have the same problem, try it.


Saturday, March 14, 2009

REPL in Perl

Read-Evaluate-Print Loop 在現代語言中非常常見,諸如 Scheme, Haskell, Ruby, 與 Python 都有內建,實際工作時是非常實用的工具,Perl 6 也即將內建 REPL Shell,Perl 5 則沒有。

這幾天偶然想在 Perl 中使用 REPL,搜尋了一下,在 得到 2007 年發表的這篇文章,介紹了四個以 Perl 5 實做的 REPL Shell,翻譯如下。

Continue reading REPL in Perl.


Monday, March 2, 2009

two pragmatic commands

$ cp /some/path/to/myfile{,.back} # cp-the-file

$ mv filename.{old,new} # quickly-rename-a-file


Friday, January 16, 2009

day spec

#!/usr/bin/env perl

use warnings;
use strict;

$csg = CSG->new;

date => "2009/01/16",
location => "Lib, 5F, Column Q30",
prepare => ["9:40~11:50", "13:30~14:00"],
end => "17:10",



Thursday, January 8, 2009


hmmm 只能說很中肯 XDDD












Saturday, January 3, 2009

GitHub Creator

# cpan Git::Github::Creator

Setting in ~/.github_creator.ini
Then, in local git repository
github_creator --name my-project --desc "an awesome thing"

Arguments are optional in a Perl module with META.yml.

GitHub Creator's repository and manual on cpan