« August 2006 | Main | May 2007 »

April 2007 Archives

April 4, 2007

I'm back to Movable Type!

Once, I was a user of Movable Type, installed it into my own server, and used to blog with it. It's been a few years since I replaced my blog system, Movable Type, with Hatena::Diary. In addition, I've used Typepad and Vox, both of them are products of Six Apart, to practice English writings.

I like all those blogging tools, but there're some problems with them:

  • Hatena::Diary isn't suitable for blogging in English
  • Typepad and Vox are less customizable

So, to motivate myself, I launched new domain, blog.kentarok.org, and installed MT. Today, I spent much time to select a theme, adjust the design, introduce some plugins, and move the entries on an old blog to new one. Everything is ready.

Some technical notes:

April 5, 2007

Twitter API client written in Perl

Recently, Twitter has seemed to be in fashion among sensitive people all around the world. I'd like to catch up with the movement to avoid to be regarded as the wack.

For a starter, I've written command line client for Twitter. Probably, it's so-called reinvention of wheels, but not matter, because it's just a practice.

Its usage is:

$ perl twitter.pl <option> [status]

If it executed like below:

$ perl twitter.pl update 'blogging about a Twitter client which I wrote'

The client accessses Twitter and set current status "blogging about a Twitter client which I wrote".

For more options, execute the script without arguments.

$ perl twitter.pl
Usage:
      $ perl twitter.pl <option> [argument]

Options:
    update <status>
        Set your current status.

    friends
        Show most recent status of those who you marked as friends.

    friends_timeline
        Show the timeline of those who you marked as friends.

    public_timeline
        Show the public timeline.

    followers
        Show the timeline of those who follow your status.

Stupidly, the script now doesn't treat multibyte strings correctly. Well, anyway, it's alright, just a practice ;)

Here's the source code of twitter.pl:

#!/usr/bin/perl

use strict;
use warnings;

use YAML;
use Switch;
use Pod::Usage;
use Net::Twitter;
use File::Spec;
use File::HomeDir;
use Term::Prompt;

@ARGV or pod2usage(1);

my $config    =  prepare_config();
my $twitter   =  Net::Twitter->new(
    username  => $config->{username},
    password  => $config->{password},
);
my ($command) =  grep { $ARGV[0] eq $_ }
    qw(update friends friends_timeline public_timeline followers) or pod2usage(1);

$command eq 'update' && !$ARGV[1] && pod2usage(1);

if (my $res = $command eq 'update' ? $twitter->can($command)->($twitter, $ARGV[1])
                                   : $twitter->can($command)->($twitter)) {
    switch ($command) {
        case qr/timeline$/ {
            for (@{$res}) {
                printf "%s: %s\n", $_->{user}{name}, $_->{text};
            }
        }
        case 'update' {
            printf "Set status: %s\n", $ARGV[1];
        }
        else {
            for (@{$res}) {
                printf "%s: %s\n", $_->{name}, $_->{status}{text};
            }
        }
    }
}
else {
    die "Failed to request: $command"
}

sub prepare_config {
    my $path   = File::Spec->catfile(File::HomeDir->my_home, ".twitter");
    my $config = eval { YAML::LoadFile($path) } || {};

    my $save;
    while (!$config->{username} || !$config->{password}) {
        $config->{username} = prompt('x', 'username: ', '', '');
        $config->{password} = prompt('p', 'password: ', '', '');
        $save++;
    }

    YAML::DumpFile($path, $config) if $save;
    chmod 0600, $path;

    return $config;
}

__END__

=head1 NAME

twitter.pl

=head1 VERSION

This is version 0.01

=head1 SYNOPSIS

  $ perl twitter.pl <option> [argument]

=head1 OPTIONS

=over 4

=item update <status>

Set your current status.

=item friends

Show most recent status of those who you marked as friends.

=item friends_timeline

Show the timeline of those who you marked as friends.

=item public_timeline

Show the public timeline.

=item followers

Show the timeline of those who follow your status.

