May 2009 Archives

Mocking

| 1 Comment | No TrackBacks

Rspec provide this super sweet syntax sugar to write mocked methods of any given object:

player.should_receive( :run ).and_return( 42 )

Ref: http://rspec.info/documentation/mocks/message_expectations.html

I’m pondering if this could be ported to Perl.

一切都離不開行銷

| No Comments | No TrackBacks

最近一直把 Free Prize Inside 這本書帶著,有時間就翻閱。這本書的內容大意是在說,花長時間研發、以硬底技術為後盾為基礎的這種商品,已經不適用現在這樣的時代;相對的,具有軟性創意 (Soft Innovation) 的產品的商機則大大提高。所謂軟性創意,特別指的是那些無需任何技術就可以實現出來的點子。像是,個人認為在台灣最常見的實例:請西施賣檳榔。

而最近發生的事情也讓我確實的感受到軟性創意的發生。

唯獨尾巴過不得

| 2 Comments | No TrackBacks
水牯牛過窗欞,頭角四蹄全通過,唯獨尾巴過不得

過了這許多年,終於領悟到這個禪宗故事,其實不是在講量子物理,也不是在講其實是有人故意把牛尾巴拉過窗欞,而是在講外包軟體專案結案前的狀態。

這真的是件不講不明白的事呢。

Perl really shouldn't be spell as PERL

Cucumber , the BDD tool, is something that is really brilliant. I wrote Ruby code for my work too and I tried to used this tool with watir. Again, Brilliant.

幸福快樂的程師設計師...嗎?

| No Comments | No TrackBacks

這兩天老是看見人 bookmark 這篇文章: The Programming Language with the Happiest Users

About testing HTTP::Engine-based app.

| No Comments | No TrackBacks

So a few days ago I wrote a page on wikibook about HTTP::Engine , telling people why having a abstraction layer is a good thing. These days I'm in a superposition states of thoughts.

I just released Test::Continuous 0.66 a few hours ago that supports TAP::Harness::Remote

Use the installed autoprove program to do so:

autoprove --harness TAP::Harness::Remote t/*.t

This requires you to have an already working ~/.remote_test configuration. Mine is something like (in YAML format):

---
ssh: /usr/bin/ssh
local:
  - /Users/gugod/git/Net-Redmine
  - /Users/gugod/git/Test-Continuous
  - /Users/gugod/git/Acme-Boolean
  - /Users/gugod/git/Railsish
  - /Users/gugod/git/Binding
user: gugod
host: example.com
root: /home/gugod/tmp/local/root
perl: /usr/bin/perl -Ilib -Iinc
master: 1
ssh_args:
  - -x
rsync_args:
  - -C
  - --exclude
  - 'blib|.git'
env:
  NET_REDMINE_TEST: 'http://localhost:30000/projects/test admin admin'

If prove --harness TAP::Harness::Remote t/*.t works for you, then you should be good switching to autoprove. If not, feel free contact me with the problem you met.

This is very helpful when I'm testing Net::Redmine , since I also need to start up a redmine server to test with, running tests on a remote, powerful server is generally faster.

More HTTP::Engine documents

| No Comments | No TrackBacks
I just happened to find a Perl Programming book on wikibooks.org, too bad that it does not have rich content on it. So I wrote a page about HTTP::Engine:

http://en.wikibooks.org/wiki/Perl_Programming/HTTP::Engine

It feels good if the content of that book can contains at least the introductory level of web frameworks in Perl, but there are just too many of them.

Also I would think it makes even more sense to write Modern Perl Programming instead of just plain old Perl Programming. Reason ? instead of always just telling people TIMTOWTDI, we can simply show that it's easy to write an modern-style of code for then language of Perl5, was first born (released) in 1994.

Quote from the perlhist perldoc:

Perl 5 introduced everything else, including the ability to introduce everything else.
Maybe it's time to seal the world TIMTOWTDI for a while and rebase our mind into a different level. There are way more powerful competitors in the jungle, and we are no longer in a good position as we used to be. It's a problem, how do we deal with it ?

perl5i ☞ perl5g

| No Comments | No TrackBacks

schwern has this perl5i module that aims to fix as much of Perl 5 as possible in one go. I read it and liked the approach, so I wrote a small program named perl5g that basically does the same thing, but you can put it in your shbang.

You can find it in my just created bin.git, which is really just about 5% of my ~/bin folder at this moment.

So here’s an example program written in perl5g:

#!/usr/bin/env perl5g
for my $module (@ARGV) {
    try {
        load $module;
        say "$module => @{[$module->VERSION]}";
    } catch($error) {
        say "Failed to load $module: $error";
    }
}

It runs like this:

> module-version IO::All CPAN
IO::All => 0.39
CPAN => 1.9304

Since it’s now possible to modify perl5 language with Devel::Declare and the related B::* families, it’s actually possible to make Perl5 a little perl6ish-perfect. You can easily craft your own perl5 interpreter like what I did. Checkout the source code, it’s actually simple.

In reply to my own article: jquery way to limit image size.

It's actually very easy to known the size of an image using Javascript. Here's the code:

var i = new Image();
i.src = "http://www.google.com.tw/intl/en_com/images/logo_plain.png";

alert(i.width + " x " + i.height);

The Image object has be used to pre-load big images. If the image is known to be pretty big and it takes sometimes to load, you might want to examine its size only after it's loaded:

var i = new Image();
i.onload = function() {
    alert(i.width + " x " + i.height);
};
i.src = "http://www.google.com.tw/intl/en_com/images/logo_plain.png";

Notice that you'll have to set the onload function before you set src. Otherwise, when the browser has cached the image locally, the "load" event might be triggered instantly, even before the onload handler is set.

One nice thing it's that this can work with images from different domains. Just like you can put images from different domains into your page with img tags.

Writing Moose code with yasnippet

| No Comments | No TrackBacks

yasnippet is awesome Emacs mode that helps reducing the number of keystrokes. I personally can't code without it now, and I recommend everyone using Emacs give it a try.

As I started to wrote Net::Redmine with Moose (or really Any::Moose), I decided to extend my snippets to fit Moose's verbs. Here's what I have so far: http://gist.github.com/106480

I did this video that demonstrates how it feels. Noticed that yasnippet is able to mirror the attribute name and its associated builder function on the fly. Very neat feature.

總之先來個有圖有真相:

twirc screenshot.png

Twirc 是個有點另類的 Twitter client。它會跑起一支 IRC Server,讓你可以用任何 IRC Client 連進去,加入其中一個設定好的頻道。在此頻道所發的訊息,則會被轉送到 Twitter 上,在 Twitter 上的好有所發的訊息,也會被轉送到此。

所以其實並不只是能用 irssi 上 Twitter,任何 IRC Client 都可以透過此方法來看 Twitter 訊息。

Using git-sd for rt.cpan.org

| No Comments | No TrackBacks

In the SD master branch, there’s a program ‘git-sd’ that can be used with git command. Here’s how I setup with my Test::Continuous

The variable is ours.

| No Comments | No TrackBacks

As I was writing the controller class of Railsish , I was facing a rather interesting problem: what’s a good way to pass variables into the template ?

If you know Rails, the one that I’m trying to cloning, or clone-ish-ing, the view code or sort of like an instance method of its corresponding class. All the instance variables that gets initialized in the controller are automatically viewable in the view code. This is super neat. Because then you don’t really have to aggregate those into a hash, and them pass it to render.

Since there is no such obvious thing in Perl that’s known as `instance variables'', I have to make something up. At least, something that's sweet enough, that I don't have to pass any variables to therender` function.