=back

=head1 AUTHOR

Copyright (c) 2007, Kentaro Kuribayashi

April 6, 2007

Google launched MyMaps

Google launched a new feature, MyMaps, which allows users to create their own maps directly onto Google's space. Creating user's maps and annotating maps aren't new at all. But it's really easy to create, and we can share the maps easily with others. Wow! I like it.

Anyway, I went straight to do it, see:

Eating houses which offer really tasty foods and I've been there ever

Easy! Fascinating! I'll go for it more.

Shrugging off My Life

Kazuya Fukuda (福田和也 - Wikipedia) is a representative critic of literature in Japan who I respect. I've read his new book, "俺はあやまらない", and I'm induced to rethink the fascination of literature, art, and critic itself. I spent much time to play with computer for recent years, but the things I truely work on are sort of such cultures, I think.

Surely I like computer-related things, but sad to say, it seems that I haven't been gifted about that things at all. I decided to shrug off my life, indulging in reading books, watching movies, and listening to music. It must be good bet.

April 7, 2007

Acme::MorningMusume version 0.09

New version of Acme::MorningMusume is going to CPAN now, which is updated along with joining 李純 (Li Chun) and 銭琳 (Qian Lin) to Morning Musume as foreign students on March 15 this year.

Honestly saying, now that I'm hardly interested in モーニング娘。 (Morning Musume) at all, I don't have a motivation to update the module to keep up with changes about them. Instead, I've supported ℃-ute (C-ute) and Berryz工房 (Berryz Kobo) recent years. They're great, fantastic, and very cute! I think I might have to make modules about ℃-ute and Berryz工房 instead of モーニング娘。

Here's an example to get and save images of each members of モーニング娘。 from Google search reaults using Acme::MorningMusume.

#!/usr/bin/perl

use strict;
use warnings;
use Acme::MorningMusume;

my $morning_musume = Acme::MorningMusume->new;

for my $musume ($morning_musume->members) {
    my $image = $musume->images(limit => 1)->next;
    $image->save_content(base => sprintf "%s_%s", $musume->family_name_en, $musume->first_name_en);
    printf "Saved image: %s\n", $musume->name_en;
}

Mushup of Twitter + Google MyMaps

Dear lazyweb,

Now that we can easily create our own maps using MyMaps that Google unveiled the other day, I'd like to mashup it with Twitter just like twittervision. I hope that it would be able to assign not only my status but also friends' one on MyMaps.

Well, now, I've senced that Plagger is exactly adequate to do it, that is, "それPla".

  1. Fetch friends' timeline from feed like http://twitter.com/statuses/friends_timeline/674383.rss, which contains my own status and friends' one
  2. Filter to extract locations from status strings written according to the syntax described at "twittermap faq"
  3. Publish those information onto Google MyMaps

Unfortunately, I don't have enough motivation to implement it, so just hope anyone does it ;)

Twitter via IRC using BitlBee

Twitter is surely fun and addictive. But, how can I more easily post my status to it is the problem which hasn't been solved yet, I think. I tried it with Perl script I wrote and blogged before a few days, but I'm not satisfied with it at all, because I hoped that I could post my status from IRC client which I'm often in front of.

In such a occasion, typester gave me a really simple and effective solution on it. "Use BitlBee", he said. Great! typester++

BitlBee is a gateway which ties IRC to other IM networks, MSN, Yahoo, Jabber, AOL, and ICQ. I connect my IRC client to Jabber network using BitlBee, now can post my status to Twitter via IRC and look at friends' status. Really convenient!

Here's the procedure I did to introduce BitlBee. I'll be glad if it would be helpful for you.

Conditions:

  • OS: debian GNU/Linux
  • IM: Jabber

Please read it keeping the conditions above in your mind.

  1. Registered my Jabber account to Twitter and verify it according to its instructions.
  2. Installed BitlBee:

    sudo apt-get install bitlbee

  3. Port 6667 (or 6668. Default is 6667) was automatically set for BitlBee through the install process. For more details, see:

    $PAGER /usr/share/doc/bitlbee/README.Debian

  4. Then, Bitlbee listens at the port number described above and will be fired up via inetd, so I can connect it with IRC client which I like.

  5. Set charset, for example:

    set charset iso-2022-jp

  6. Registered my Jabber account to BitlBee server, sending the message below via IRC client:

    account add jabber example@jabber.org password

  7. Activated the account:

    account on

  8. If success, BitlBee logs in Jabber network and twitter joins a channel owned by BitlBee and me.

  9. Started private talk with twitter. To post status, just send a message via IRC client. And friends status are automatically flow down on the channel. Great!

    Twitter via IRC

You might want to consult also PrincessLeia.com - Bitlbee Quickstart Guide (Online Edition) & Notes.

April 8, 2007

Follow up: How to do with Twitter via IRC

This post is a follow up for my previous entry: Twitter via IRC using BitlBee

Using BitlBee is good way to tie IRC with IM networks, but it requires some steps of procedures to work well. That's a bother.

Good news for windows users! mayuki solved the problem with an elegant way. He implemented IRC server which works as a gateway to Twitter.

3 steps to introduce TwitterIrcGateway:

  1. Download it
  2. Run it
  3. Connect your IRC client to it

Really easy! For more, see the instruction written by the author himself: subtech - MisuzillaSubtechImpl - TwitterIrcGateway

April 9, 2007

On Voting

Honestly and personally saying, I wonder why such so many people think that they ought to go voting someone and actually do it. Have they been forced to think so? Who's been doing it?

Political participating is never limited only to voting. In short, to live, precisely speaking, to live well itself is exactly political. In this point, I can't say that I don't have any sympathy for Koichi Toyama at all.

Well, just a murmur.

April 10, 2007

Post Skype's Mood Text to Twitter

I wrote a WSH script, skype2twitter.js, which allows you to post your mood text set on Skype client to Twitter. After setting your username and password of Twiter, just run it. Then, the script checks your mood text, and posts it to Twitter if changed.

Be sure that now it just only posts the mood text to twitter, that is, it doesn't synchronize the mood text and the status on Twitter, which can be updated from Web, IM or the other various places. I expect someone to enhance it to enable to do it.

To tell the truth, what I did with the script is just to mix this script and another one. Thank to them!

skype2twitter.js

// configurations
var username = 'username';
var password = 'password';
var interval = 60000;

var status;
var skype = newComObject("Skype4Com.Skype");
var ua    = createUserAgent();

while (true) {
    if (status == skype.CurrentUserProfile.MoodText) continue;

    status = skype.CurrentUserProfile.MoodText
    postStatus(ua, username, password, status);
    WScript.Sleep(interval);
}

function postStatus (ua, username, password, status) {
    try {
        ua.open(
            'POST',
            'http://twitter.com/statuses/update.json',
            false,
            username,
            password
        );
        ua.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        ua.setRequestHeader('X-Twitter-Client', 'Skype2Twitter');
        ua.setRequestHeader('X-Twitter-Client-Version', '0.01');
        ua.setRequestHeader('X-Twitter-Client-URL',  'http://blog.kentarok.org/2007/04/10/skype2twitter.xml');
        ua.send('status=' + encodeURIComponent(status));

        if(ua.status == 200) {
            print('Updated: ' + status);
        }
        else {
            print('Error: ' + ua.status + ' - ' + ua.statusText);
        }
    }
    catch (e) {
        print (e.message);
    }
}

function createUserAgent () {
    try{
        return new ActiveXObject('Msxml2.XMLHTTP');
    }
    catch (e) {
        try{
            return new ActiveXObject('Microsoft.XMLHTTP');
        }
        catch(e){
            return null;
        }
    }
}

function newComObject (lib) {
    var obj;

    try {
        obj = WScript.CreateObject(lib);
    }
    catch(e){
        obj = new ActiveXObject(lib);
    }

    return obj;
}

function print (string) {
    WScript.Echo(string);
}

April 11, 2007

About a Girl (, Wearing Glasses)

I absolutely hate those who attach their fingers to glasses when they're taken photographies. Wearing glasses, especially for girls, has been revaluated recent years, so we often get an oppotunity of looking at such photos. Whenever I encounter such photos, I'm forced to feel annoyed their befavior, sucking arround for the fashion.

I absolutely love girls who're wearing glasses, especially celluloid-rimmed one, but think they should wear glasses in a dignified manner without attaching their fingers to it.

MT Plugin to Attach Bookmark Counts on Delicious

To attach counts which indicate how many people bookmarked my entries to del.icio.us, I wrote a tiny plugin script pasted below. I'm sure that anyone must have written a script like it yet, but it's probably much faster to write it for myself than to google for it.

delicious-count.pl

use strict;
use Digest::MD5 ();
use MT::Template::Context;

MT::Template::Context->add_tag(DeliciousCount => sub {
    my $ctx  = shift;
    my $link = $ctx->stash('entry') ? $ctx->stash('entry')->permalink
                                : $ctx->stash('blog')->site_url;
    my $digested = Digest::MD5::md5_hex($link);

    return qq{<a href="http://del.icio.us/url/$digested"><img src="http://del.icio.us/feeds/img/savedcount/$digested?aggregate"></a>};
});

1;

April 15, 2007

Twittering via E-mail

There must be many people who'd like to post their status to Twitter from cell-phones. In my case, Twitter hasn't supported the cell-phones provided by Japanese careers yet, or to be exact, Japanese cell-phones don't support International SMS, so I've been forced inconvenience on not to be able to do it. However, it's nonsence that I only wait for them to concider my circumstance. I have to help me for myself.

Today, I found DreamHost, which hosts this blog and other websites of mine, supported piping E-mails into other programs. Great! I went straight to write a tiny script, mail2twitter.rb, which allows me to post my status via e-mail. Then I created a new user to accept the e-mails. Finally, created a file named .forward.postfix right under the user's home directory like this:

"| /home/username/path/to/mail2twitter.rb"

That's all. For more, consult DreamHost Wiki to know how to configure your environment. And I drew upon a script written by ma.la to write this script. Thanks!

Note:

  • Don't forget to give the script an executable privilege(e.g. chmod +x mail2twitter.rb).
  • Hide the address to accept e-mails from anyone. mail2twitter.rb checks who sends an e-mail by From field of it, but, you know, it's inadequate to save your status from malicious people.
  • This way explained here is basically applicable to other environments which support e-mail piping.

mail2twitter.rb

#!/usr/bin/ruby

require 'uri'
require 'kconv'
require 'mailread'
require 'net/http'

username  = 'username'
password  = 'password'
addresses = ['foo@exapmle.com', 'bar@example.com']

mail      = Mail.new($stdin)
exit unless addresses.find{|address| mail['From'].index address}

status    = URI.escape(Kconv::kconv(mail['Subject'], Kconv::UTF8, Kconv::AUTO))
req       = Net::HTTP::Post.new('/statuses/update.json')
req.body  = 'status=' + status
req.basic_auth username, password

Net::HTTP.new('twitter.com', 80).start {|http|
  http.request req
}

NHK started broadcasting their radio program on business English online

textbook for "Business English" I found NHK started broadcasting their radio program on business English, "ビジネス英会話", online from this month. I went to a book store and bought a textbook for the program without any delay. It's really super!

Until now, I've taken TOEIC two times. In either times, the score of listening is terribly lesser than reading. I must enhance my ability of listening, but to put it into practice is difficult, so expect the program helps me to do so.

April 16, 2007

IRC2Twitter Gateway Apps

Do you enjoy twittering? How do you play with Twitter? The best way I think is to post statuses via IRC. You may wonder how you can do it. Don't worry! Many people help you with their excellent tools.

Yappo and typester hacked up Perl scripts which work as a gateway and connect IRC to Twitter. To make it, the former implements POE::Component::Client::Twitter and the latter uses POE::Component::Jabber. If you're a Ruby guy, you might want to use tig.rb (twitter irc gareway) written by cho45. Super cool!

By the way, I use TwitterIrcGateway habitually. Today, I found there was Linux version of it (using Mono)! I went straight to test it and confirmed that it worked well in my environment, debian GNU/Linux (sid). According to mayuki, the author of TwitterIrcGateway, as it includes also Mono itself, we don't need to install it for ourselves in advance. Really great!

I wrote an init script like this:

$ cat /etc/init.d/TwitterIrcGateway
#!/bin/sh

NAME="TwitterIrcGateway"
DIR="/path/to/TwitterIrcGateway/"
OPT="--port=6669 --interval=60 --resolve-tinyurl=true --encoding=iso-2022-jp --ignore-watch-error=true --enable-drop-protection=true"
KILL="/usr/bin/killall"

case "$1" in
    start)
        echo -n "Starting $NAME..."
        cd ${DIR} && ./${NAME} ${OPT} 2> /dev/null &
        echo "."
        ;;
    stop)
        echo -n "Stopping $NAME... "
        ${KILL} $NAME
        ;;
    *)
        echo "Usage: /etc/init.d/$NAME {start|stop}"
        exit 1
        ;;
esac

exit 0

April 19, 2007

Commands Execution History

Here's the history of the commands I executed from someday in this year to today.

$ ruby -pe 'gsub(/^.+;| .+$/,"")' .zhistory | sort | uniq -c | sort -r | head -30
    880 sudo
    831 svk
    473 ls
    369 cd
    217 rm
    199 perl
    195 svn
    121 apt-cache
    117 mv
    106 wget
    101 chmod
    100 mkdir
     84 perldoc
     79 cp
     76 cat
     60 '
     52
     49 vi
     44 href
     34 tar
     34 less
     32 ps
     30 echo
     29 ruby
     29 ln
     27 locate
     24 jed
     23 kill
     22 screen
     22 lv

April 25, 2007

Template::Plugin::Shorten version 0.01 released

The initial version of Template::Plugin::Shorten is now on CPAN. It works as a Template::Toolkit plugin, which filters URLs to shorten or lengthen using URL shortening sites like TinyURL.com.

I made it so that I could neatly write a template for a Plagger plugin, P::P::Publish::Twitter, which now supports templatization using TT. I'm afraid that it may cause some problems in other contexts.

Here's a usage of this module:

# Load this plugin
[% USE Shorten %]

# Shortening URLs
[% FILTER shorten_url %]
  <a href="http://search.cpan.org/">search.cpan.org</a>
[% END %]

# or

[% text | shorten_url %]

# Lengthening URLs
[% FILTER lengthen_url %]
  <a href="http://tinyurl.com/37rwu">search.cpan.org</a>
[% END %]

# or

[% text | lengthen_url %]

Alternative usage of Twitter

Twitter not only is a site where we replay to the question, "What are you doing?", but also can be an alternative way of informing and reminding us of anything like news, weather forecast, blog posts which gathers many attentions, TODOs, and so on.

For instance, there's a tweet which broadcasts weather forecast of Tokyo area in Japan to its followers.

Sorry to say, since I'm not live in Tokyo or near there but Amami Island, Kagoshima, forecast of Tokyo area is entirely useless for me. So, I made my version of it:

Also, I made another tweets which convey QotD, Question of the Day, from Vox, really fascinating blogging tool offered by Six Apart, to Twitter.

They just only fetch QotD from Vox and dump it onto Twitter, but QotD is suitable also for such sites as Twitter, so it's worth the trial to do it, I think.

Acknowledgements:

About April 2007

This page contains all entries posted to blog.kentarok.org in April 2007. They are listed from oldest to newest.

August 2006 is the previous archive.

May 2007 is the next archive.

Many more can be found on the main index page or by looking through the archives.

Powered by
Movable Type 3.34